GNU bug report logs -
#76679
31.0.50; forward-sentence not working in the narrowed buffer under c-ts-mode
Previous Next
Reported by: lorniu <lorniu <at> gmail.com>
Date: Sun, 2 Mar 2025 10:23:02 UTC
Severity: normal
Tags: moreinfo
Merged with 76497
Fixed in version 31.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 76679 in the body.
You can then email your comments to 76679 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Sun, 02 Mar 2025 10:23:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
lorniu <lorniu <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 02 Mar 2025 10:23:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
The code `(forward-thing 'sentence)' is not working in narrowed region
under c-ts-mode.
For example, open file `test.c`, then turn on `c-ts-mode', what in the
buffer is:
int main () { return 0; }
Now select word `return' and execute `narrow-to-region', then in buffer:
Ireturn
where `I' represent the cursor. Now execute:
(forward-thing 'sentence)
Then you will find that the cursor is stay still, not moving to the
end. This behavior is not like the ones anywhere else, I think it's a bug.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Sun, 09 Mar 2025 09:58:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 76679 <at> debbugs.gnu.org (full text, mbox):
> From: lorniu <lorniu <at> gmail.com>
> Date: Sun, 02 Mar 2025 15:44:48 +0800
>
>
> The code `(forward-thing 'sentence)' is not working in narrowed region
> under c-ts-mode.
>
> For example, open file `test.c`, then turn on `c-ts-mode', what in the
> buffer is:
>
> int main () { return 0; }
>
> Now select word `return' and execute `narrow-to-region', then in buffer:
>
> Ireturn
>
> where `I' represent the cursor. Now execute:
>
> (forward-thing 'sentence)
>
> Then you will find that the cursor is stay still, not moving to the
> end. This behavior is not like the ones anywhere else, I think it's a bug.
I'm not sure the notion of a "sentence" is well defined in C-like
languages.
Yuan and Juri, any comments or suggestions?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Mon, 10 Mar 2025 18:38:03 GMT)
Full text and
rfc822 format available.
Message #11 received at 76679 <at> debbugs.gnu.org (full text, mbox):
>> The code `(forward-thing 'sentence)' is not working in narrowed region
>> under c-ts-mode.
>>
>> For example, open file `test.c`, then turn on `c-ts-mode', what in the
>> buffer is:
>>
>> int main () { return 0; }
>>
>> Now select word `return' and execute `narrow-to-region', then in buffer:
>>
>> Ireturn
>>
>> where `I' represent the cursor. Now execute:
>>
>> (forward-thing 'sentence)
>>
>> Then you will find that the cursor is stay still, not moving to the
>> end. This behavior is not like the ones anywhere else, I think it's a bug.
>
> I'm not sure the notion of a "sentence" is well defined in C-like
> languages.
>
> Yuan and Juri, any comments or suggestions?
We agreed that a "sentence" in C-like languages is a thing that
ends with a semicolon (or a comma that separates arguments).
However, this report raises a different question: whether forward-sentence
should navigate to the end of the narrowed region when the semicolon is hidden?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Mon, 10 Mar 2025 19:19:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 76679 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> We agreed that a "sentence" in C-like languages is a thing that
> ends with a semicolon (or a comma that separates arguments).
>
> However, this report raises a different question: whether forward-sentence
> should navigate to the end of the narrowed region when the semicolon is hidden?
Isn't that what forward-sentence does in e.g. text-mode? So wouldn't
doing that in C-like languages be consistent with that?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Tue, 11 Mar 2025 07:35:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 76679 <at> debbugs.gnu.org (full text, mbox):
>> We agreed that a "sentence" in C-like languages is a thing that
>> ends with a semicolon (or a comma that separates arguments).
>>
>> However, this report raises a different question: whether forward-sentence
>> should navigate to the end of the narrowed region when the semicolon is hidden?
>
> Isn't that what forward-sentence does in e.g. text-mode? So wouldn't
> doing that in C-like languages be consistent with that?
When you set the end of the narrowed region at the middle
of the sentence either in text-mode or in C-like languages,
then use forward-sentence to move the end of the narrowed region,
then widen with 'C-x n w', point will be not at the end
of the sentence. This behavior makes no sense.
Regardless of the fact that treesit-forward-sentence works
differently from forward-sentence, their both results make no sense.
There is no meaningful difference whether to keep point at its old
position as treesit-forward-sentence does, or move point to the
middle of the sentence as forward-sentence does.
So I think there is no bug here.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Tue, 11 Mar 2025 12:01:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 76679 <at> debbugs.gnu.org (full text, mbox):
> From: Juri Linkov <juri <at> linkov.net>
> Cc: lorniu <lorniu <at> gmail.com>, Yuan Fu <casouri <at> gmail.com>,
> 76679 <at> debbugs.gnu.org
> Date: Mon, 10 Mar 2025 20:28:12 +0200
>
> >> The code `(forward-thing 'sentence)' is not working in narrowed region
> >> under c-ts-mode.
> >>
> >> For example, open file `test.c`, then turn on `c-ts-mode', what in the
> >> buffer is:
> >>
> >> int main () { return 0; }
> >>
> >> Now select word `return' and execute `narrow-to-region', then in buffer:
> >>
> >> Ireturn
> >>
> >> where `I' represent the cursor. Now execute:
> >>
> >> (forward-thing 'sentence)
> >>
> >> Then you will find that the cursor is stay still, not moving to the
> >> end. This behavior is not like the ones anywhere else, I think it's a bug.
> >
> > I'm not sure the notion of a "sentence" is well defined in C-like
> > languages.
> >
> > Yuan and Juri, any comments or suggestions?
>
> We agreed that a "sentence" in C-like languages is a thing that
> ends with a semicolon (or a comma that separates arguments).
>
> However, this report raises a different question: whether forward-sentence
> should navigate to the end of the narrowed region when the semicolon is hidden?
Nothing else would make sense. Almost all Emacs commands behave like
there's nothing beyond the end of the narrowed region. The few
exceptions are only in very specialized cases, which this one isn't,
because it's just a movement command.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Tue, 11 Mar 2025 13:19:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 76679 <at> debbugs.gnu.org (full text, mbox):
> From: Juri Linkov <juri <at> linkov.net>
> Cc: Eli Zaretskii <eliz <at> gnu.org>, 76679 <at> debbugs.gnu.org, lorniu
> <lorniu <at> gmail.com>, Yuan Fu <casouri <at> gmail.com>
> Date: Tue, 11 Mar 2025 09:24:05 +0200
>
> >> We agreed that a "sentence" in C-like languages is a thing that
> >> ends with a semicolon (or a comma that separates arguments).
> >>
> >> However, this report raises a different question: whether forward-sentence
> >> should navigate to the end of the narrowed region when the semicolon is hidden?
> >
> > Isn't that what forward-sentence does in e.g. text-mode? So wouldn't
> > doing that in C-like languages be consistent with that?
>
> When you set the end of the narrowed region at the middle
> of the sentence either in text-mode or in C-like languages,
> then use forward-sentence to move the end of the narrowed region,
> then widen with 'C-x n w', point will be not at the end
> of the sentence. This behavior makes no sense.
Why does it not make sense? What else would you expect a movement
command to do?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Tue, 11 Mar 2025 14:42:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 76679 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
>>> We agreed that a "sentence" in C-like languages is a thing that
>>> ends with a semicolon (or a comma that separates arguments).
>>>
>>> However, this report raises a different question: whether forward-sentence
>>> should navigate to the end of the narrowed region when the semicolon is hidden?
>>
>> Isn't that what forward-sentence does in e.g. text-mode? So wouldn't
>> doing that in C-like languages be consistent with that?
>
> When you set the end of the narrowed region at the middle
> of the sentence either in text-mode or in C-like languages,
> then use forward-sentence to move the end of the narrowed region,
> then widen with 'C-x n w', point will be not at the end
> of the sentence. This behavior makes no sense.
>
> Regardless of the fact that treesit-forward-sentence works
> differently from forward-sentence, their both results make no sense.
>
> There is no meaningful difference whether to keep point at its old
> position as treesit-forward-sentence does, or move point to the
> middle of the sentence as forward-sentence does.
>
> So I think there is no bug here.
Doesn't it make sense to be consistent with `fundamental-mode`?
Consider this case:
(progn
(get-buffer-create "mybuf99")
(pop-to-buffer "mybuf99")
(erase-buffer)
(insert "sentence sentence sentence.")
(goto-char (point-min))
(narrow-to-region (point-min) 15)
(forward-sentence)
(widen))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Tue, 11 Mar 2025 17:23:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 76679 <at> debbugs.gnu.org (full text, mbox):
>> However, this report raises a different question: whether forward-sentence
>> should navigate to the end of the narrowed region when the semicolon is hidden?
>
> Nothing else would make sense. Almost all Emacs commands behave like
> there's nothing beyond the end of the narrowed region. The few
> exceptions are only in very specialized cases, which this one isn't,
> because it's just a movement command.
Ok, this patch provides the same behavior as for forward-sentence:
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 319dc5a41fc..f94c97c2e7c 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -3417,9 +3417,10 @@ treesit-forward-sentence
by `text' and `sentence' in `treesit-thing-settings'."
(if (treesit-node-match-p (treesit-node-at (point)) 'text t)
(funcall #'forward-sentence-default-function arg)
- (funcall
- (if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
- 'sentence (abs arg))))
+ (or (funcall
+ (if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
+ 'sentence (abs arg))
+ (goto-char (if (> arg 0) (point-max) (point-min))))))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76679
; Package
emacs
.
(Thu, 13 Mar 2025 18:47:01 GMT)
Full text and
rfc822 format available.
Message #32 received at 76679 <at> debbugs.gnu.org (full text, mbox):
merge 76679 76497
close 76679 31.0.50
thanks
> @@ -3417,9 +3417,10 @@ treesit-forward-sentence
> by `text' and `sentence' in `treesit-thing-settings'."
> (if (treesit-node-match-p (treesit-node-at (point)) 'text t)
> (funcall #'forward-sentence-default-function arg)
> - (funcall
> - (if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
> - 'sentence (abs arg))))
> + (or (funcall
> + (if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
> + 'sentence (abs arg))
> + (goto-char (if (> arg 0) (point-max) (point-min))))))
Actually this is not so simple, because also need to handle
range boundaries as well. So pushed the change that stops
at the 'treesit-parser' overlay's end.
Merged 76497 76679.
Request was from
Juri Linkov <juri <at> linkov.net>
to
control <at> debbugs.gnu.org
.
(Thu, 13 Mar 2025 18:48:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 31.0.50, send any further explanations to
76679 <at> debbugs.gnu.org and lorniu <lorniu <at> gmail.com>
Request was from
Juri Linkov <juri <at> linkov.net>
to
control <at> debbugs.gnu.org
.
(Thu, 13 Mar 2025 18:48:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 11 Apr 2025 11:24:10 GMT)
Full text and
rfc822 format available.
This bug report was last modified 27 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.