-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclaude-shell-fontifier.el
More file actions
666 lines (616 loc) · 26.8 KB
/
claude-shell-fontifier.el
File metadata and controls
666 lines (616 loc) · 26.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
;;; claude-shell-fontifier.el --- Fontifier for claude-shell -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2024 Armin Friedl
;;
;; Author: Armin Friedl <dev@friedl.net>
;; Maintainer: Armin Friedl <dev@friedl.net>
;; Created: März 16, 2024
;; Version: 0.0.3
;; Keywords: anthropic claude claude-shell shell-maker terminals wp help tools
;; Homepage: https://github.com/arminfriedl/claude-shell
;; Package-Requires: ((emacs "29.1") (shell-maker "0.50.5"))
;;
;; This file is not part of GNU Emacs.
;; MIT License
;; Copyright (c) 2024 Armin Friedl
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;; The above copyright notice and this permission notice shall be included in all
;; copies or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;; Commentary:
;;
;; `claude-shell-fontifier' provides fontification for the output of
;; `claude-shell'. It is heavily based on similar function in `chatgpt-shell'
;; (https://github.com/xenodium/chatgpt-shell/).
;;
;; It is intended only for internal use in `claude-shell'. This package will be
;; removed as soon as the respective functionality is integrated in
;; `shell-maker' proper.
;;
;;; Code:
(require 'shell-maker)
(defcustom claude-shell-fontifier-language-mapping '(("elisp" . "emacs-lisp")
("objective-c" . "objc")
("objectivec" . "objc")
("cpp" . "c++"))
"Maps external language names to Emacs names.
Use only lower-case names.
For example:
lowercase Emacs mode (without -mode)
Objective-C -> (\"objective-c\" . \"objc\")"
:type '(alist :key-type (string :tag "Language Name/Alias")
:value-type (string :tag "Mode Name (without -mode)"))
:group 'claude-shell)
(defun claude-shell-fontifier-markdown-block-language (text)
"Get the language label of a Markdown TEXT code block."
(when (string-match (rx bol "```" (0+ space) (group (+ (not (any "\n"))))) text)
(match-string 1 text)))
(defun claude-shell-fontifier-markdown-block-at-point ()
"Markdown start/end cons if point at block. nil otherwise."
(save-excursion
(save-restriction
(when (eq major-mode 'claude-shell-fontifier-mode)
(shell-maker-narrow-to-prompt))
(let* ((language)
(language-start)
(language-end)
(start (save-excursion
(when (re-search-backward "^```" nil t)
(setq language (claude-shell-fontifier-markdown-block-language (thing-at-point 'line)))
(save-excursion
(forward-char 3) ; ```
(setq language-start (point))
(end-of-line)
(setq language-end (point)))
language-end)))
(end (save-excursion
(when (re-search-forward "^```" nil t)
(forward-line 0)
(point)))))
(when (and start end
(> (point) start)
(< (point) end))
(list (cons 'language language)
(cons 'language-start language-start)
(cons 'language-end language-end)
(cons 'start start)
(cons 'end end)))))))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--markdown-headers (&optional avoid-ranges)
"Extract markdown headers with AVOID-RANGES."
(let ((headers '())
(case-fold-search nil))
(save-excursion
(goto-char (point-min))
(while (re-search-forward
(rx bol (group (one-or-more "#"))
(one-or-more space)
(group (one-or-more (not (any "\n")))) eol)
nil t)
(when-let ((begin (match-beginning 0))
(end (match-end 0)))
(unless (seq-find (lambda (avoided)
(and (>= begin (car avoided))
(<= end (cdr avoided))))
avoid-ranges)
(push
(list
'start begin
'end end
'level (cons (match-beginning 1) (match-end 1))
'title (cons (match-beginning 2) (match-end 2)))
headers)))))
(nreverse headers)))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--markdown-links (&optional avoid-ranges)
"Extract markdown links with AVOID-RANGES."
(let ((links '())
(case-fold-search nil))
(save-excursion
(goto-char (point-min))
(while (re-search-forward
(rx (seq "["
(group (one-or-more (not (any "]"))))
"]"
"("
(group (one-or-more (not (any ")"))))
")"))
nil t)
(when-let ((begin (match-beginning 0))
(end (match-end 0)))
(unless (seq-find (lambda (avoided)
(and (>= begin (car avoided))
(<= end (cdr avoided))))
avoid-ranges)
(push
(list
'start begin
'end end
'title (cons (match-beginning 1) (match-end 1))
'url (cons (match-beginning 2) (match-end 2)))
links)))))
(nreverse links)))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--markdown-bolds (&optional avoid-ranges)
"Extract markdown bolds with AVOID-RANGES."
(let ((bolds '())
(case-fold-search nil))
(save-excursion
(goto-char (point-min))
(while (re-search-forward
(rx (or (group "**" (group (one-or-more (not (any "\n*")))) "**")
(group "__" (group (one-or-more (not (any "\n_")))) "__")))
nil t)
(when-let ((begin (match-beginning 0))
(end (match-end 0)))
(unless (seq-find (lambda (avoided)
(and (>= begin (car avoided))
(<= end (cdr avoided))))
avoid-ranges)
(push
(list
'start begin
'end end
'text (cons (or (match-beginning 2)
(match-beginning 4))
(or (match-end 2)
(match-end 4))))
bolds)))))
(nreverse bolds)))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--markdown-strikethroughs (&optional avoid-ranges)
"Extract markdown strikethroughs with AVOID-RANGES."
(let ((strikethroughs '())
(case-fold-search nil))
(save-excursion
(goto-char (point-min))
(while (re-search-forward
(rx "~~" (group (one-or-more (not (any "\n~")))) "~~")
nil t)
(when-let ((begin (match-beginning 0))
(end (match-end 0)))
(unless (seq-find (lambda (avoided)
(and (>= begin (car avoided))
(<= end (cdr avoided))))
avoid-ranges)
(push
(list
'start begin
'end end
'text (cons (match-beginning 1)
(match-end 1)))
strikethroughs)))))
(nreverse strikethroughs)))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--markdown-italics (&optional avoid-ranges)
"Extract markdown italics with AVOID-RANGES."
(let ((italics '())
(case-fold-search nil))
(save-excursion
(goto-char (point-min))
(while (re-search-forward
(rx (or (group (or bol (one-or-more (any "\n \t")))
(group "*")
(group (one-or-more (not (any "\n*")))) "*")
(group (or bol (one-or-more (any "\n \t")))
(group "_")
(group (one-or-more (not (any "\n_")))) "_")))
nil t)
(when-let ((begin (match-beginning 0))
(end (match-end 0)))
(unless (seq-find (lambda (avoided)
(and (>= begin (car avoided))
(<= end (cdr avoided))))
avoid-ranges)
(push
(list
'start (or (match-beginning 2)
(match-beginning 5))
'end end
'text (cons (or (match-beginning 3)
(match-beginning 6))
(or (match-end 3)
(match-end 6))))
italics)))))
(nreverse italics)))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--markdown-inline-codes (&optional avoid-ranges)
"Get a list of all inline markdown code in buffer with AVOID-RANGES."
(let ((codes '())
(case-fold-search nil))
(save-excursion
(goto-char (point-min))
(while (re-search-forward
"`\\([^`\n]+\\)`"
nil t)
(when-let ((begin (match-beginning 0))
(end (match-end 0)))
(unless (seq-find (lambda (avoided)
(and (>= begin (car avoided))
(<= end (cdr avoided))))
avoid-ranges)
(push
(list
'body (cons (match-beginning 1) (match-end 1))) codes)))))
(nreverse codes)))
;; TODO: Move to shell-maker.
(defvar claude-shell-fontifier--source-block-regexp
(rx bol (zero-or-more whitespace) (group "```") (zero-or-more whitespace) ;; ```
(group (zero-or-more (or alphanumeric "-" "+"))) ;; language
(zero-or-more whitespace)
(one-or-more "\n")
(group (*? anychar)) ;; body
(one-or-more "\n")
(group "```") (or "\n" eol)))
(defvar-local claude-shell-fontifier--is-primary-p nil)
(defun claude-shell-fontifier-next-source-block ()
"Move point to previous source block."
(interactive)
(when-let
((next-block
(save-excursion
(when-let ((current (claude-shell-fontifier-markdown-block-at-point)))
(goto-char (map-elt current 'end))
(end-of-line))
(when (re-search-forward claude-shell-fontifier--source-block-regexp nil t)
(claude-shell-fontifier--match-source-block)))))
(goto-char (car (map-elt next-block 'body)))))
(defun claude-shell-fontifier-previous-item ()
"Go to previous item.
Could be a prompt or a source block."
(interactive)
(unless (eq major-mode 'claude-shell-fontifier-mode)
(user-error "Not in a shell"))
(let ((prompt-pos (save-excursion
(when (comint-next-prompt (- 1))
(point))))
(block-pos (save-excursion
(when (claude-shell-fontifier-previous-source-block)
(point)))))
(cond ((and block-pos prompt-pos)
(goto-char (max prompt-pos
block-pos)))
(block-pos
(goto-char block-pos))
(prompt-pos
(goto-char prompt-pos)))))
(defun claude-shell-fontifier-next-item ()
"Go to next item.
Could be a prompt or a source block."
(interactive)
(unless (eq major-mode 'claude-shell-fontifier-mode)
(user-error "Not in a shell"))
(let ((prompt-pos (save-excursion
(when (comint-next-prompt 1)
(point))))
(block-pos (save-excursion
(when (claude-shell-fontifier-next-source-block)
(point)))))
(cond ((and block-pos prompt-pos)
(goto-char (min prompt-pos
block-pos)))
(block-pos
(goto-char block-pos))
(prompt-pos
(goto-char prompt-pos)))))
(defun claude-shell-fontifier-previous-source-block ()
"Move point to previous source block."
(interactive)
(when-let
((previous-block
(save-excursion
(when-let ((current (claude-shell-fontifier-markdown-block-at-point)))
(goto-char (map-elt current 'start))
(forward-line 0))
(when (re-search-backward claude-shell-fontifier--source-block-regexp nil t)
(claude-shell-fontifier--match-source-block)))))
(goto-char (car (map-elt previous-block 'body)))))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--match-source-block ()
"Return a matched source block by the previous search/regexp operation."
(list
'start (cons (match-beginning 1)
(match-end 1))
'end (cons (match-beginning 4)
(match-end 4))
'language (when (and (match-beginning 2)
(match-end 2))
(cons (match-beginning 2)
(match-end 2)))
'body (cons (match-beginning 3) (match-end 3))))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--source-blocks ()
"Get a list of all source blocks in buffer."
(let ((markdown-blocks '())
(case-fold-search nil))
(save-excursion
(goto-char (point-min))
(while (re-search-forward
claude-shell-fontifier--source-block-regexp
nil t)
(when-let ((begin (match-beginning 0))
(end (match-end 0)))
(push (claude-shell-fontifier--match-source-block)
markdown-blocks))))
(nreverse markdown-blocks)))
(defun claude-shell-fontifier--resolve-internal-language (language)
"Resolve external LANGUAGE to internal.
For example \"elisp\" -> \"emacs-lisp\"."
(when language
(or (map-elt claude-shell-fontifier-language-mapping
(downcase (string-trim language)))
(when (intern (concat (downcase (string-trim language))
"-mode"))
(downcase (string-trim language))))))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--fontify-source-block (quotes1-start quotes1-end lang
lang-start lang-end body-start body-end quotes2-start quotes2-end)
"Fontify a source block.
Use QUOTES1-START QUOTES1-END LANG LANG-START LANG-END BODY-START
BODY-END QUOTES2-START and QUOTES2-END."
;; Overlay beginning "```" with a copy block button.
(overlay-put (make-overlay quotes1-start
quotes1-end)
'display
(propertize "📋 "
'pointer 'hand
'keymap (shell-maker--make-ret-binding-map
(lambda ()
(interactive)
(kill-ring-save body-start body-end)
(message "Copied")))))
;; Hide end "```" altogether.
(overlay-put (make-overlay quotes2-start
quotes2-end) 'invisible 'chatgpt-shell)
(unless (eq lang-start lang-end)
(overlay-put (make-overlay lang-start
lang-end) 'face '(:box t))
(overlay-put (make-overlay lang-end
(1+ lang-end)) 'display "\n\n"))
(let ((lang-mode (intern (concat (or
(claude-shell-fontifier--resolve-internal-language lang)
(downcase (string-trim lang)))
"-mode")))
(string (buffer-substring-no-properties body-start body-end))
(buf (if (and (boundp 'shell-maker--config)
shell-maker--config)
(shell-maker-buffer shell-maker--config)
(current-buffer)))
(pos 0)
(props)
(overlay)
(propertized-text))
(if (fboundp lang-mode)
(progn
(setq propertized-text
(with-current-buffer
(get-buffer-create
(format " *claude-shell-fontifier-fontification:%s*" lang-mode))
(let ((inhibit-modification-hooks nil)
(inhibit-message t))
(erase-buffer)
;; Additional space ensures property change.
(insert string " ")
(funcall lang-mode)
(font-lock-ensure))
(buffer-string)))
(while (< pos (length propertized-text))
(setq props (text-properties-at pos propertized-text))
(setq overlay (make-overlay (+ body-start pos)
(+ body-start (1+ pos))
buf))
(overlay-put overlay 'face (plist-get props 'face))
(setq pos (1+ pos))))
(overlay-put (make-overlay body-start body-end buf)
'face 'font-lock-doc-markup-face))))
(defun claude-shell-fontifier--fontify-divider (start end)
"Display text between START and END as a divider."
(overlay-put (make-overlay start end
(if (and (boundp 'shell-maker--config)
shell-maker--config)
(shell-maker-buffer shell-maker--config)
(current-buffer)))
'display
(concat (propertize (concat (make-string (window-body-width) ? ) "")
'face '(:underline t)) "\n")))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--fontify-link (start end title-start title-end url-start url-end)
"Fontify a markdown link.
Use START END TITLE-START TITLE-END URL-START URL-END."
;; Hide markup before
(overlay-put (make-overlay start title-start) 'invisible 'chatgpt-shell)
;; Show title as link
(overlay-put (make-overlay title-start title-end) 'face 'link)
;; Make RET open the URL
(define-key (let ((map (make-sparse-keymap)))
(define-key map [mouse-1]
(lambda () (interactive)
(browse-url (buffer-substring-no-properties url-start url-end))))
(define-key map (kbd "RET")
(lambda () (interactive)
(browse-url (buffer-substring-no-properties url-start url-end))))
(overlay-put (make-overlay title-start title-end) 'keymap map)
map)
[remap self-insert-command] 'ignore)
;; Hide markup after
(overlay-put (make-overlay title-end end) 'invisible 'chatgpt-shell))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--fontify-bold (start end text-start text-end)
"Fontify a markdown bold.
Use START END TEXT-START TEXT-END."
;; Hide markup before
(overlay-put (make-overlay start text-start) 'invisible 'chatgpt-shell)
;; Show title as bold
(overlay-put (make-overlay text-start text-end) 'face 'bold)
;; Hide markup after
(overlay-put (make-overlay text-end end) 'invisible 'chatgpt-shell))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--fontify-header (start _end level-start level-end title-start title-end)
"Fontify a markdown header.
Use START END LEVEL-START LEVEL-END TITLE-START TITLE-END."
;; Hide markup before
(overlay-put (make-overlay start title-start) 'invisible 'chatgpt-shell)
;; Show title as header
(overlay-put (make-overlay title-start title-end) 'face
(cond ((eq (- level-end level-start) 1)
'org-level-1)
((eq (- level-end level-start) 2)
'org-level-2)
((eq (- level-end level-start) 3)
'org-level-3)
((eq (- level-end level-start) 4)
'org-level-4)
((eq (- level-end level-start) 5)
'org-level-5)
((eq (- level-end level-start) 6)
'org-level-6)
((eq (- level-end level-start) 7)
'org-level-7)
((eq (- level-end level-start) 8)
'org-level-8)
(t
'org-level-1))))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--fontify-italic (start end text-start text-end)
"Fontify a markdown italic.
Use START END TEXT-START TEXT-END."
;; Hide markup before
(overlay-put (make-overlay start text-start) 'invisible 'chatgpt-shell)
;; Show title as italic
(overlay-put (make-overlay text-start text-end) 'face 'italic)
;; Hide markup after
(overlay-put (make-overlay text-end end) 'invisible 'chatgpt-shell))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--fontify-strikethrough (start end text-start text-end)
"Fontify a markdown strikethrough.
Use START END TEXT-START TEXT-END."
;; Hide markup before
(overlay-put (make-overlay start text-start) 'invisible 'chatgpt-shell)
;; Show title as strikethrough
(overlay-put (make-overlay text-start text-end) 'face '(:strike-through t))
;; Hide markup after
(overlay-put (make-overlay text-end end) 'invisible 'chatgpt-shell))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--fontify-inline-code (body-start body-end)
"Fontify a source block.
Use QUOTES1-START QUOTES1-END LANG LANG-START LANG-END BODY-START
BODY-END QUOTES2-START and QUOTES2-END."
;; Hide ```
(overlay-put (make-overlay (1- body-start)
body-start) 'invisible 'chatgpt-shell)
(overlay-put (make-overlay body-end
(1+ body-end)) 'invisible 'chatgpt-shell)
(overlay-put (make-overlay body-start body-end
(if (and (boundp 'shell-maker--config)
shell-maker--config)
(shell-maker-buffer shell-maker--config)
(current-buffer)))
'face 'font-lock-doc-markup-face))
(defun claude-shell-fontifier-rename-block-at-point ()
"Rename block at point (perhaps a different language)."
(interactive)
(save-excursion
(if-let ((block (claude-shell-fontifier-markdown-block-at-point)))
(if (map-elt block 'language)
(perform-replace (map-elt block 'language)
(read-string "Name: " nil nil "") nil nil nil nil nil
(map-elt block 'language-start) (map-elt block 'language-end))
(let ((new-name (read-string "Name: " nil nil "")))
(goto-char (map-elt block 'language-start))
(insert new-name)
(claude-shell-fontifier--put-source-block-overlays)))
(user-error "No block at point"))))
(defun claude-shell-fontifier-remove-block-overlays ()
"Remove block overlays. Handy for renaming blocks."
(interactive)
(dolist (overlay (overlays-in (point-min) (point-max)))
(delete-overlay overlay)))
(defun claude-shell-fontifier-refresh-rendering ()
"Refresh markdown rendering by re-applying to entire buffer."
(interactive)
(claude-shell-fontifier--put-source-block-overlays))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--put-source-block-overlays ()
"Put overlays for all source blocks."
(when claude-shell-fontifier-highlight-blocks
(let* ((source-blocks (claude-shell-fontifier--source-blocks))
(avoid-ranges (seq-map (lambda (block)
(map-elt block 'body))
source-blocks)))
(dolist (overlay (overlays-in (point-min) (point-max)))
(delete-overlay overlay))
(dolist (block source-blocks)
(claude-shell-fontifier--fontify-source-block
(car (map-elt block 'start))
(cdr (map-elt block 'start))
(buffer-substring-no-properties (car (map-elt block 'language))
(cdr (map-elt block 'language)))
(car (map-elt block 'language))
(cdr (map-elt block 'language))
(car (map-elt block 'body))
(cdr (map-elt block 'body))
(car (map-elt block 'end))
(cdr (map-elt block 'end))))
(when claude-shell-fontifier-insert-dividers
(dolist (divider (shell-maker--prompt-end-markers))
(claude-shell-fontifier--fontify-divider (car divider) (cdr divider))))
(dolist (link (claude-shell-fontifier--markdown-links avoid-ranges))
(claude-shell-fontifier--fontify-link
(map-elt link 'start)
(map-elt link 'end)
(car (map-elt link 'title))
(cdr (map-elt link 'title))
(car (map-elt link 'url))
(cdr (map-elt link 'url))))
(dolist (header (claude-shell-fontifier--markdown-headers avoid-ranges))
(claude-shell-fontifier--fontify-header
(map-elt header 'start)
(map-elt header 'end)
(car (map-elt header 'level))
(cdr (map-elt header 'level))
(car (map-elt header 'title))
(cdr (map-elt header 'title))))
(dolist (bold (claude-shell-fontifier--markdown-bolds avoid-ranges))
(claude-shell-fontifier--fontify-bold
(map-elt bold 'start)
(map-elt bold 'end)
(car (map-elt bold 'text))
(cdr (map-elt bold 'text))))
(dolist (italic (claude-shell-fontifier--markdown-italics avoid-ranges))
(claude-shell-fontifier--fontify-italic
(map-elt italic 'start)
(map-elt italic 'end)
(car (map-elt italic 'text))
(cdr (map-elt italic 'text))))
(dolist (strikethrough (claude-shell-fontifier--markdown-strikethroughs avoid-ranges))
(claude-shell-fontifier--fontify-strikethrough
(map-elt strikethrough 'start)
(map-elt strikethrough 'end)
(car (map-elt strikethrough 'text))
(cdr (map-elt strikethrough 'text))))
(dolist (inline-code (claude-shell-fontifier--markdown-inline-codes avoid-ranges))
(claude-shell-fontifier--fontify-inline-code
(car (map-elt inline-code 'body))
(cdr (map-elt inline-code 'body)))))))
;; TODO: Move to shell-maker.
(defun claude-shell-fontifier--unpaired-length (length)
"Expand LENGTH to include paired responses.
Each request has a response, so double LENGTH if set.
Add one for current request (without response).
If no LENGTH set, use 2048."
(if length
(1+ (* 2 length))
2048))
(provide 'claude-shell-fontifier)
;;; claude-shell-fontifier.el ends here