From: joaotavora@gmail.com (João Távora)
To: 28814@debbugs.gnu.org
Cc: dgutov@yandex.ru
Subject: bug#28814: [BUMP, PATCH] (26.0.90; When *xref* window is needed, original window-switching intent is lost )
Date: Fri, 20 Oct 2017 10:13:43 +0100 [thread overview]
Message-ID: <871slyi3lk.fsf_-_@gmail.com> (raw)
In-Reply-To: <handler.28814.B.150791088020837.ack@debbugs.gnu.org> (GNU bug Tracking System's message of "Fri, 13 Oct 2017 16:08:02 +0000")
[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]
Ping,
Hoping someone can take a look at this bug I reported a week ago. Here
are two very simple Emacs -Q recipes that demonstrate it.
emacs -Q
C-x 3 [split-window-right]
C-x 2 [split-window-below]
M-. xref-backend-definitions RET [xref-find-definitions]
C-n [next-line]
RET [xref-goto-xref]
Expected the definition to be found in the original window where I
pressed M-. but instead it was found in another. Another case:
emacs -Q
C-x 4 . xref-backend-definitions RET [xref-find-definitions-other-window]
C-n
RET
Expected the definition to be found in some other window, different from
the one I pressed M-. on. Instead went to the same one. Also, in both
situations, expected the window configuration to be the same as if I had
searched for, say xref-backend-functions.
This is fixed by the patches that I reattach after minor tweaks. The
general idea is to have the *xref*, whose sudden appearance is hard to
predict, obtrude as little as possible on the user's window
configuration.
João
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Honor-window-switching-intents-in-xref-find-definiti.patch --]
[-- Type: text/x-diff, Size: 5639 bytes --]
From 1b760816ac8886313996c635ee1cf696b937c20e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= <joaotavora@gmail.com>
Date: Fri, 13 Oct 2017 15:13:14 +0100
Subject: [PATCH 1/2] Honor window-switching intents in xref-find-definitions
When there is more than one xref to jump to, and an *xref* window
appears to help the user choose, the original intent to open a
definition another window or frame is remembered when the choice to go
to or show a reference is finally made.
* lisp/progmodes/xref.el (xref--show-pos-in-buf): Rewrite.
(xref--original-window-intent): New variable.
(xref--original-window): Rename from xref--window and move up
here for clarity.
(xref--show-pos-in-buf): Rewrite. Don't take SELECT arg here.
(xref--show-location): Handle window selection decision here.
(xref--window): Rename to xref--original-window.
(xref-show-location-at-point): Don't attempt window management here.
(xref--show-xrefs): Ensure display-action intent is saved.
---
lisp/progmodes/xref.el | 69 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 48 insertions(+), 21 deletions(-)
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 80cdcb3f18..c3e7982205 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -449,43 +449,68 @@ xref--with-dedicated-window
(when xref-w
(set-window-dedicated-p xref-w xref-w-dedicated)))))
-(defun xref--show-pos-in-buf (pos buf select)
- (let ((xref-buf (current-buffer))
- win)
+(defvar-local xref--original-window-intent nil
+ "Original window-switching intent before xref buffer creation.")
+
+(defvar-local xref--original-window nil
+ "The original window this xref buffer was created from.")
+
+(defun xref--show-pos-in-buf (pos buf)
+ "Goto and display position POS of buffer BUF in a window.
+Honour `xref--original-window-intent', run `xref-after-jump-hook'
+and finally return the window."
+ (let* ((xref-buf (current-buffer))
+ (pop-up-frames
+ (or (eq xref--original-window-intent 'frame)
+ pop-up-frames))
+ (action
+ (cond ((memq
+ xref--original-window-intent
+ '(window frame))
+ t)
+ ((and
+ (window-live-p xref--original-window)
+ (or (not (window-dedicated-p xref--original-window))
+ (eq (window-buffer xref--original-window) buf)))
+ `(,(lambda (buf _alist)
+ (set-window-buffer xref--original-window buf)
+ xref--original-window))))))
(with-selected-window
- (xref--with-dedicated-window
- (display-buffer buf))
+ (with-selected-window
+ ;; Just before `display-buffer', place ourselves in the
+ ;; original window to suggest preserving it. Of course, if
+ ;; user has deleted the original window, all bets are off,
+ ;; just use the selected one.
+ (or (and (window-live-p xref--original-window)
+ xref--original-window)
+ (selected-window))
+ (display-buffer buf action))
(xref--goto-char pos)
(run-hooks 'xref-after-jump-hook)
(let ((buf (current-buffer)))
- (setq win (selected-window))
(with-current-buffer xref-buf
- (setq-local other-window-scroll-buffer buf))))
- (when select
- (select-window win))))
+ (setq-local other-window-scroll-buffer buf)))
+ (selected-window))))
(defun xref--show-location (location &optional select)
(condition-case err
(let* ((marker (xref-location-marker location))
(buf (marker-buffer marker)))
- (xref--show-pos-in-buf marker buf select))
+ (cond (select
+ (select-window (xref--show-pos-in-buf marker buf)))
+ (t
+ (save-selected-window
+ (xref--with-dedicated-window
+ (xref--show-pos-in-buf marker buf))))))
(user-error (message (error-message-string err)))))
-(defvar-local xref--window nil
- "The original window this xref buffer was created from.")
-
(defun xref-show-location-at-point ()
"Display the source of xref at point in the appropriate window, if any."
(interactive)
(let* ((xref (xref--item-at-point))
(xref--current-item xref))
(when xref
- ;; Try to avoid the window the current xref buffer was
- ;; originally created from.
- (if (window-live-p xref--window)
- (with-selected-window xref--window
- (xref--show-location (xref-item-location xref)))
- (xref--show-location (xref-item-location xref))))))
+ (xref--show-location (xref-item-location xref)))))
(defun xref-next-line ()
"Move to the next xref and display its source in the appropriate window."
@@ -727,7 +752,8 @@ xref--show-xref-buffer
(xref--xref-buffer-mode)
(pop-to-buffer (current-buffer))
(goto-char (point-min))
- (setq xref--window (assoc-default 'window alist))
+ (setq xref--original-window (assoc-default 'window alist)
+ xref--original-window-intent (assoc-default 'display-action alist))
(current-buffer)))))
\f
@@ -754,7 +780,8 @@ xref--show-xrefs
(t
(xref-push-marker-stack)
(funcall xref-show-xrefs-function xrefs
- `((window . ,(selected-window)))))))
+ `((window . ,(selected-window))
+ (display-action . ,display-action))))))
(defun xref--prompt-p (command)
(or (eq xref-prompt-for-identifier t)
--
2.14.2
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Quit-the-xref-window-if-user-decides-to-go-to-a-ref.patch --]
[-- Type: text/x-diff, Size: 1392 bytes --]
From 9feaf473479dcd8edcf2c0bb14044995abb5eeb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= <joaotavora@gmail.com>
Date: Fri, 13 Oct 2017 16:37:47 +0100
Subject: [PATCH 2/2] Quit the *xref* window if user decides to go to a ref
The idea is to have this window, whose sudden appearance is hard to
predict, obtrude as little as possible on the user's window
configuration.
* lisp/progmodes/xref.el (xref--show-location): When SELECT is
t, quit window.
---
lisp/progmodes/xref.el | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index c3e7982205..cf9e027ba0 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -495,9 +495,12 @@ xref--show-pos-in-buf
(defun xref--show-location (location &optional select)
(condition-case err
(let* ((marker (xref-location-marker location))
- (buf (marker-buffer marker)))
+ (buf (marker-buffer marker))
+ (xref-buffer (current-buffer)))
(cond (select
- (select-window (xref--show-pos-in-buf marker buf)))
+ (quit-window nil nil)
+ (with-current-buffer xref-buffer
+ (select-window (xref--show-pos-in-buf marker buf))))
(t
(save-selected-window
(xref--with-dedicated-window
--
2.14.2
[-- Attachment #4: Type: text/plain, Size: 681 bytes --]
help-debbugs@gnu.org (GNU bug Tracking System) writes:
> Thank you for filing a new bug report with debbugs.gnu.org.
>
> This is an automatically generated reply to let you know your message
> has been received.
>
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
>
> Your message has been sent to the package maintainer(s):
> bug-gnu-emacs@gnu.org
>
> If you wish to submit further information on this problem, please
> send it to 28814@debbugs.gnu.org.
>
> Please do not send mail to help-debbugs@gnu.org unless you wish
> to report a problem with the Bug-tracking system.
next prev parent reply other threads:[~2017-10-20 9:13 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-13 16:07 bug#28814: 26.0.90; When *xref* window is needed, original window-switching intent is lost João Távora
[not found] ` <handler.28814.B.150791088020837.ack@debbugs.gnu.org>
2017-10-16 17:58 ` bug#28814: Acknowledgement (26.0.90; When *xref* window is needed, original window-switching intent is lost ) João Távora
2017-10-20 9:13 ` João Távora [this message]
2017-10-20 10:39 ` bug#28814: [BUMP, PATCH] " Dmitry Gutov
2017-10-23 2:06 ` Dmitry Gutov
2017-10-23 8:23 ` João Távora
2017-10-23 20:03 ` João Távora
2017-10-25 0:24 ` Dmitry Gutov
2017-10-25 7:43 ` João Távora
2017-10-25 10:24 ` Dmitry Gutov
2017-10-25 13:29 ` João Távora
2017-10-25 14:49 ` Dmitry Gutov
2017-10-25 15:35 ` João Távora
2017-10-25 15:46 ` Dmitry Gutov
2017-10-25 15:11 ` Eli Zaretskii
2017-10-25 15:27 ` João Távora
2017-10-25 15:39 ` Eli Zaretskii
2017-10-25 20:56 ` João Távora
2017-10-26 7:56 ` martin rudalics
2017-10-26 16:42 ` Eli Zaretskii
2017-10-26 22:40 ` Dmitry Gutov
2017-10-27 0:05 ` João Távora
2017-11-02 17:06 ` Dmitry Gutov
2017-10-26 23:59 ` João Távora
2017-10-28 9:41 ` Eli Zaretskii
2017-10-28 19:19 ` João Távora
2017-11-02 17:03 ` João Távora
2017-11-02 17:07 ` Eli Zaretskii
2017-11-02 19:07 ` João Távora
2017-11-02 19:32 ` Eli Zaretskii
2017-11-03 13:47 ` Eli Zaretskii
2017-11-03 16:18 ` João Távora
2017-11-03 19:06 ` Eli Zaretskii
2017-10-26 12:39 ` Dmitry Gutov
2017-10-25 7:46 ` martin rudalics
2017-10-25 13:19 ` João Távora
2017-10-26 7:56 ` martin rudalics
2017-10-25 0:07 ` Dmitry Gutov
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871slyi3lk.fsf_-_@gmail.com \
--to=joaotavora@gmail.com \
--cc=28814@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.