branch: elpa/typst-ts-mode commit 3f8c4abc15543cb1e6870045f158f92f04cf396f Author: Huan Nguyen <nguyenthieuh...@gmail.com> Commit: Huan Nguyen <nguyenthieuh...@gmail.com>
fix: Do not autoincrement when encountering escape --- typst-ts-mode.el | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/typst-ts-mode.el b/typst-ts-mode.el index 2a9117e19d..361a5a2055 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -1114,6 +1114,17 @@ return the node that is one character left from the end of line." (goto-char (1- (pos-eol))))) (point))))) +(defun typst-ts-mode--item-escape-p () + "Does the end have an escape?" + (string= (treesit-node-type + (treesit-node-at + (save-excursion + ;; like back-to-indentation but for trailing lines at the end + (move-end-of-line nil) + (re-search-backward "^\\|[^[:space:]]") + (point)))) + "escape")) + (defun typst-ts-mode-meta-return (&optional arg) "Depending on context, insert a heading or insert an item. The new heading is created after the ending of current heading. @@ -1122,7 +1133,8 @@ Using ARG argument will ignore the context and it will insert a heading instead. (let ((node (typst-ts-mode--item-on-line-p))) (cond (arg (typst-ts-mode-insert--heading nil)) - ((string= (treesit-node-type node) "item") + ((and (string= (treesit-node-type node) "item") + (not (typst-ts-mode--item-escape-p))) (typst-ts-mode-insert--item node)) (t (typst-ts-mode-insert--heading node))))) @@ -1145,7 +1157,8 @@ When prefix ARG is non-nil, call global return function." ;; on item node end ((and (eolp) (setq node (typst-ts-mode--item-on-line-p)) - (string= (treesit-node-type node) "item") + (and (string= (treesit-node-type node) "item") + (not (typst-ts-mode--item-escape-p))) (not (string= (treesit-node-get node '((child -1 nil) (type))) "linebreak"))) (if (> (treesit-node-child-count node) 1) (typst-ts-mode-insert--item node) @@ -1173,8 +1186,8 @@ When prefix ARG is non-nil, call global return function." NODE must be an item node! This function respects indentation." (let* (;; +, -, or <num>. - (item-type (treesit-node-text - (treesit-node-child node 0))) + (item-type (treesit-node-text + (treesit-node-child node 0))) (item-number (string-to-number item-type)) (item-end (treesit-node-end node)) (node-bol-column (typst-ts-mode-column-at-pos