branch: elpa/typst-ts-mode
commit f7e4ddf4fb2bc4d23dbb40b1cf4122e4b12edc35
Author: meowking <[email protected]>
Commit: meowking <[email protected]>

    fix(indentation/editing): container types (like `#[]`) inside item
---
 typst-ts-core.el    |  7 +++++--
 typst-ts-editing.el | 14 +++++++++++---
 typst-ts-mode.el    | 28 +++++++++++++++++++---------
 3 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/typst-ts-core.el b/typst-ts-core.el
index 6b7b8357ca..b5ab461e23 100644
--- a/typst-ts-core.el
+++ b/typst-ts-core.el
@@ -32,10 +32,13 @@
   :type 'natnum
   :group 'typst-ts)
 
-(defconst typst-ts-mode--container-node-types-regexp
+(defconst typst-ts-core--container-node-types
   ;; '_math_group' here is because `treesit-parent-until' doesn't hanlde node 
type alias well
   ;; TODO file a bug
-  (regexp-opt '("block" "content" "group" "math" "_math_group"))
+  '("block" "content" "group" "math" "_math_group"))
+
+(defconst typst-ts-mode--container-node-types-regexp
+  (regexp-opt typst-ts-core--container-node-types)
   "Container node types regexp.")
 
 (defun typst-ts-core-column-at-pos (point)
diff --git a/typst-ts-editing.el b/typst-ts-editing.el
index 1f20d2d20c..e1c7edd6be 100644
--- a/typst-ts-editing.el
+++ b/typst-ts-editing.el
@@ -129,11 +129,19 @@ When prefix ARG is non-nil, call global return function."
                       (save-excursion
                         (forward-line 1)
                         (point))))
-                    (next-line-top-item-node
+                    (next-line-top-node  ; get container type or `item' type 
node
                      (typst-ts-core-parent-util-type
-                      next-line-node "item" t t)))
+                      next-line-node
+                      (regexp-opt
+                       (append
+                        typst-ts-core--container-node-types
+                        '("item")))
+                      t)))
                (if has-children
-                   (if (and next-line-top-item-node
+                   ;; example:
+                   ;; - #[| <- return
+                   ;; ]
+                   (if (and next-line-top-node
                             ;; end of buffer situation (or next line is the end
                             ;; line (and no newline character))
                             (not (equal
diff --git a/typst-ts-mode.el b/typst-ts-mode.el
index fbaae6266e..b22094e010 100644
--- a/typst-ts-mode.el
+++ b/typst-ts-mode.el
@@ -471,12 +471,12 @@ NODE, PARENT and BOL see `treesit-simple-indent-rules'."
   ;; see `typst-ts-mode-electric-pair-open-newline-between-pairs-psif'
   ;; It may be better to turn off `electric-pair-open-newline-between-pairs'
   `((typst
-     ;; ((lambda (node parent bol)  ; NOTE
-     ;;    (message "%s %s %s %s %s" node parent
-     ;;             (treesit-node-parent parent)
-     ;;             (treesit-node-parent (treesit-node-parent parent)) bol)
-     ;;    nil)
-     ;;  parent-bol 0)
+     ((lambda (node parent bol)  ; NOTE
+        (message "%s %s %s %s %s" node parent
+                 (treesit-node-parent parent)
+                 (treesit-node-parent (treesit-node-parent parent)) bol)
+        nil)
+      parent-bol 0)
 
      ((and no-node (parent-is "source_file")) prev-line 0)
      ((parent-is "source_file") column-0 0)
@@ -519,7 +519,15 @@ NODE, PARENT and BOL see `treesit-simple-indent-rules'."
      
      ;; item - new item content should follow its previous line's indentation
      ;; level
-     ((and no-node typst-ts-mode--indentation-prev-line-is-item-p)
+     ((and no-node
+           typst-ts-mode--indentation-prev-line-is-item-p
+           ;; not in container
+           ;; example:
+           ;; - hi
+           ;;   hi #[
+           ;;     - hello | <- return
+           ;;   ]
+           (not (n-p-gp nil "parbreak" 
,typst-ts-mode--container-node-types-regexp)))
       typst-ts-mode--indentation-multiline-item-get-anchor_ 0)
 
      ;; raw block
@@ -719,10 +727,12 @@ typst tree sitter grammar (at least %s)!" 
(current-time-string min-time))
   ;; provides outline ellipsis (if you use `set-display-table-slot' to set)
   (outline-minor-mode t)
 
+  ;; FIXME
   ;; necessary for
   ;; `typst-ts-mode-cycle'(`typst-ts-editing--indent-item-node-lines')
-  ;; and indentation to work 
-  ;; (indent-tabs-mode -1)
+  ;; since it calculate offset based on character
+  ;; (maybe also some indentation rules)
+  (indent-tabs-mode -1)
 
   (typst-ts-mode-check-grammar-version))
 

Reply via email to