Function: neocaml--fill-paragraph

neocaml--fill-paragraph is a natively compiled function defined in neocaml.el.

Signature

(neocaml--fill-paragraph &optional JUSTIFY)

Documentation

Fill the OCaml comment at point.

Uses tree-sitter to find comment boundaries, then narrows to the comment body (excluding delimiters) and fills. Returns t if point was in a comment, nil otherwise to let the default handler run.

Source Code

;; Defined in /nix/store/ahssdx4rwzyxhyhavpn0bkznk13xrggi-emacs-packages-deps/share/emacs/site-lisp/elpa/neocaml-20260907.2015/neocaml.el
(defun neocaml--fill-paragraph (&optional _justify)
  "Fill the OCaml comment at point.
Uses tree-sitter to find comment boundaries, then narrows to the
comment body (excluding delimiters) and fills.  Returns t if point
was in a comment, nil otherwise to let the default handler run."
  (let* ((comment (neocaml--comment-at-point)))
    (when comment
      (let ((start (treesit-node-start comment))
            (end (treesit-node-end comment)))
        (save-excursion
          (save-restriction
            ;; Narrow to comment body: skip (* prefix and *) suffix
            (goto-char start)
            (when (looking-at "(\\*+[ \t]*")
              (setq start (match-end 0)))
            (goto-char end)
            (when (looking-back "\\*+)" nil)
              (goto-char (match-beginning 0))
              (skip-chars-backward " \t")
              (setq end (point)))
            ;; Compute body column before narrowing.
            (goto-char start)
            (let ((body-col (current-column)))
              (narrow-to-region start end)
              ;; Treat list items (- foo, * foo, + foo) and odoc tags
              ;; (@param, @return) as paragraph boundaries so they
              ;; don't get merged into prose.
              (let* ((paragraph-start
                      (concat paragraph-start
                              "\\|[ \t]*[-*+][ \t]"
                              "\\|[ \t]*@[a-z]+\\b"))
                     par-start par-end)
                ;; Find the paragraph containing point (without
                ;; fill-prefix set, so list items are recognized as
                ;; paragraph boundaries).
                (save-excursion
                  (skip-chars-forward " \t")
                  (backward-paragraph)
                  (skip-chars-forward " \t\n")
                  (setq par-start (point))
                  (forward-paragraph)
                  (setq par-end (point)))
                ;; Use body-col for first-line paragraphs, actual
                ;; indentation for indented paragraphs (list items).
                (let* ((par-col (save-excursion
                                  (goto-char par-start)
                                  (skip-chars-forward " \t")
                                  (current-column)))
                       (fill-prefix
                        (make-string (max body-col par-col) ?\s))
                       (fill-paragraph-function nil))
                  (fill-region-as-paragraph par-start par-end)))))
          t)))))