Function: markdown-ts--new-marker-for-line

markdown-ts--new-marker-for-line is a byte-compiled function defined in markdown-ts-mode.el.gz.

Signature

(markdown-ts--new-marker-for-line ITEM)

Documentation

Return the marker string for a new item following ITEM.

When the current line has a list marker pattern at a different indentation than ITEM (e.g., a nested marker that the grammar did not recognize as a list_item), use the current line's marker. Otherwise, fall back to markdown-ts--list-item-new-marker.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts--new-marker-for-line (item)
  "Return the marker string for a new item following ITEM.
When the current line has a list marker pattern at a different
indentation than ITEM (e.g., a nested marker that the grammar did
not recognize as a list_item), use the current line's marker.
Otherwise, fall back to `markdown-ts--list-item-new-marker'."
  (let ((marker-node (treesit-node-child item 0)))
    (if (= (line-number-at-pos)
            (line-number-at-pos (treesit-node-start marker-node)))
        ;; Item's marker is on the current line: use it normally.
        (markdown-ts--list-item-new-marker item)
      ;; Item's marker is on a different line.  The parser may have
      ;; failed to recognize a nested marker (e.g., a lone `  - '
      ;; parsed as a setext heading).  Read the current line.
      (let ((line (buffer-substring-no-properties
                   (line-beginning-position) (line-end-position))))
        (if (string-match
             "\\`\\([[:blank:]]*\\)\\([-*+] \\|\\([0-9]+\\)\\([.)] \\)\\)"
             line)
            (let ((indent (match-string 1 line))
                  (num (match-string 3 line))
                  (suffix (match-string 4 line))
                  (unordered (match-string 2 line)))
              (if num
                  (concat indent (number-to-string
                                  (1+ (string-to-number num)))
                          suffix)
                (concat indent unordered)))
          ;; No marker pattern on current line: use item's marker.
          (markdown-ts--list-item-new-marker item))))))