diff options
| author | Dmitry Gutov | 2015-01-06 13:21:59 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2015-01-06 13:28:37 +0300 |
| commit | 835f0c2c26909c4799f715817693a292bd08df21 (patch) | |
| tree | c333a14a039926d34179556e2662f8762211156e | |
| parent | f5afaf9ce74dd04e37d72e62ecd85fc19c06bb55 (diff) | |
| download | emacs-scratch/xref.tar.gz emacs-scratch/xref.zip | |
Use `quit-window' to restore configuration before xrefscratch/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.
| -rw-r--r-- | lisp/ChangeLog | 14 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 46 |
2 files changed, 45 insertions, 15 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 76ba2cd4c80..5311b50793c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | 2015-01-06 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * progmodes/xref.el (xref--display-history): New variable. | ||
| 4 | (xref--window-configuration): Remove. | ||
| 5 | (xref--history-pushnew): New function. | ||
| 6 | (xref--display-position): Use `xref--history-pushnew'. Add new | ||
| 7 | argument. | ||
| 8 | (xref--restore-window-configuration): Remove. | ||
| 9 | (xref--show-location, xref-show-location-at-point): Update | ||
| 10 | accordingly. | ||
| 11 | (xref--xref-buffer-mode): Don't use `pre-command-hook'. | ||
| 12 | (xref--quit): New command. | ||
| 13 | (xref--xref-buffer-mode-map): Bind `q' to it. | ||
| 14 | |||
| 1 | 2015-01-05 Dmitry Gutov <dgutov@yandex.ru> | 15 | 2015-01-05 Dmitry Gutov <dgutov@yandex.ru> |
| 2 | 16 | ||
| 3 | * progmodes/xref.el (xref--insert-xrefs): Add `help-echo' property | 17 | * progmodes/xref.el (xref--insert-xrefs): Add `help-echo' property |
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index b822619f783..b79b12f685f 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -332,19 +332,30 @@ WINDOW controls how the buffer is displayed: | |||
| 332 | 332 | ||
| 333 | ;; The xref buffer is used to display a set of xrefs. | 333 | ;; The xref buffer is used to display a set of xrefs. |
| 334 | 334 | ||
| 335 | (defvar-local xref--window-configuration nil) | 335 | (defvar-local xref--display-history nil) |
| 336 | 336 | ||
| 337 | (defun xref--display-position (pos other-window recenter-arg) | 337 | (defun xref--history-pushnew (value) |
| 338 | ;; show the location, but don't hijack focus. | 338 | (unless (equal value (car xref--display-history)) |
| 339 | (push value xref--display-history))) | ||
| 340 | |||
| 341 | (defun xref--display-position (pos other-window recenter-arg xref-buf) | ||
| 342 | ;; Show the location, but don't hijack focus. | ||
| 339 | (with-selected-window (display-buffer (current-buffer) other-window) | 343 | (with-selected-window (display-buffer (current-buffer) other-window) |
| 340 | (goto-char pos) | 344 | (goto-char pos) |
| 341 | (recenter recenter-arg))) | 345 | (recenter recenter-arg) |
| 346 | (let ((val (cons (current-buffer) (selected-window))) | ||
| 347 | (rest (window-parameter nil 'quit-restore))) | ||
| 348 | ;; Save the new entry if the window displayed another buffer | ||
| 349 | ;; previously. | ||
| 350 | (when (and rest (not (eq (car rest) 'same))) | ||
| 351 | (with-current-buffer xref-buf | ||
| 352 | (xref--history-pushnew val)))))) | ||
| 342 | 353 | ||
| 343 | (defun xref--show-location (location) | 354 | (defun xref--show-location (location) |
| 344 | (condition-case err | 355 | (condition-case err |
| 345 | (progn | 356 | (let ((xref-buf (current-buffer))) |
| 346 | (xref--goto-location location) | 357 | (xref--goto-location location) |
| 347 | (xref--display-position (point) t 1)) | 358 | (xref--display-position (point) t 1 xref-buf)) |
| 348 | (user-error (message (error-message-string err))))) | 359 | (user-error (message (error-message-string err))))) |
| 349 | 360 | ||
| 350 | (defun xref-show-location-at-point () | 361 | (defun xref-show-location-at-point () |
| @@ -352,14 +363,8 @@ WINDOW controls how the buffer is displayed: | |||
| 352 | (interactive) | 363 | (interactive) |
| 353 | (let ((loc (xref--location-at-point))) | 364 | (let ((loc (xref--location-at-point))) |
| 354 | (when loc | 365 | (when loc |
| 355 | (setq xref--window-configuration (current-window-configuration)) | ||
| 356 | (xref--show-location loc)))) | 366 | (xref--show-location loc)))) |
| 357 | 367 | ||
| 358 | (defun xref--restore-window-configuration () | ||
| 359 | (when xref--window-configuration | ||
| 360 | (set-window-configuration xref--window-configuration) | ||
| 361 | (setq xref--window-configuration nil))) | ||
| 362 | |||
| 363 | (defun xref-next-line () | 368 | (defun xref-next-line () |
| 364 | "Move to the next xref and display its source in the other window." | 369 | "Move to the next xref and display its source in the other window." |
| 365 | (interactive) | 370 | (interactive) |
| @@ -388,11 +393,10 @@ WINDOW controls how the buffer is displayed: | |||
| 388 | 393 | ||
| 389 | (define-derived-mode xref--xref-buffer-mode fundamental-mode "XREF" | 394 | (define-derived-mode xref--xref-buffer-mode fundamental-mode "XREF" |
| 390 | "Mode for displaying cross-references." | 395 | "Mode for displaying cross-references." |
| 391 | (setq buffer-read-only t) | 396 | (setq buffer-read-only t)) |
| 392 | (add-hook 'pre-command-hook #'xref--restore-window-configuration nil t)) | ||
| 393 | 397 | ||
| 394 | (let ((map xref--xref-buffer-mode-map)) | 398 | (let ((map xref--xref-buffer-mode-map)) |
| 395 | (define-key map (kbd "q") #'quit-window) | 399 | (define-key map (kbd "q") #'xref--quit) |
| 396 | (define-key map (kbd "n") #'xref-next-line) | 400 | (define-key map (kbd "n") #'xref-next-line) |
| 397 | (define-key map (kbd "p") #'xref-prev-line) | 401 | (define-key map (kbd "p") #'xref-prev-line) |
| 398 | (define-key map (kbd "RET") #'xref-goto-xref) | 402 | (define-key map (kbd "RET") #'xref-goto-xref) |
| @@ -402,6 +406,18 @@ WINDOW controls how the buffer is displayed: | |||
| 402 | (define-key map (kbd ".") #'xref-next-line) | 406 | (define-key map (kbd ".") #'xref-next-line) |
| 403 | (define-key map (kbd ",") #'xref-prev-line)) | 407 | (define-key map (kbd ",") #'xref-prev-line)) |
| 404 | 408 | ||
| 409 | (defun xref--quit () | ||
| 410 | "Quit all windows in `xref--display-history', then quit current window." | ||
| 411 | (interactive) | ||
| 412 | (let ((window (selected-window)) | ||
| 413 | (history xref--display-history)) | ||
| 414 | (setq xref--display-history nil) | ||
| 415 | (pcase-dolist (`(,buf . ,win) history) | ||
| 416 | (when (and (window-live-p win) | ||
| 417 | (eq buf (window-buffer win))) | ||
| 418 | (quit-window nil win))) | ||
| 419 | (quit-window nil window))) | ||
| 420 | |||
| 405 | (defconst xref-buffer-name "*xref*" | 421 | (defconst xref-buffer-name "*xref*" |
| 406 | "The name of the buffer to show xrefs.") | 422 | "The name of the buffer to show xrefs.") |
| 407 | 423 | ||