Function: markdown-ts--list-item-at-point

markdown-ts--list-item-at-point is a byte-compiled function defined in markdown-ts-mode.el.gz.

Signature

(markdown-ts--list-item-at-point)

Documentation

Return the innermost list_item node containing point, or nil.

Uses the position after back-to-indentation so that point in a line's leading whitespace resolves to the item on that line, not to a preceding item whose node spans the whitespace. Inside block quotes, also try from the content position past the > markers.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts--list-item-at-point ()
  "Return the innermost list_item node containing point, or nil.
Uses the position after `back-to-indentation' so that point in
a line's leading whitespace resolves to the item on that line,
not to a preceding item whose node spans the whitespace.
Inside block quotes, also try from the content position past
the `>' markers."
  (when-let* ((pos (save-excursion (back-to-indentation) (point)))
              (node (treesit-node-at pos 'markdown))
              (bol (line-beginning-position))
              (eol (line-end-position)))
    (or (let ((item (treesit-parent-until
                     node (lambda (n)
                            (equal (treesit-node-type n) "list_item")))))
          ;; Verify the current line is within the item's range.
          ;; `treesit-node-at' can return a node inside a list_item
          ;; even when point is on a preceding line.
          (when (and item
                     (<= (treesit-node-start item) eol)
                     (>= (treesit-node-end item) bol))
            item))
        ;; When back-to-indentation lands on block quote markers,
        ;; skip past them and try from the content position.
        (let ((content-pos (save-excursion
                             (beginning-of-line)
                             (skip-chars-forward "> \t")
                             (point))))
          (when (> content-pos pos)
            (when-let* ((cnode (treesit-node-at content-pos 'markdown)))
              (let ((item (treesit-parent-until
                           cnode
                           (lambda (n)
                             (equal (treesit-node-type n) "list_item")))))
                (when (and item
                           (<= (treesit-node-start item) eol)
                           (>= (treesit-node-end item) bol))
                  item))))))))