From: Juri Linkov <juri@linkov.net>
To: 70789@debbugs.gnu.org
Cc: Yuan Fu <casouri@gmail.com>
Subject: bug#70789: treesit navigate for outlines at bobp
Date: Sun, 05 May 2024 19:52:43 +0300 [thread overview]
Message-ID: <86seywi4kk.fsf@mail.linkov.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 414 bytes --]
'treesit-outline-search' didn't match outlines at the beginning of
the buffer because unlike 're-search-forward' (used by outline-mode)
that matches the text that immediately follows point,
'treesit-navigate-thing' misses text at point and stars the search
after point.
So there is a need to handle this difference specially. Therefore this
patch adds such special-handling of bobp to 'treesit-outline-search':
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: treesit-outline-search-bobp.patch --]
[-- Type: text/x-diff, Size: 1493 bytes --]
diff --git a/lisp/treesit.el b/lisp/treesit.el
index e55e04e53b3..86ed1bbae33 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2884,15 +2884,21 @@ treesit-outline-search
(start (treesit-node-start node)))
(eq (pos-bol) (save-excursion (goto-char start) (pos-bol))))
- (let* ((pos
+ (let* ((bob-pos
+ ;; `treesit-navigate-thing' can't find a thing at bobp,
+ ;; so use `looking-at' to match at bobp.
+ (and (bobp) (treesit-outline-search bound move backward t) (point)))
+ (pos
;; When function wants to find the current outline, point
;; is at the beginning of the current line. When it wants
;; to find the next outline, point is at the second column.
- (if (eq (point) (pos-bol))
- (if (bobp) (point) (1- (point)))
- (pos-eol)))
- (found (treesit-navigate-thing pos (if backward -1 1) 'beg
- treesit-outline-predicate)))
+ (unless bob-pos
+ (if (eq (point) (pos-bol))
+ (if (bobp) (point) (1- (point)))
+ (pos-eol))))
+ (found (or bob-pos
+ (treesit-navigate-thing pos (if backward -1 1) 'beg
+ treesit-outline-predicate))))
(if found
(if (or (not bound) (if backward (>= found bound) (<= found bound)))
(progn
next reply other threads:[~2024-05-05 16:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-05 16:52 Juri Linkov [this message]
2024-05-06 3:11 ` bug#70789: treesit navigate for outlines at bobp Yuan Fu
2024-05-06 6:43 ` Juri Linkov
2024-05-09 0:16 ` Yuan Fu
2024-05-09 6:28 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86seywi4kk.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=70789@debbugs.gnu.org \
--cc=casouri@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).