From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Newsgroups: gmane.emacs.bugs 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 Message-ID: <871slyi3lk.fsf_-_@gmail.com> References: <87infjm3p3.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1508490873 25152 195.159.176.226 (20 Oct 2017 09:14:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 20 Oct 2017 09:14:33 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cc: dgutov@yandex.ru To: 28814@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 20 11:14:29 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5TNa-0003pR-DN for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Oct 2017 11:14:10 +0200 Original-Received: from localhost ([::1]:52749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5TNh-0003PL-Pr for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Oct 2017 05:14:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5TNY-0003P8-Mr for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2017 05:14:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5TNS-0008Sl-FW for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2017 05:14:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42417) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5TNS-0008SU-9T for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2017 05:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e5TNR-0003ok-Qk for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2017 05:14:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Oct 2017 09:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28814 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: help-debbugs@gnu.org (GNU bug Tracking System) X-Debbugs-Original-Cc: 28814@debbugs.gnu.org, dgutov@yandex.ru Original-Received: via spool by 28814-submit@debbugs.gnu.org id=B28814.150849083414652 (code B ref 28814); Fri, 20 Oct 2017 09:14:01 +0000 Original-Received: (at 28814) by debbugs.gnu.org; 20 Oct 2017 09:13:54 +0000 Original-Received: from localhost ([127.0.0.1]:51098 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5TNK-0003oG-7J for submit@debbugs.gnu.org; Fri, 20 Oct 2017 05:13:54 -0400 Original-Received: from mail-wm0-f45.google.com ([74.125.82.45]:44449) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5TNI-0003o1-6g for 28814@debbugs.gnu.org; Fri, 20 Oct 2017 05:13:52 -0400 Original-Received: by mail-wm0-f45.google.com with SMTP id 196so18763598wma.1 for <28814@debbugs.gnu.org>; Fri, 20 Oct 2017 02:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=65zxZVmQ6COLMU6aSDHy4n7oOabF8r+9DmwdC5YWNgg=; b=nzelxcujYEPxNzGdVI9ZMGo6tIzCpFgwflhBE4hVCGbK3dijL8/bKE7nYxAnWO9lvQ FNjav6iZj3qv2yHiPHp0nwq3htfQl7SwTMVucgxrv1kD02j6c+LOBR5RyfKKkkxxJrea 76Yyrc8nn71MvaWtV89Hb1Cs0gl1gaKRpuAG4TqlW141kspimZ4cS+T9zXScId0mBJIv 8JjjPiQ8GYmx866nPQHgTu0E66gWQU3gjRHVIDggS+5jKS2zLQ8ZelURDN8BOShf0cVo Blw9RYD3SLO6llbqGqOKbiZByVP7b87O03e7QZdvmHpmR1Q9n0yJ7MDzSotNoa7qByK/ UB6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=65zxZVmQ6COLMU6aSDHy4n7oOabF8r+9DmwdC5YWNgg=; b=H2Y/VqDlvO7r98i2R6YEZnavNLPW6i4bLQncz58eMZlKQGqf6lMQ26ojcvaSwNvDH6 UJJZDQu5YbSyRBKlkA1+wJIL5EWcNFDmEy1HuAkcVgLqLSh1GK5FqU9bwpD1xexN+IFC Msd6iCNG2sNNSAJutqSeFCvwKSUDpkwXDCdvz+/M9jg/xGRUVIyqwWR7+pEOqN9Z7EpG qXYQgVIM9eSsvQBQcWIq6YA5HRUCa0TP2ghXuodIzYvj/Lm4PT3bWBlmsN81lSwsPhmn xdSis0k8mKExTUQ0ItTSxVC+N6MWK/FNvD/wQ4yu2sCG7IuMXtm8/gsq3RAO0UyABVGF sa8w== X-Gm-Message-State: AMCzsaXLutJcc1FW26oqdKV4L7v3ObSGS7YYV1UwnoLA2E8NPNJ9/xQ1 wGyKal7Kf19OIsZPnvhbuT0= X-Google-Smtp-Source: ABhQp+TtuoxVo2O0Txp/2FhvdswZtUsyemsrGHgBFKKPrIMIzOPr7qp5C9HHo2hwKqndRYLCYbT2qA== X-Received: by 10.28.16.209 with SMTP id 200mr1068247wmq.35.1508490826600; Fri, 20 Oct 2017 02:13:46 -0700 (PDT) Original-Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id 67sm1211202wmw.22.2017.10.20.02.13.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 02:13:45 -0700 (PDT) In-Reply-To: (GNU bug Tracking System's message of "Fri, 13 Oct 2017 16:08:02 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:138753 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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=C3=A3o --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Honor-window-switching-intents-in-xref-find-definiti.patch >From 1b760816ac8886313996c635ee1cf696b937c20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= 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))))) @@ -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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Quit-the-xref-window-if-user-decides-to-go-to-a-ref.patch >From 9feaf473479dcd8edcf2c0bb14044995abb5eeb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= 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 --=-=-= Content-Type: text/plain 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. --=-=-=--