aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
Diffstat (limited to 'admin')
-rw-r--r--admin/notes/tree-sitter/starter-guide38
1 files changed, 26 insertions, 12 deletions
diff --git a/admin/notes/tree-sitter/starter-guide b/admin/notes/tree-sitter/starter-guide
index 378ff581afa..e5736038622 100644
--- a/admin/notes/tree-sitter/starter-guide
+++ b/admin/notes/tree-sitter/starter-guide
@@ -350,24 +350,38 @@ node.
350Something like this should suffice: 350Something like this should suffice:
351 351
352#+begin_src elisp 352#+begin_src elisp
353(defun xxx-beginning-of-defun (&optional arg) 353(defun js--treesit-beginning-of-defun (&optional arg)
354 (if (> arg 0) 354 (let ((arg (or arg 1)))
355 ;; Go backward. 355 (if (> arg 0)
356 ;; Go backward.
357 (while (and (> arg 0)
358 (treesit-search-forward-goto
359 "function_definition" 'start nil t))
360 (setq arg (1- arg)))
361 ;; Go forward.
362 (while (and (< arg 0)
363 (treesit-search-forward-goto
364 "function_definition" 'start))
365 (setq arg (1+ arg))))))
366
367(defun xxx-end-of-defun (&optional arg)
368 (let ((arg (or arg 1)))
369 (if (< arg 0)
370 ;; Go backward.
371 (while (and (< arg 0)
372 (treesit-search-forward-goto
373 "function_definition" 'end nil t))
374 (setq arg (1+ arg)))
375 ;; Go forward.
356 (while (and (> arg 0) 376 (while (and (> arg 0)
357 (treesit-search-forward-goto 377 (treesit-search-forward-goto
358 "function_definition" 'start nil t)) 378 "function_definition" 'end))
359 (setq arg (1- arg))) 379 (setq arg (1- arg))))))
360 ;; Go forward.
361 (while (and (< arg 0)
362 (treesit-search-forward-goto
363 "function_definition" 'start))
364 (setq arg (1+ arg)))))
365 380
366(setq-local beginning-of-defun-function #'xxx-beginning-of-defun) 381(setq-local beginning-of-defun-function #'xxx-beginning-of-defun)
382(setq-local end-of-defun-function #'xxx-end-of-defun)
367#+end_src 383#+end_src
368 384
369And the same for end-of-defun.
370
371* Which-func 385* Which-func
372 386
373You can find the current function by going up the tree and looking for 387You can find the current function by going up the tree and looking for