diff options
author | Juri Linkov <juri@linkov.net> | 2024-12-29 19:42:40 +0200 |
---|---|---|
committer | Juri Linkov <juri@linkov.net> | 2024-12-29 19:42:40 +0200 |
commit | 3db984c72b8609c84f06a0fd62e59b4823ea0876 (patch) | |
tree | 791df014ca185b20fc8c2a5011d02606c20c5e41 /lisp/emacs-lisp | |
parent | c85d2e3519bf93837cead012a8281ee9bb4be9a8 (diff) | |
download | emacs-3db984c72b8609c84f06a0fd62e59b4823ea0876.tar.gz emacs-3db984c72b8609c84f06a0fd62e59b4823ea0876.tar.bz2 emacs-3db984c72b8609c84f06a0fd62e59b4823ea0876.zip |
Add new variable 'forward-list-function' for 'treesit-forward-list'
* lisp/emacs-lisp/lisp.el (forward-list-default-function): New function.
(forward-list-function): New variable (bug#73404).
(forward-list): Move meat to 'forward-list-default-function',
and call 'forward-list-function' when non-nil.
* lisp/treesit.el (treesit-forward-list): Rewrite to not rely on
'treesit-forward-sexp'.
(treesit-major-mode-setup): Set 'forward-list-function' to
'treesit-forward-list'.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/lisp.el | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index c9e27e78c33..e45064a459b 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -143,6 +143,14 @@ This command assumes point is not in a string or comment." (point)) nil t)))) +(defun forward-list-default-function (&optional arg) + "Default function for `forward-list-function'." + (goto-char (or (scan-lists (point) arg 0) (buffer-end arg)))) + +(defvar forward-list-function nil + "If non-nil, `forward-list' delegates to this function. +Should take the same arguments and behave similarly to `forward-list'.") + (defun forward-list (&optional arg interactive) "Move forward across one balanced group of parentheses. This command will also work on other parentheses-like expressions @@ -150,6 +158,7 @@ defined by the current language mode. With ARG, do it that many times. Negative arg -N means move backward across N groups of parentheses. This command assumes point is not in a string or comment. +Calls `forward-list-function' to do the work, if that is non-nil. If INTERACTIVE is non-nil, as it is interactively, report errors as appropriate for this kind of usage." (interactive "^p\nd") @@ -160,7 +169,9 @@ report errors as appropriate for this kind of usage." "No next group" "No previous group")))) (or arg (setq arg 1)) - (goto-char (or (scan-lists (point) arg 0) (buffer-end arg))))) + (if forward-list-function + (funcall forward-list-function arg) + (forward-list-default-function arg)))) (defun backward-list (&optional arg interactive) "Move backward across one balanced group of parentheses. @@ -169,6 +180,7 @@ defined by the current language mode. With ARG, do it that many times. Negative arg -N means move forward across N groups of parentheses. This command assumes point is not in a string or comment. +Uses `forward-list' to do the work. If INTERACTIVE is non-nil, as it is interactively, report errors as appropriate for this kind of usage." (interactive "^p\nd") |