GNU bug report logs - #28645
26.0.50; semantic-ia-fast-jump jumps to a random place in buffer

Previous Next

Package: emacs;

Reported by: Constantine <hi-angel <at> yandex.ru>

Date: Fri, 29 Sep 2017 13:25:01 UTC

Severity: normal

Found in version 26.0.50

Done: Dmitry Gutov <dgutov <at> yandex.ru>

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 28645 in the body.
You can then email your comments to 28645 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Fri, 29 Sep 2017 13:25:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Constantine <hi-angel <at> yandex.ru>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 29 Sep 2017 13:25:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Constantine <hi-angel <at> yandex.ru>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.0.50; semantic-ia-fast-jump jumps to a random place in buffer
Date: Fri, 29 Sep 2017 16:23:54 +0300
When declaration is in another buffer, semantic-ia-fast-jump often
jumps to this buffer, but to incorrect line. However if the
declaration is in the same buffer where the command was used, it always
— as far as I've seen — jumps to the correct line.

Steps to reproduce:

1. Create the following 2 files with the following content:
    $ grep -n "" myfunc.h test.cpp
    myfunc.h:1:void myfunc1() {
    myfunc.h:2:}
    myfunc.h:3:void myfunc2() {
    myfunc.h:4:}
    test.cpp:1:#include "myfunc.h"
    test.cpp:2:
    test.cpp:3:int main() {
    test.cpp:4:     myfunc1();
    test.cpp:5:     myfunc2();
    test.cpp:6:}
2. Run emacs -Q test.cpp
3. Enable `M-x semantic-mode`
4. Put cursor into "myfunc2", and type `M-x semantic-ia-fast-jump`
    (you'll see it jumped to the correct declaration at myfunc.h file)
5. Use `C-x b RET` to switch back to test.cpp
6. Put cursor into "myfunc1", and type `M-x semantic-ia-fast-jump`

Result: it jumped to "myfunc2" declaration, not to "myfunc1" as it ought to.

I also want to note that though ATM I am using emacs-git, I've seen the
problem for don't remember how long, just didn't report.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Fri, 29 Sep 2017 14:43:01 GMT) Full text and rfc822 format available.

Message #8 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Constantine <hi-angel <at> yandex.ru>, 28645 <at> debbugs.gnu.org
Cc: martin rudalics <rudalics <at> gmx.at>
Subject: Re: bug#28645: 26.0.50; semantic-ia-fast-jump jumps to a random place
 in buffer
Date: Fri, 29 Sep 2017 16:42:16 +0200
On 9/29/17 3:23 PM, Constantine wrote:
'> Result: it jumped to "myfunc2" declaration, not to "myfunc1" as it ought
> to.
> 
> I also want to note that though ATM I am using emacs-git, I've seen the
> problem for don't remember how long, just didn't report.

Thanks for the report. You appear to have fallen victim of our windowing 
improvements. I'm not sure this is the correct fix (Martin?), but here's 
a patch that seems to correct the behavior.

diff --git a/lisp/cedet/semantic/ia.el b/lisp/cedet/semantic/ia.el
index d4201fcf51..0692d03aca 100644
--- a/lisp/cedet/semantic/ia.el
+++ b/lisp/cedet/semantic/ia.el
@@ -322,7 +322,8 @@ semantic-ia--fast-jump-helper
   (semantic-go-to-tag dest)
   ;; 3) go-to-tag doesn't switch the buffer in the current window,
   ;;    so it is like find-file-noselect.  Bring it forward.
-  (switch-to-buffer (current-buffer))
+  (let (switch-to-buffer-preserve-window-point)
+    (switch-to-buffer (current-buffer)))
   ;; 4) Fancy pulsing.
   (pulse-momentary-highlight-one-line (point))
   )




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Fri, 29 Sep 2017 14:58:01 GMT) Full text and rfc822 format available.

Message #11 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Constantine <hi-angel <at> yandex.ru>
To: Dmitry Gutov <dgutov <at> yandex.ru>, 28645 <at> debbugs.gnu.org
Subject: Re: bug#28645: 26.0.50; semantic-ia-fast-jump jumps to a random place
 in buffer
Date: Fri, 29 Sep 2017 17:57:11 +0300
On 29.09.2017 17:42, Dmitry Gutov wrote:
> On 9/29/17 3:23 PM, Constantine wrote:
> '> Result: it jumped to "myfunc2" declaration, not to "myfunc1" as it ought
>> to.
>>
>> I also want to note that though ATM I am using emacs-git, I've seen the
>> problem for don't remember how long, just didn't report.
> 
> Thanks for the report. You appear to have fallen victim of our windowing 
> improvements. I'm not sure this is the correct fix (Martin?), but here's 
> a patch that seems to correct the behavior.
> 
> diff --git a/lisp/cedet/semantic/ia.el b/lisp/cedet/semantic/ia.el
> index d4201fcf51..0692d03aca 100644
> --- a/lisp/cedet/semantic/ia.el
> +++ b/lisp/cedet/semantic/ia.el
> @@ -322,7 +322,8 @@ semantic-ia--fast-jump-helper
>     (semantic-go-to-tag dest)
>     ;; 3) go-to-tag doesn't switch the buffer in the current window,
>     ;;    so it is like find-file-noselect.  Bring it forward.
> -  (switch-to-buffer (current-buffer))
> +  (let (switch-to-buffer-preserve-window-point)
> +    (switch-to-buffer (current-buffer)))
>     ;; 4) Fancy pulsing.
>     (pulse-momentary-highlight-one-line (point))
>     )

Yay, thank you, works for me!

Tested-by: Constantine Kharlamov <Hi-Angel <at> yandex.ru>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Fri, 29 Sep 2017 18:19:02 GMT) Full text and rfc822 format available.

Message #14 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Dmitry Gutov <dgutov <at> yandex.ru>, Constantine <hi-angel <at> yandex.ru>, 
 28645 <at> debbugs.gnu.org
Subject: Re: bug#28645: 26.0.50; semantic-ia-fast-jump jumps to a random place
 in buffer
Date: Fri, 29 Sep 2017 20:18:05 +0200
> +  (let (switch-to-buffer-preserve-window-point)
> +    (switch-to-buffer (current-buffer)))

I think (pop-to-buffer-same-window (current-buffer)) should be used
instead.

martin




Reply sent to Dmitry Gutov <dgutov <at> yandex.ru>:
You have taken responsibility. (Sat, 30 Sep 2017 14:20:01 GMT) Full text and rfc822 format available.

Notification sent to Constantine <hi-angel <at> yandex.ru>:
bug acknowledged by developer. (Sat, 30 Sep 2017 14:20:02 GMT) Full text and rfc822 format available.

Message #19 received at 28645-done <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: martin rudalics <rudalics <at> gmx.at>, Constantine <hi-angel <at> yandex.ru>,
 28645-done <at> debbugs.gnu.org
Subject: Re: bug#28645: 26.0.50; semantic-ia-fast-jump jumps to a random place
 in buffer
Date: Sat, 30 Sep 2017 16:19:37 +0200
On 9/29/17 8:18 PM, martin rudalics wrote:
>  > +  (let (switch-to-buffer-preserve-window-point)
>  > +    (switch-to-buffer (current-buffer)))
> 
> I think (pop-to-buffer-same-window (current-buffer)) should be used
> instead.

Done.

Thanks all!




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Tue, 03 Oct 2017 09:42:01 GMT) Full text and rfc822 format available.

Message #22 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Bastian Beischer <bastian.beischer <at> gmail.com>
To: bug#28645 <28645 <at> debbugs.gnu.org>
Cc: rudalics <at> gmx.at, dgutov <at> yandex.ru
Subject: Re: Status: 26.0.50;
 semantic-ia-fast-jump jumps to a random place in buffer
Date: Tue, 03 Oct 2017 11:40:58 +0200
Hey,

Thanks for the fix in semantic-ia-fast-jump Dmitry and Martin. However,
I think there are more places which need to be fixed in CEDET. A quick
search for switch-to-buffer shows these in lisp/cedet:

$ grep -n -e 'switch-to-buffer' lisp/cedet
./semantic/decorate/include.el:470:     (switch-to-buffer (get-file-buffer file)))
./semantic/imenu.el:180:                  (switch-to-buffer ob))
./semantic/debug.el:156:      (switch-to-buffer (oref iface data-buffer))
./semantic/debug.el:160:  (switch-to-buffer (oref iface parser-buffer))
./semantic/debug.el:166:  (switch-to-buffer (oref iface source-buffer))
./semantic/debug.el:453:      (switch-to-buffer buf))
./semantic/debug.el:467:      (switch-to-buffer buf))
./semantic/bovine/c.el:980:     (switch-to-buffer (get-buffer-create "*MODE HACK TEST*"))
./semantic/bovine/c.el:992:    (switch-to-buffer-other-window
./semantic/complete.el:1533:    (switch-to-buffer-other-window buf t)
./semantic/complete.el:2123:      (switch-to-buffer (current-buffer))
./semantic/symref/list.el:182:    (switch-to-buffer-other-window buff)
./semantic/symref/list.el:314:    (switch-to-buffer-other-window buff)
./semantic/symref/list.el:328:    (switch-to-buffer-other-window buff)
./semantic/symref/list.el:344:    (switch-to-buffer-other-window buff)
./semantic/symref/list.el:420:    (switch-to-buffer-other-window (semantic-tag-buffer tag))
./semantic/symref/list.el:440:              (switch-to-buffer (current-buffer))
./semantic/sb.el:320:    (switch-to-buffer (current-buffer))
./semantic/analyze/refs.el:351:    (switch-to-buffer (current-buffer))
./semantic/mru-bookmark.el:116:    (switch-to-buffer (current-buffer))
./semantic/texi.el:630:;;       (switch-to-buffer docbuff))
./semantic/texi.el:675:   (switch-to-buffer (semantic-tag-buffer (car tags)))
./semantic/senator.el:533:      (switch-to-buffer (current-buffer))
./semantic/senator.el:537:      (switch-to-buffer result)
./semantic/senator.el:741:                              (switch-to-buffer (semantic-tag-buffer v))
./semantic.el:1081: `global-semantic-mru-bookmark-mode'   - Provide `switch-to-buffer'-like
./srecode/getset.el:263:    (switch-to-buffer (current-buffer))
./ede/custom.el:103:    (switch-to-buffer (get-buffer-create "*EDE sort targets*"))
./ede/shell.el:44:      (switch-to-buffer-other-window buff t))

I was able to reproduce the bug in "semantic-complete-jump" and
"semantic-analyze-proto-impl-toggle", for example.

I would also be grateful for a little bit of background information. At
which point did it become necessary to use 'pop-to-buffer' instead of
'switch-to-buffer'? Apparently 'semantic-ia-fast-jump' et al worked fine
in older emacs versions.

When is it ok to use 'switch-to-buffer'? There are numerous occurences
of it throughout emacs...

Thanks
Bastian




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Wed, 04 Oct 2017 09:04:02 GMT) Full text and rfc822 format available.

Message #25 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Bastian Beischer <bastian.beischer <at> gmail.com>, 
 bug#28645 <28645 <at> debbugs.gnu.org>
Cc: dgutov <at> yandex.ru
Subject: Re: Status: 26.0.50; semantic-ia-fast-jump jumps to a random place
 in buffer
Date: Wed, 04 Oct 2017 11:03:17 +0200
> I would also be grateful for a little bit of background information. At
> which point did it become necessary to use 'pop-to-buffer' instead of
> 'switch-to-buffer'? Apparently 'semantic-ia-fast-jump' et al worked fine
> in older emacs versions.
>
> When is it ok to use 'switch-to-buffer'? There are numerous occurences
> of it throughout emacs...

Consider the following scenario:

(1) ‘switch-to-buffer-preserve-window-point’ is t (it is so by default).

(2) An application explicitly sets point in a buffer that is currently
    not displayed in the selected window to a value different from the
    value of ‘window-point’ of that window at the last time this buffer
    was displayed there.

(3) The application wants to switch to the buffer in the selected window
    with ‘window-point’ at the position of point assigned in (2).

If the application used ‘switch-to-buffer’ in (3), then ‘window-point’
will be reset to the old location of ‘window-point’ which is obviously
not what the application wants.  So to get what it wants, an application
either has to bind ‘switch-to-buffer-preserve-window-point’ to nil
around the ‘switch-to-buffer’ call or use ‘pop-to-buffer-same-window’
(‘display-buffer-same-window’ if the window may remain unselected)
instead.

IMHO applications should never call ‘switch-to-buffer’.  They should
either call ‘pop-to-buffer’ - if the user is supposed to now continue
working in the window showing the buffer - and ‘display-buffer’ in all
other cases.  Both allow the user to control how to display the buffer.

Only if there is a clear preference that the buffer should be shown in
the _selected_ window, the ‘-same-window’ functions should be called.
And programmers should be aware that at the time they want to show a
buffer in the selected window, that window might be the minibuffer
window or a window dedicated to some other buffer.

martin





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Wed, 04 Oct 2017 11:12:02 GMT) Full text and rfc822 format available.

Message #28 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Bastian Beischer <bastian.beischer <at> gmail.com>
To: martin rudalics <rudalics <at> gmx.at>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>, Brief Busters <dgutov <at> yandex.ru>
Subject: Re: Status: 26.0.50;
 semantic-ia-fast-jump jumps to a random place in buffer
Date: Wed, 4 Oct 2017 13:11:13 +0200
Hey Martin,

On Wed, Oct 4, 2017 at 11:03 AM, martin rudalics <rudalics <at> gmx.at> wrote:
>> I would also be grateful for a little bit of background information. At
>> which point did it become necessary to use 'pop-to-buffer' instead of
>> 'switch-to-buffer'? Apparently 'semantic-ia-fast-jump' et al worked fine
>> in older emacs versions.
>>
>> When is it ok to use 'switch-to-buffer'? There are numerous occurences
>> of it throughout emacs...
>
> Consider the following scenario:
>
> (1) ‘switch-to-buffer-preserve-window-point’ is t (it is so by default).
>
> (2) An application explicitly sets point in a buffer that is currently
>     not displayed in the selected window to a value different from the
>     value of ‘window-point’ of that window at the last time this buffer
>     was displayed there.
>
> (3) The application wants to switch to the buffer in the selected window
>     with ‘window-point’ at the position of point assigned in (2).
>
> If the application used ‘switch-to-buffer’ in (3), then ‘window-point’
> will be reset to the old location of ‘window-point’ which is obviously
> not what the application wants.  So to get what it wants, an application
> either has to bind ‘switch-to-buffer-preserve-window-point’ to nil
> around the ‘switch-to-buffer’ call or use ‘pop-to-buffer-same-window’
> (‘display-buffer-same-window’ if the window may remain unselected)
> instead.
>
> IMHO applications should never call ‘switch-to-buffer’.  They should
> either call ‘pop-to-buffer’ - if the user is supposed to now continue
> working in the window showing the buffer - and ‘display-buffer’ in all
> other cases.  Both allow the user to control how to display the buffer.
>
> Only if there is a clear preference that the buffer should be shown in
> the _selected_ window, the ‘-same-window’ functions should be called.
> And programmers should be aware that at the time they want to show a
> buffer in the selected window, that window might be the minibuffer
> window or a window dedicated to some other buffer.

I understand. Then this must mean that the change in behavior in CEDET
was triggered with this commit:

commit ee297210cffb9e8d05912686a39fa158414ba050
Author: Mark Oteiza <mvoteiza <at> udel.edu>
Date:   Thu May 26 21:47:18 2016 -0400

   Preserve buffer point in windows by default (Bug#4041).

   * doc/lispref/windows.texi: Mention new default.
   * etc/NEWS: Mention new default.
   * lisp/window.el (switch-to-buffer-preserve-window-point): Default to t.

which is part of master and emacs-26 but was not part of any previous releases.

I also understand your other arguments. But the question is: While
your recommendation makes sense, there clearly still is a lot of code
which uses switch-to-buffer without binding
switch-to-buffer-preserve-window-point to nil and it wasn't fixed when
this variable's default was changed. This is true in lisp code shipped
in emacs and it is probably also true for lots of third party code in
the wild. Who is going to fix all this code? And if it turns out that
the fixing all this code is too difficult / impossible, is it
justified to fix bug #4041 at the cost of causing numerous other bugs
(which arguably are due to misuse of switch-to-buffer, but they will
have to be fixed either way)?

>
> martin
>

Cheers and thanks again for your answer.
Bastian




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Thu, 05 Oct 2017 08:11:02 GMT) Full text and rfc822 format available.

Message #31 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Bastian Beischer <bastian.beischer <at> gmail.com>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>, Brief Busters <dgutov <at> yandex.ru>
Subject: Re: Status: 26.0.50; semantic-ia-fast-jump jumps to a random place
 in buffer
Date: Thu, 05 Oct 2017 10:09:58 +0200
> I understand. Then this must mean that the change in behavior in CEDET
> was triggered with this commit:
>
> commit ee297210cffb9e8d05912686a39fa158414ba050
> Author: Mark Oteiza <mvoteiza <at> udel.edu>
> Date:   Thu May 26 21:47:18 2016 -0400

Right.

> I also understand your other arguments. But the question is: While
> your recommendation makes sense, there clearly still is a lot of code
> which uses switch-to-buffer without binding
> switch-to-buffer-preserve-window-point to nil and it wasn't fixed when
> this variable's default was changed. This is true in lisp code shipped
> in emacs and it is probably also true for lots of third party code in
> the wild. Who is going to fix all this code? And if it turns out that
> the fixing all this code is too difficult / impossible, is it
> justified to fix bug #4041 at the cost of causing numerous other bugs
> (which arguably are due to misuse of switch-to-buffer, but they will
> have to be fixed either way)?

This would have the banal consequence that all users who then set
‘switch-to-buffer-preserve-window-point’ to a non-nil value would have
to live with the wrong behavior forever: Nobody would care about fixing
it because "the default" DTRT already.

martin





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Sun, 15 Oct 2017 23:07:02 GMT) Full text and rfc822 format available.

Message #34 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Bastian Beischer <bastian.beischer <at> gmail.com>,
 bug#28645 <28645 <at> debbugs.gnu.org>
Subject: Re: bug#28645: Status: 26.0.50; semantic-ia-fast-jump jumps to a
 random place in buffer
Date: Mon, 16 Oct 2017 02:06:04 +0300
Hey Bastian,

On 10/3/17 12:40 PM, Bastian Beischer wrote:

> $ grep -n -e 'switch-to-buffer' lisp/cedet
> ./semantic/decorate/include.el:470:     (switch-to-buffer (get-file-buffer file)))
> ./semantic/imenu.el:180:                  (switch-to-buffer ob))
> ./semantic/debug.el:156:      (switch-to-buffer (oref iface data-buffer))
> ./semantic/debug.el:160:  (switch-to-buffer (oref iface parser-buffer))
> ./semantic/debug.el:166:  (switch-to-buffer (oref iface source-buffer))
> ./semantic/debug.el:453:      (switch-to-buffer buf))
> ./semantic/debug.el:467:      (switch-to-buffer buf))
> ./semantic/bovine/c.el:980:     (switch-to-buffer (get-buffer-create "*MODE HACK TEST*"))
> ./semantic/bovine/c.el:992:    (switch-to-buffer-other-window
> ./semantic/complete.el:1533:    (switch-to-buffer-other-window buf t)
> ./semantic/complete.el:2123:      (switch-to-buffer (current-buffer))
> ./semantic/symref/list.el:182:    (switch-to-buffer-other-window buff)
> ./semantic/symref/list.el:314:    (switch-to-buffer-other-window buff)
> ./semantic/symref/list.el:328:    (switch-to-buffer-other-window buff)
> ./semantic/symref/list.el:344:    (switch-to-buffer-other-window buff)
> ./semantic/symref/list.el:420:    (switch-to-buffer-other-window (semantic-tag-buffer tag))
> ./semantic/symref/list.el:440:              (switch-to-buffer (current-buffer))
> ./semantic/sb.el:320:    (switch-to-buffer (current-buffer))
> ./semantic/analyze/refs.el:351:    (switch-to-buffer (current-buffer))
> ./semantic/mru-bookmark.el:116:    (switch-to-buffer (current-buffer))
> ./semantic/texi.el:630:;;       (switch-to-buffer docbuff))
> ./semantic/texi.el:675:   (switch-to-buffer (semantic-tag-buffer (car tags)))
> ./semantic/senator.el:533:      (switch-to-buffer (current-buffer))
> ./semantic/senator.el:537:      (switch-to-buffer result)
> ./semantic/senator.el:741:                              (switch-to-buffer (semantic-tag-buffer v))
> ./semantic.el:1081: `global-semantic-mru-bookmark-mode'   - Provide `switch-to-buffer'-like
> ./srecode/getset.el:263:    (switch-to-buffer (current-buffer))
> ./ede/custom.el:103:    (switch-to-buffer (get-buffer-create "*EDE sort targets*"))
> ./ede/shell.el:44:      (switch-to-buffer-other-window buff t))
> 
> I was able to reproduce the bug in "semantic-complete-jump" and
> "semantic-analyze-proto-impl-toggle", for example.

With Martin's explanation, I guess we should replace all of these uses 
with pop-to-buffer-same-window.

Could you try out this kind of change and see if it fixes the problems 
you are still seeing, without introducing any obvious new ones?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Mon, 16 Oct 2017 10:22:01 GMT) Full text and rfc822 format available.

Message #37 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Bastian Beischer <bastian.beischer <at> gmail.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>
Subject: Re: bug#28645: Status: 26.0.50; semantic-ia-fast-jump jumps to a
 random place in buffer
Date: Mon, 16 Oct 2017 12:21:06 +0200
[Message part 1 (text/plain, inline)]
Hey Dmitry,

On Mon, Oct 16, 2017 at 1:06 AM, Dmitry Gutov <dgutov <at> yandex.ru> wrote:

> Hey Bastian,
>
> On 10/3/17 12:40 PM, Bastian Beischer wrote:
>
> $ grep -n -e 'switch-to-buffer' lisp/cedet
>> ./semantic/decorate/include.el:470:     (switch-to-buffer
>> (get-file-buffer file)))
>> ./semantic/imenu.el:180:                  (switch-to-buffer ob))
>> ./semantic/debug.el:156:      (switch-to-buffer (oref iface data-buffer))
>> ./semantic/debug.el:160:  (switch-to-buffer (oref iface parser-buffer))
>> ./semantic/debug.el:166:  (switch-to-buffer (oref iface source-buffer))
>> ./semantic/debug.el:453:      (switch-to-buffer buf))
>> ./semantic/debug.el:467:      (switch-to-buffer buf))
>> ./semantic/bovine/c.el:980:     (switch-to-buffer (get-buffer-create
>> "*MODE HACK TEST*"))
>> ./semantic/bovine/c.el:992:    (switch-to-buffer-other-window
>> ./semantic/complete.el:1533:    (switch-to-buffer-other-window buf t)
>> ./semantic/complete.el:2123:      (switch-to-buffer (current-buffer))
>> ./semantic/symref/list.el:182:    (switch-to-buffer-other-window buff)
>> ./semantic/symref/list.el:314:    (switch-to-buffer-other-window buff)
>> ./semantic/symref/list.el:328:    (switch-to-buffer-other-window buff)
>> ./semantic/symref/list.el:344:    (switch-to-buffer-other-window buff)
>> ./semantic/symref/list.el:420:    (switch-to-buffer-other-window
>> (semantic-tag-buffer tag))
>> ./semantic/symref/list.el:440:              (switch-to-buffer
>> (current-buffer))
>> ./semantic/sb.el:320:    (switch-to-buffer (current-buffer))
>> ./semantic/analyze/refs.el:351:    (switch-to-buffer (current-buffer))
>> ./semantic/mru-bookmark.el:116:    (switch-to-buffer (current-buffer))
>> ./semantic/texi.el:630:;;       (switch-to-buffer docbuff))
>> ./semantic/texi.el:675:   (switch-to-buffer (semantic-tag-buffer (car
>> tags)))
>> ./semantic/senator.el:533:      (switch-to-buffer (current-buffer))
>> ./semantic/senator.el:537:      (switch-to-buffer result)
>> ./semantic/senator.el:741:                              (switch-to-buffer
>> (semantic-tag-buffer v))
>> ./semantic.el:1081: `global-semantic-mru-bookmark-mode'   - Provide
>> `switch-to-buffer'-like
>> ./srecode/getset.el:263:    (switch-to-buffer (current-buffer))
>> ./ede/custom.el:103:    (switch-to-buffer (get-buffer-create "*EDE sort
>> targets*"))
>> ./ede/shell.el:44:      (switch-to-buffer-other-window buff t))
>>
>> I was able to reproduce the bug in "semantic-complete-jump" and
>> "semantic-analyze-proto-impl-toggle", for example.
>>
>
> With Martin's explanation, I guess we should replace all of these uses
> with pop-to-buffer-same-window.
>
> Could you try out this kind of change and see if it fixes the problems you
> are still seeing, without introducing any obvious new ones?
>

​I replaced ​switch-to-buffer with pop-to-buffer-same-window in those
functions which I'm using regularly and it fixes the problem. The CEDET
functions where I made the replacements and checked them are:

semantic-analyze-proto-impl-toggle
semantic-complete-jump
semantic-decoration-include-visit
semantic-ia--fast-jump-helper
semantic-mrub-vist
senator-jump
senator-jump-regexp
​senator-go-to-up-reference

​I didn't make any other replacements because:

a) For some of them I'm not sure if 'pop-to-buffer-same-window' or
'pop-to-buffer' ​should be used.
b) I'm not using any of the other functions with matches so I wouldn't be
able to test the change.

Also, searching for 'switch-to-buffer' in non-CEDET related lisp files in
the emacs sources reveals more places which need to be fixed, but I didn't
go that far. However, probably somebody (tm) should check them all
one-by-one :-(

I also think that the advice not to use switch-to-buffer and instead use
pop-to-buffer(-same-window) should get a prominent entry in NEWS so that
third-parties can check their code and make the changes there, too. For
example, SLIME has this open issue:

https://github.com/slime/slime/issues/391
https://lists.gnu.org/archive/html/emacs-devel/2017-06/msg00227.html

and others are probably also affected.

Cheers
Bastian
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Tue, 17 Oct 2017 08:59:02 GMT) Full text and rfc822 format available.

Message #40 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Bastian Beischer <bastian.beischer <at> gmail.com>, 
 Dmitry Gutov <dgutov <at> yandex.ru>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>
Subject: Re: bug#28645: Status: 26.0.50; semantic-ia-fast-jump jumps to a
 random place in buffer
Date: Tue, 17 Oct 2017 10:58:35 +0200
> I also think that the advice not to use switch-to-buffer and instead use
> pop-to-buffer(-same-window) should get a prominent entry in NEWS so that
> third-parties can check their code and make the changes there, too.

I added a sentence to that sense.  If more is needed please tell me.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Tue, 17 Oct 2017 10:45:01 GMT) Full text and rfc822 format available.

Message #43 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Bastian Beischer <bastian.beischer <at> gmail.com>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>
Subject: Re: bug#28645: Status: 26.0.50; semantic-ia-fast-jump jumps to a
 random place in buffer
Date: Tue, 17 Oct 2017 13:44:30 +0300
On 10/16/17 1:21 PM, Bastian Beischer wrote:

> ​I replaced ​switch-to-buffer with pop-to-buffer-same-window in those 
> functions which I'm using regularly and it fixes the problem. The CEDET 
> functions where I made the replacements and checked them are:
> 
> semantic-analyze-proto-impl-toggle
> semantic-complete-jump
> semantic-decoration-include-visit
> semantic-ia--fast-jump-helper
> semantic-mrub-vist
> senator-jump
> senator-jump-regexp
> ​senator-go-to-up-reference
> 
> ​I didn't make any other replacements because:
> 
> a) For some of them I'm not sure if 'pop-to-buffer-same-window' or 
> 'pop-to-buffer' ​should be used.
> b) I'm not using any of the other functions with matches so I wouldn't 
> be able to test the change.
> 
> Also, searching for 'switch-to-buffer' in non-CEDET related lisp files 
> in the emacs sources reveals more places which need to be fixed, but I 
> didn't go that far. However, probably somebody (tm) should check them 
> all one-by-one :-(

Could you send a patch with the replacements you did make?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Tue, 17 Oct 2017 12:31:02 GMT) Full text and rfc822 format available.

Message #46 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Bastian Beischer <bastian.beischer <at> gmail.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>
Subject: Re: bug#28645: Status: 26.0.50;
 semantic-ia-fast-jump jumps to a random place in buffer
Date: Tue, 17 Oct 2017 14:30:35 +0200
Dmitry Gutov <dgutov <at> yandex.ru> writes:

> On 10/16/17 1:21 PM, Bastian Beischer wrote:
>
>> ​I replaced ​switch-to-buffer with pop-to-buffer-same-window in those functions
>> which I'm using regularly and it fixes the problem. The CEDET functions where
>> I made the replacements and checked them are:
>>
>> semantic-analyze-proto-impl-toggle
>> semantic-complete-jump
>> semantic-decoration-include-visit
>> semantic-ia--fast-jump-helper
>> semantic-mrub-vist
>> senator-jump
>> senator-jump-regexp
>> ​senator-go-to-up-reference
>>

It turns out that senator-jump and senator-jump-regexp don't exist in
emacs but only in upstream CEDET. So no need to change these.

>> ​I didn't make any other replacements because:
>>
>> a) For some of them I'm not sure if 'pop-to-buffer-same-window' or
>> 'pop-to-buffer' ​should be used.
>> b) I'm not using any of the other functions with matches so I wouldn't be able
>> to test the change.
>>
>> Also, searching for 'switch-to-buffer' in non-CEDET related lisp files in the
>> emacs sources reveals more places which need to be fixed, but I didn't go that
>> far. However, probably somebody (tm) should check them all one-by-one :-(
>
> Could you send a patch with the replacements you did make?

Sure:

diff --git a/lisp/cedet/semantic/analyze/refs.el b/lisp/cedet/semantic/analyze/refs.el
index 55fcd83043..a58479f505 100644
--- a/lisp/cedet/semantic/analyze/refs.el
+++ b/lisp/cedet/semantic/analyze/refs.el
@@ -348,7 +348,7 @@ Only works for tags in the global namespace."
 
     (push-mark)
     (semantic-go-to-tag target)
-    (switch-to-buffer (current-buffer))
+    (pop-to-buffer-same-windown (current-buffer))
     (semantic-momentary-highlight-tag target))
   )
 
diff --git a/lisp/cedet/semantic/complete.el b/lisp/cedet/semantic/complete.el
index ff8e61e54d..325ca1f441 100644
--- a/lisp/cedet/semantic/complete.el
+++ b/lisp/cedet/semantic/complete.el
@@ -2120,7 +2120,7 @@ completion works."
     (when (semantic-tag-p tag)
       (push-mark)
       (semantic-go-to-tag tag)
-      (switch-to-buffer (current-buffer))
+      (pop-to-buffer-same-window (current-buffer))
       (semantic-momentary-highlight-tag tag)
       (message "%S: %s "
               (semantic-tag-class tag)
diff --git a/lisp/cedet/semantic/decorate/include.el b/lisp/cedet/semantic/decorate/include.el
index 6876e5f3a4..4a86b9e4ee 100644
--- a/lisp/cedet/semantic/decorate/include.el
+++ b/lisp/cedet/semantic/decorate/include.el
@@ -467,7 +467,7 @@ its contents.
        (error "Could not location include %s"
               (semantic-tag-name tag)))
        ((get-file-buffer file)
-       (switch-to-buffer (get-file-buffer file)))
+       (pop-to-buffer-same-window (get-file-buffer file)))
        ((stringp file)
        (find-file file))
        ))))
diff --git a/lisp/cedet/semantic/mru-bookmark.el b/lisp/cedet/semantic/mru-bookmark.el
index 5fa58e08ea..24863de01b 100644
--- a/lisp/cedet/semantic/mru-bookmark.el
+++ b/lisp/cedet/semantic/mru-bookmark.el
@@ -113,7 +113,7 @@ Uses `semantic-go-to-tag' and highlighting."
          (forward-char o))
       (error nil))
     ;; make it visible
-    (switch-to-buffer (current-buffer))
+    (pop-to-buffer-same-window (current-buffer))
     (semantic-momentary-highlight-tag tag)
     ))
 
diff --git a/lisp/cedet/semantic/senator.el b/lisp/cedet/semantic/senator.el
index e86658628b..d37345aa2d 100644
--- a/lisp/cedet/semantic/senator.el
+++ b/lisp/cedet/semantic/senator.el
@@ -530,11 +530,11 @@ Some tags such as includes have other reference features."
        ;; A tag
        ((semantic-tag-p result)
        (semantic-go-to-tag result)
-       (switch-to-buffer (current-buffer))
+       (pop-to-buffer-same-window (current-buffer))
        (semantic-momentary-highlight-tag result))
        ;; Buffers
        ((bufferp result)
-       (switch-to-buffer result)
+       (pop-to-buffer-same-window result)
        (pulse-momentary-highlight-one-line (point)))
        ;; Files
        ((and (stringp result) (file-exists-p result))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Wed, 18 Oct 2017 23:47:03 GMT) Full text and rfc822 format available.

Message #49 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Bastian Beischer <bastian.beischer <at> gmail.com>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>
Subject: Re: bug#28645: Status: 26.0.50; semantic-ia-fast-jump jumps to a
 random place in buffer
Date: Thu, 19 Oct 2017 02:46:20 +0300
On 10/17/17 3:30 PM, Bastian Beischer wrote:
>> Could you send a patch with the replacements you did make?
> 
> Sure:

Thanks! I've pushed it to emacs-26 now.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Thu, 19 Oct 2017 09:42:02 GMT) Full text and rfc822 format available.

Message #52 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Bastian Beischer <bastian.beischer <at> gmail.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>
Subject: Re: bug#28645: Status: 26.0.50; semantic-ia-fast-jump jumps to a
 random place in buffer
Date: Thu, 19 Oct 2017 11:41:18 +0200
[Message part 1 (text/plain, inline)]
On Thu, Oct 19, 2017 at 1:46 AM, Dmitry Gutov <dgutov <at> yandex.ru> wrote:
> On 10/17/17 3:30 PM, Bastian Beischer wrote:
>>>
>>> Could you send a patch with the replacements you did make?
>>
>>
>> Sure:
>
>
> Thanks! I've pushed it to emacs-26 now.

Hello Dmitry,

thanks a lot. Would you mind installing the attached whitespace fixes
as well as a follow up?

Cheers
Bastian
[whitespace.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28645; Package emacs. (Thu, 19 Oct 2017 10:04:01 GMT) Full text and rfc822 format available.

Message #55 received at 28645 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Bastian Beischer <bastian.beischer <at> gmail.com>
Cc: bug#28645 <28645 <at> debbugs.gnu.org>
Subject: Re: bug#28645: Status: 26.0.50; semantic-ia-fast-jump jumps to a
 random place in buffer
Date: Thu, 19 Oct 2017 13:03:35 +0300
On 10/19/17 12:41 PM, Bastian Beischer wrote:

> thanks a lot. Would you mind installing the attached whitespace fixes
> as well as a follow up?

Also done, thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 16 Nov 2017 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 301 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.