Function: markdown-ts--tocs

markdown-ts--tocs is a byte-compiled function defined in markdown-ts-mode-x.el.gz.

Signature

(markdown-ts--tocs &optional BEG END)

Documentation

Scan the current buffer for toc entries from BEG to END.

If BEG is nil, use point-min. If END is nil, use point-max.

Return an alist of the form:
  '((keyword (node beg end vars)))

Vars are expanded via hack-local-variables-prop-line.

Return the list in the order of appearance in the buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode-x.el.gz
(defun markdown-ts--tocs (&optional beg end)
  "Scan the current buffer for toc entries from BEG to END.
If BEG is nil, use `point-min'.  If END is nil, use `point-max'.

Return an alist of the form:
  \\='((keyword (node beg end vars)))

Vars are expanded via `hack-local-variables-prop-line'.

Return the list in the order of appearance in the buffer."
  ;; NOTE: This scans all matching nodes below BEG with no maximum count
  ;; even when we want only a single next matching item.  Perhaps
  ;; `treesit-query-capture' could be improved to accept a max-count
  ;; argument.
  ;;
  ;; Match "markdown-ts-toc:", "markdown-ts-toc-abc123:" but not
  ;; "markdown-ts-tocxxx:".
  (let ((res))
    (dolist (node
             (treesit-query-capture
              'markdown
              '((((html_block) @markdown-ts-toc)
                 (:match "<!--[[:blank:]]*markdown-ts-toc\\(-[[:alnum:]]+\\)*:" @markdown-ts-toc)))
              (or beg (point-min))
              (or end (point-max))
              'node-only))
      (let* ((s (treesit-node-text node 'no-property))
             (match (string-match "\\(markdown-ts-toc\\(-[[:alnum:]]+\\)*\\):.*" s))
             (keyword (when match (match-string 1 s))))
        (let ((vars))
          (with-work-buffer
            (insert s)
            (setq vars (hack-local-variables-prop-line)))
          (push
           `(,keyword
             (node . ,node)
             (beg . ,(treesit-node-start node))
             (end . ,(treesit-node-end node))
             (vars . ,vars))
           res))))
    (nreverse res)))