Function: neocaml--fontify-doc-markup
neocaml--fontify-doc-markup is a natively compiled function defined in
neocaml.el.
Signature
(neocaml--fontify-doc-markup NODE OVERRIDE START END &rest _)
Documentation
Fontify ocamldoc markup inside the comment NODE.
Only doc comments are touched; plain comments are left alone.
OVERRIDE is the override flag from treesit-font-lock-rules.
Scanning always starts from the beginning of the node - starting
mid-comment could miss an opening marker - but stops once past END,
the end of the region being fontified; jit-lock asks for the rest
later.
Source Code
;; Defined in /nix/store/ahssdx4rwzyxhyhavpn0bkznk13xrggi-emacs-packages-deps/share/emacs/site-lisp/elpa/neocaml-20260907.2015/neocaml.el
(defun neocaml--fontify-doc-markup (node override _start end &rest _)
"Fontify ocamldoc markup inside the comment NODE.
Only doc comments are touched; plain comments are left alone.
OVERRIDE is the override flag from `treesit-font-lock-rules'.
Scanning always starts from the beginning of the node - starting
mid-comment could miss an opening marker - but stops once past END,
the end of the region being fontified; jit-lock asks for the rest
later."
(let ((limit (treesit-node-end node)))
(save-excursion
(goto-char (treesit-node-start node))
(when (looking-at neocaml--doc-comment-regexp)
(forward-char 3) ; skip the (**
(while (< (point) (min limit end))
(let ((c (char-after)))
(cond
;; Escape sequences: \{ \} \[ \] \@
((eq c ?\\)
(forward-char
(if (memq (char-after (1+ (point))) '(?\{ ?\} ?\[ ?\] ?@)) 2 1)))
((eq c ?\{)
(cond
;; {[ code block ]} and {v verbatim v} - no markup inside
((looking-at "{\\(?:\\(\\[\\)\\|v[ \t\n]\\)")
(let* ((open (point))
(opener-end (match-end 0))
(closer (if (match-beginning 1) "]}" "v}"))
(close (save-excursion
(search-forward closer limit t))))
(if (not close)
(goto-char opener-end)
(neocaml--doc-markup-fontify-span
open opener-end (- close 2) close
'neocaml-doc-code-face override)
(goto-char close))))
;; {!ref}, {:url}, {{!ref} ...}, {{:url} ...} - the target
;; runs to the brace closing the innermost opener
((looking-at "{{?[!:]")
(let* ((open (point))
(target-beg (match-end 0))
(close (save-excursion
(goto-char target-beg)
(neocaml--doc-markup-close ?\{ ?\} limit))))
(if (not close)
(goto-char target-beg)
(neocaml--doc-markup-fontify-span
open target-beg close (1+ close)
'neocaml-doc-reference-face override)
(goto-char (1+ close)))))
;; {b ...}, {i ...}, {e ...}, {2 ...} headings, {^ ...},
;; {_ ...}, {C ...}, {L ...}, {R ...}
((looking-at
"{\\(?:[0-9]\\(?::[^ \t\n{}]+\\)?\\|[bie^_CLR]\\)[ \t\n]")
(let* ((open (point))
(marker-end (match-end 0))
(close (save-excursion
(goto-char marker-end)
(neocaml--doc-markup-close ?\{ ?\} limit))))
(if (not close)
(goto-char marker-end)
(neocaml--doc-markup-fontify-span
open marker-end close (1+ close)
(neocaml--doc-markup-content-face (char-after (1+ open)))
override)
;; Continue scanning inside the construct so that
;; nested markup like {b ... {i ...}} stacks its faces.
(goto-char marker-end))))
(t (forward-char 1))))
;; [inline code]
((eq c ?\[)
(let ((open (point))
(close (save-excursion
(forward-char 1)
(neocaml--doc-markup-close ?\[ ?\] limit))))
(if (not close)
(forward-char 1)
(neocaml--doc-markup-fontify-span
open (1+ open) close (1+ close)
'neocaml-doc-code-face override)
(goto-char (1+ close)))))
;; @tags, at the start of a line or after whitespace
((eq c ?@)
(if (and (memq (char-before) '(?\s ?\t ?\n ?*))
(looking-at neocaml--doc-markup-tag-regexp))
(progn
(treesit-fontify-with-override
(point) (match-end 0) 'neocaml-doc-markup-face override)
(goto-char (match-end 0)))
(forward-char 1)))
;; Plain text: hop to the next markup candidate at C speed.
(t
(forward-char 1)
(skip-chars-forward "^\\\\{[@" limit)))))))))