Function: markdown-ts--fill-block-quote

markdown-ts--fill-block-quote is a byte-compiled function defined in markdown-ts-mode.el.gz.

Signature

(markdown-ts--fill-block-quote JUSTIFY)

Documentation

Fill the paragraph at point inside a block quote.

Find the paragraph node at point within the block quote and fill
only that paragraph, preserving the > prefix. When the
paragraph is inside a list item, align continuation lines with the item's text column. JUSTIFY is as in fill-paragraph.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts--fill-block-quote (justify)
  "Fill the paragraph at point inside a block quote.
Find the paragraph node at point within the block quote and fill
only that paragraph, preserving the `> ' prefix.  When the
paragraph is inside a list item, align continuation lines with
the item's text column.  JUSTIFY is as in `fill-paragraph'."
  ;; Skip past `> ' markers and any list marker to land inside the
  ;; content, where the paragraph node lives.
  (let* ((content-pos (save-excursion
                        (beginning-of-line)
                        (skip-chars-forward "> \t")
                        ;; If we land on a list marker, skip past it.
                        (when (looking-at "[-*+] \\|[0-9]+[.)]\s")
                          (goto-char (match-end 0)))
                        (min (1+ (point)) (point-max))))
         (node (treesit-node-at content-pos 'markdown))
         (para (treesit-parent-until
                node (lambda (n)
                       (equal (treesit-node-type n) "paragraph")))))
    (when para
      ;; The grammar may include trailing block_continuation nodes
      ;; (blank `> >' lines) as children of the paragraph.  Use the
      ;; end of the last inline child so fill does not merge across
      ;; what should be a paragraph boundary.
      (let* ((last-inline
              (seq-find (lambda (child)
                          (equal (treesit-node-type child) "inline"))
                        (reverse (treesit-node-children para))))
             (para-end (if last-inline
                           (treesit-node-end last-inline)
                         (treesit-node-end para)))
             (bq-prefix (markdown-ts--block-quote-prefix))
             ;; When inside a list item, extend the prefix with spaces
             ;; so continuation lines align with the item's text.
             (list-item (treesit-parent-until para "\\`list_item\\'"))
             (prefix (if list-item
                         (let* ((text-col (markdown-ts--list-item-text-column
                                           list-item))
                                (extra (max 0 (- text-col (length bq-prefix)))))
                           (concat bq-prefix (make-string extra ?\s)))
                       bq-prefix))
             (adaptive-fill-function nil)
             (fill-forward-paragraph-function #'forward-paragraph)
             (fill-paragraph-function nil))
        (save-restriction
          ;; Narrow to the full lines of the paragraph so that the
          ;; `> ' markers are included in the fill region.
          (narrow-to-region
           (save-excursion
             (goto-char (treesit-node-start para))
             (beginning-of-line)
             (point))
           para-end)
          (let ((fill-prefix prefix))
            (fill-paragraph justify))))))
  t)