branch: elpa/typst-ts-mode
commit 0728efcbd94420753a813d538855b4f7168fdfcd
Author: Meow King <mr.meowk...@anche.no>
Commit: Meow King <mr.meowk...@anche.no>

    refactor
---
 typst-ts-core.el    | 18 +++++++++++++-----
 typst-ts-editing.el |  8 +++-----
 typst-ts-mode.el    |  4 ----
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/typst-ts-core.el b/typst-ts-core.el
index 8b7b5fd9e3..fab4ba780f 100644
--- a/typst-ts-core.el
+++ b/typst-ts-core.el
@@ -27,6 +27,11 @@
 ;; code from Emacs binary
 (declare-function treesit-parser-list "treesit" t t)
 
+(defcustom typst-ts-mode-indent-offset 4
+  "Number of spaces for each indentation step in `typst-ts-mode'."
+  :type 'natnum
+  :group 'typst-ts)
+
 (defun typst-ts-core-column-at-pos (point)
   "Get the column at position POINT."
   (save-excursion
@@ -40,17 +45,20 @@
     (back-to-indentation)
     (point)))
 
-(defun typst-ts-core-get-node-at-bol-nonwhite ()
-  "Get node at the first non-whitespace character at line beginning."
+(defun typst-ts-core-get-node-at-bol-nonwhite (&optional pos)
+  "Get node at the first non-whitespace character at line beginning.
+If POS is given, operate on the line that POS locates at."
   (save-excursion
+    (when pos
+      (goto-char pos))
     (back-to-indentation)
     (treesit-node-at (point))))
 
-(defun typst-ts-core-get-parent-of-node-at-bol-nonwhite ()
+(defun typst-ts-core-get-parent-of-node-at-bol-nonwhite (&optional pos)
   "See `typst-ts-core-get-node-at-bol-nonwhite'.
-May return nil."
+POS.  May return nil."
   (treesit-node-parent
-   (typst-ts-core-get-node-at-bol-nonwhite)))
+   (typst-ts-core-get-node-at-bol-nonwhite pos)))
 
 (defun typst-ts-core-node-get (node instructions)
   "Get things from NODE by INSTRUCTIONS.
diff --git a/typst-ts-editing.el b/typst-ts-editing.el
index 33febea742..d9fc4365a7 100644
--- a/typst-ts-editing.el
+++ b/typst-ts-editing.el
@@ -239,10 +239,9 @@ When there is no section it will insert a heading below 
point."
                           (goto-char prev-nonwhite-pos)
                           (back-to-indentation)
                           (point)))
-                       (prev-nonwhite-line-heading-node
-                        (treesit-node-at prev-nonwhite-line-bol))
-                       (prev-nonwhite-line-top-node (treesit-node-parent
-                                                     
prev-nonwhite-line-heading-node))
+                       (prev-nonwhite-line-top-node
+                        (treesit-node-parent
+                         (treesit-node-at prev-nonwhite-line-bol)))
                        (cur-line-bol-column (typst-ts-core-column-at-pos 
cur-line-bol))
                        (prev-nonwhite-line-bol-column
                         (typst-ts-core-column-at-pos prev-nonwhite-line-bol)))
@@ -251,7 +250,6 @@ When there is no section it will insert a heading below 
point."
               ;; 2. psy| <- can toggle indent
               ((and
                 (equal (treesit-node-type prev-nonwhite-line-top-node) "item")
-                (equal (treesit-node-type prev-nonwhite-line-heading-node) "-")
                 ;; previous nonwhite-line ending is not '\' character
                 (not (equal (treesit-node-type prev-nonwhite-line-node) 
"linebreak")))
                ;; TODO cycle all its children
diff --git a/typst-ts-mode.el b/typst-ts-mode.el
index 63b3c3c298..2dc59b9b21 100644
--- a/typst-ts-mode.el
+++ b/typst-ts-mode.el
@@ -50,10 +50,6 @@
   :group 'text
   :group 'languages)
 
-(defcustom typst-ts-mode-indent-offset 4
-  "Number of spaces for each indentation step in `typst-ts-mode'."
-  :type 'natnum
-  :group 'typst-ts)
 
 (defcustom typst-ts-mode-grammar-location nil
   "Specify typst tree sitter grammar file location.

Reply via email to