diff options
author | Yuan Fu <casouri@gmail.com> | 2022-12-29 01:28:25 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2022-12-29 01:43:28 -0800 |
commit | 38c35bf0f6a938001dfecbe439addf8fb62897c6 (patch) | |
tree | c75c8993ade96e58380526affb308598308f1251 /lisp | |
parent | 9371d488be62a37788b499a7e44b1f5db158e212 (diff) | |
download | emacs-38c35bf0f6a938001dfecbe439addf8fb62897c6.tar.gz emacs-38c35bf0f6a938001dfecbe439addf8fb62897c6.tar.bz2 emacs-38c35bf0f6a938001dfecbe439addf8fb62897c6.zip |
Clean up treesit-default-defun-skipper and add comments
* lisp/treesit.el (treesit-default-defun-skipper): Clean up, fix some
small issue, add comment.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/treesit.el | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 4ee0fba79b7..0ba4395a6b4 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -1744,13 +1744,17 @@ this function depends on `treesit-defun-type-regexp' and This function tries to move to the beginning of a line, either by moving to the empty newline after a defun, or to the beginning of the current line if the beginning of the defun is indented." - (cond ((and (looking-at (rx (* (or " " "\\t")) "\n")) - (not (looking-at (rx bol)))) - (goto-char (match-end 0))) - ((save-excursion - (skip-chars-backward " \t") - (eq (point) (line-beginning-position))) - (goto-char (line-beginning-position))))) + ;; Moving forward, point at the end of a line and not already on an + ;; empty line: go to BOL of the next line (which hopefully is an + ;; empty line). + (cond ((and (looking-at (rx (* (or " " "\t")) "\n")) + (not (bolp))) + (forward-line 1)) + ;; Moving backward, but there are some whitespace (and only + ;; whitespace) between point and BOL: go back to BOL. + ((looking-back (rx (+ (or " " "\t"))) + (line-beginning-position)) + (beginning-of-line)))) ;; prev-sibling: ;; 1. end-of-node before pos |