emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/xref 60eb217: Use `quit-window' to restore configu


From: Dmitry Gutov
Subject: [Emacs-diffs] scratch/xref 60eb217: Use `quit-window' to restore configuration before xref
Date: Tue, 06 Jan 2015 10:22:22 +0000

branch: scratch/xref
commit 60eb2175cc6a5e3db9f3633fc7e14c412eec50bd
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Use `quit-window' to restore configuration before xref
    
    * lisp/progmodes/xref.el (xref--display-history): New variable.
    (xref--window-configuration): Remove.
    (xref--history-pushnew): New function.
    (xref--display-position): Use `xref--history-pushnew'.  Add new
    argument.
    (xref--restore-window-configuration): Remove.
    (xref--show-location, xref-show-location-at-point): Update
    accordingly.
    (xref--xref-buffer-mode): Don't use `pre-command-hook'.
    (xref--quit): New command.
    (xref--xref-buffer-mode-map): Bind `q' to it.
---
 lisp/ChangeLog         |   14 ++++++++++++++
 lisp/progmodes/xref.el |   44 +++++++++++++++++++++++++++++---------------
 2 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 76ba2cd..5311b50 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
+2015-01-06  Dmitry Gutov  <address@hidden>
+
+       * progmodes/xref.el (xref--display-history): New variable.
+       (xref--window-configuration): Remove.
+       (xref--history-pushnew): New function.
+       (xref--display-position): Use `xref--history-pushnew'.  Add new
+       argument.
+       (xref--restore-window-configuration): Remove.
+       (xref--show-location, xref-show-location-at-point): Update
+       accordingly.
+       (xref--xref-buffer-mode): Don't use `pre-command-hook'.
+       (xref--quit): New command.
+       (xref--xref-buffer-mode-map): Bind `q' to it.
+
 2015-01-05  Dmitry Gutov  <address@hidden>
 
        * progmodes/xref.el (xref--insert-xrefs): Add `help-echo' property
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index b822619..d48349f 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -332,19 +332,30 @@ WINDOW controls how the buffer is displayed:
 
 ;; The xref buffer is used to display a set of xrefs.
 
-(defvar-local xref--window-configuration nil)
+(defvar-local xref--display-history nil)
 
-(defun xref--display-position (pos other-window recenter-arg)
-  ;; show the location, but don't hijack focus.
+(defun xref--history-pushnew (value)
+  (unless (equal value (car xref--display-history))
+    (push value xref--display-history)))
+
+(defun xref--display-position (pos other-window recenter-arg xref-buf)
+  ;; Show the location, but don't hijack focus.
   (with-selected-window (display-buffer (current-buffer) other-window)
     (goto-char pos)
-    (recenter recenter-arg)))
+    (recenter recenter-arg)
+    (let ((val (cons (current-buffer) (selected-window)))
+          (rest (window-parameter nil 'quit-restore)))
+      ;; Save the new entry if the window displayed another buffer
+      ;; previously.
+      (when (and rest (not (eq (car rest) 'same)))
+        (with-current-buffer xref-buf
+          (xref--history-pushnew val))))))
 
 (defun xref--show-location (location)
   (condition-case err
-      (progn
+      (let ((xref-buf (current-buffer)))
         (xref--goto-location location)
-        (xref--display-position (point) t 1))
+        (xref--display-position (point) t 1 xref-buf))
     (user-error (message (error-message-string err)))))
 
 (defun xref-show-location-at-point ()
@@ -352,14 +363,8 @@ WINDOW controls how the buffer is displayed:
   (interactive)
   (let ((loc (xref--location-at-point)))
     (when loc
-      (setq xref--window-configuration (current-window-configuration))
       (xref--show-location loc))))
 
-(defun xref--restore-window-configuration ()
-  (when xref--window-configuration
-    (set-window-configuration xref--window-configuration)
-    (setq xref--window-configuration nil)))
-
 (defun xref-next-line ()
   "Move to the next xref and display its source in the other window."
   (interactive)
@@ -388,11 +393,10 @@ WINDOW controls how the buffer is displayed:
 
 (define-derived-mode xref--xref-buffer-mode fundamental-mode "XREF"
   "Mode for displaying cross-references."
-  (setq buffer-read-only t)
-  (add-hook 'pre-command-hook #'xref--restore-window-configuration nil t))
+  (setq buffer-read-only t))
 
 (let ((map xref--xref-buffer-mode-map))
-  (define-key map (kbd "q") #'quit-window)
+  (define-key map (kbd "q") #'xref--quit)
   (define-key map (kbd "n") #'xref-next-line)
   (define-key map (kbd "p") #'xref-prev-line)
   (define-key map (kbd "RET") #'xref-goto-xref)
@@ -402,6 +406,16 @@ WINDOW controls how the buffer is displayed:
   (define-key map (kbd ".") #'xref-next-line)
   (define-key map (kbd ",") #'xref-prev-line))
 
+(defun xref--quit ()
+  "Quit all windows from `xref--display-history', then quit current window."
+  (interactive)
+  (let ((window (selected-window)))
+    (pcase-dolist (`(,buf . ,win) xref--display-history)
+      (when (and (window-live-p win)
+                 (eq buf (window-buffer win)))
+        (quit-window nil win)))
+    (quit-window nil window)))
+
 (defconst xref-buffer-name "*xref*"
   "The name of the buffer to show xrefs.")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]