Function: markdown-ts-insert-list-item

markdown-ts-insert-list-item is an interactive and byte-compiled function defined in markdown-ts-mode.el.gz.

Signature

(markdown-ts-insert-list-item)

Documentation

Insert a new list item, splitting text at point.

Text after point moves to the new item. At the beginning of a line, an empty item is inserted above and the current content is pushed down. Inside a block quote, the new line includes the quote prefix. For ordered lists, the number is incremented. When not inside a list, fall back to markdown-ts-newline.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts-insert-list-item ()
  "Insert a new list item, splitting text at point.
Text after point moves to the new item.  At the beginning of a line,
an empty item is inserted above and the current content is pushed down.
Inside a block quote, the new line includes the quote prefix.
For ordered lists, the number is incremented.
When not inside a list, fall back to `markdown-ts-newline'."
  (interactive)
  (let* ((node (treesit-node-at
                (save-excursion (back-to-indentation) (point))
                'markdown))
         (in-bq (and (treesit-parent-until node "\\`block_quote\\'")
                     (save-excursion
                       (beginning-of-line)
                       (looking-at-p "[ \t]*>"))))
         (bq-prefix (when in-bq (markdown-ts--block-quote-prefix)))
         (item (markdown-ts--list-item-at-point)))
    (cond
     ((and item
           (or (not in-bq)
               (>= (markdown-ts--line-block-quote-depth)
                   (markdown-ts--line-block-quote-depth
                    (treesit-node-start (treesit-node-child item 0))))))
      (let* ((new-marker (markdown-ts--new-marker-for-line item))
             (at-bol (<= (current-column)
                         (save-excursion
                           (back-to-indentation)
                           (current-column))))
             (tail (when (and (not at-bol)
                              (not (looking-at-p "[ \t]*$")))
                     (delete-and-extract-region
                      (point) (line-end-position)))))
        (if at-bol
            ;; At BOL: insert empty item above, push current line down.
            (progn
              (beginning-of-line)
              (when bq-prefix (insert bq-prefix))
              (insert new-marker "\n")
              (back-to-indentation))
          ;; Mid-line or EOL: new item below with tail text.
          (delete-horizontal-space)
          (newline)
          (when bq-prefix (insert bq-prefix))
          (insert new-marker)
          (when tail (save-excursion (insert (string-trim-left tail)))))))

     ;; Not in a list: fall back to newline behavior.
     (t (markdown-ts-newline)))))