diff options
| author | Dmitry Gutov | 2015-01-19 04:19:32 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2015-01-19 04:19:32 +0200 |
| commit | 36bfd6947f8671eb279d8aa8f2976ada24361dec (patch) | |
| tree | 96e832885931f1419c3ae197d96d55187dfafff4 | |
| parent | b87d7cc2493335c68f3376a0455a7b00224ca1f6 (diff) | |
| download | emacs-36bfd6947f8671eb279d8aa8f2976ada24361dec.tar.gz emacs-36bfd6947f8671eb279d8aa8f2976ada24361dec.zip | |
Use quit-window to hide buffers temporarily displayed by xref
* lisp/progmodes/xref.el (xref--display-history): New variable.
(xref--window-configuration): Remove.
(xref--save-to-history): New function.
(xref--display-position): Use it. 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-goto-xref): Use it.
(xref--xref-buffer-mode-map): Bind `q' to it.
| -rw-r--r-- | lisp/ChangeLog | 14 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 50 |
2 files changed, 48 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d84e83158c2..39d9436b3f1 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | 2015-01-19 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * progmodes/xref.el (xref--display-history): New variable. | ||
| 4 | (xref--window-configuration): Remove. | ||
| 5 | (xref--save-to-history): New function. | ||
| 6 | (xref--display-position): Use it. Add new argument. | ||
| 7 | (xref--restore-window-configuration): Remove. | ||
| 8 | (xref--show-location, xref-show-location-at-point): Update | ||
| 9 | accordingly. | ||
| 10 | (xref--xref-buffer-mode): Don't use `pre-command-hook'. | ||
| 11 | (xref--quit): New command. | ||
| 12 | (xref-goto-xref): Use it. | ||
| 13 | (xref--xref-buffer-mode-map): Bind `q' to it. | ||
| 14 | |||
| 1 | 2015-01-18 Dmitry Gutov <dgutov@yandex.ru> | 15 | 2015-01-18 Dmitry Gutov <dgutov@yandex.ru> |
| 2 | 16 | ||
| 3 | * progmodes/xref.el (xref-goto-xref): Perform the jump even inside | 17 | * progmodes/xref.el (xref-goto-xref): Perform the jump even inside |
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 59da5793295..4431cb5d3b3 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -51,6 +51,7 @@ | |||
| 51 | (require 'cl-lib) | 51 | (require 'cl-lib) |
| 52 | (require 'eieio) | 52 | (require 'eieio) |
| 53 | (require 'ring) | 53 | (require 'ring) |
| 54 | (require 'pcase) | ||
| 54 | 55 | ||
| 55 | (defgroup xref nil "Cross-referencing commands" | 56 | (defgroup xref nil "Cross-referencing commands" |
| 56 | :group 'tools) | 57 | :group 'tools) |
| @@ -333,19 +334,31 @@ WINDOW controls how the buffer is displayed: | |||
| 333 | 334 | ||
| 334 | ;; The xref buffer is used to display a set of xrefs. | 335 | ;; The xref buffer is used to display a set of xrefs. |
| 335 | 336 | ||
| 336 | (defvar-local xref--window-configuration nil) | 337 | (defvar-local xref--display-history nil |
| 338 | "List of pairs (BUFFER . WINDOW), for temporarily displayed buffers.") | ||
| 337 | 339 | ||
| 338 | (defun xref--display-position (pos other-window recenter-arg) | 340 | (defun xref--save-to-history (buf win) |
| 339 | ;; show the location, but don't hijack focus. | 341 | (let ((restore (window-parameter win 'quit-restore))) |
| 342 | ;; Save the new entry if the window displayed another buffer | ||
| 343 | ;; previously. | ||
| 344 | (when (and restore (not (eq (car restore) 'same))) | ||
| 345 | (push (cons buf win) xref--display-history)))) | ||
| 346 | |||
| 347 | (defun xref--display-position (pos other-window recenter-arg xref-buf) | ||
| 348 | ;; Show the location, but don't hijack focus. | ||
| 340 | (with-selected-window (display-buffer (current-buffer) other-window) | 349 | (with-selected-window (display-buffer (current-buffer) other-window) |
| 341 | (goto-char pos) | 350 | (goto-char pos) |
| 342 | (recenter recenter-arg))) | 351 | (recenter recenter-arg) |
| 352 | (let ((buf (current-buffer)) | ||
| 353 | (win (selected-window))) | ||
| 354 | (with-current-buffer xref-buf | ||
| 355 | (xref--save-to-history buf win))))) | ||
| 343 | 356 | ||
| 344 | (defun xref--show-location (location) | 357 | (defun xref--show-location (location) |
| 345 | (condition-case err | 358 | (condition-case err |
| 346 | (progn | 359 | (let ((xref-buf (current-buffer))) |
| 347 | (xref--goto-location location) | 360 | (xref--goto-location location) |
| 348 | (xref--display-position (point) t 1)) | 361 | (xref--display-position (point) t 1 xref-buf)) |
| 349 | (user-error (message (error-message-string err))))) | 362 | (user-error (message (error-message-string err))))) |
| 350 | 363 | ||
| 351 | (defun xref-show-location-at-point () | 364 | (defun xref-show-location-at-point () |
| @@ -353,14 +366,8 @@ WINDOW controls how the buffer is displayed: | |||
| 353 | (interactive) | 366 | (interactive) |
| 354 | (let ((loc (xref--location-at-point))) | 367 | (let ((loc (xref--location-at-point))) |
| 355 | (when loc | 368 | (when loc |
| 356 | (setq xref--window-configuration (current-window-configuration)) | ||
| 357 | (xref--show-location loc)))) | 369 | (xref--show-location loc)))) |
| 358 | 370 | ||
| 359 | (defun xref--restore-window-configuration () | ||
| 360 | (when xref--window-configuration | ||
| 361 | (set-window-configuration xref--window-configuration) | ||
| 362 | (setq xref--window-configuration nil))) | ||
| 363 | |||
| 364 | (defun xref-next-line () | 371 | (defun xref-next-line () |
| 365 | "Move to the next xref and display its source in the other window." | 372 | "Move to the next xref and display its source in the other window." |
| 366 | (interactive) | 373 | (interactive) |
| @@ -385,16 +392,15 @@ WINDOW controls how the buffer is displayed: | |||
| 385 | (let ((loc (or (xref--location-at-point) | 392 | (let ((loc (or (xref--location-at-point) |
| 386 | (error "No reference at point"))) | 393 | (error "No reference at point"))) |
| 387 | (window xref--window)) | 394 | (window xref--window)) |
| 388 | (quit-window) | 395 | (xref--quit) |
| 389 | (xref--pop-to-location loc window))) | 396 | (xref--pop-to-location loc window))) |
| 390 | 397 | ||
| 391 | (define-derived-mode xref--xref-buffer-mode fundamental-mode "XREF" | 398 | (define-derived-mode xref--xref-buffer-mode fundamental-mode "XREF" |
| 392 | "Mode for displaying cross-references." | 399 | "Mode for displaying cross-references." |
| 393 | (setq buffer-read-only t) | 400 | (setq buffer-read-only t)) |
| 394 | (add-hook 'pre-command-hook #'xref--restore-window-configuration nil t)) | ||
| 395 | 401 | ||
| 396 | (let ((map xref--xref-buffer-mode-map)) | 402 | (let ((map xref--xref-buffer-mode-map)) |
| 397 | (define-key map (kbd "q") #'quit-window) | 403 | (define-key map (kbd "q") #'xref--quit) |
| 398 | (define-key map (kbd "n") #'xref-next-line) | 404 | (define-key map (kbd "n") #'xref-next-line) |
| 399 | (define-key map (kbd "p") #'xref-prev-line) | 405 | (define-key map (kbd "p") #'xref-prev-line) |
| 400 | (define-key map (kbd "RET") #'xref-goto-xref) | 406 | (define-key map (kbd "RET") #'xref-goto-xref) |
| @@ -404,6 +410,18 @@ WINDOW controls how the buffer is displayed: | |||
| 404 | (define-key map (kbd ".") #'xref-next-line) | 410 | (define-key map (kbd ".") #'xref-next-line) |
| 405 | (define-key map (kbd ",") #'xref-prev-line)) | 411 | (define-key map (kbd ",") #'xref-prev-line)) |
| 406 | 412 | ||
| 413 | (defun xref--quit () | ||
| 414 | "Quit all windows in `xref--display-history', then quit current window." | ||
| 415 | (interactive) | ||
| 416 | (let ((window (selected-window)) | ||
| 417 | (history xref--display-history)) | ||
| 418 | (setq xref--display-history nil) | ||
| 419 | (pcase-dolist (`(,buf . ,win) history) | ||
| 420 | (when (and (window-live-p win) | ||
| 421 | (eq buf (window-buffer win))) | ||
| 422 | (quit-window nil win))) | ||
| 423 | (quit-window nil window))) | ||
| 424 | |||
| 407 | (defconst xref-buffer-name "*xref*" | 425 | (defconst xref-buffer-name "*xref*" |
| 408 | "The name of the buffer to show xrefs.") | 426 | "The name of the buffer to show xrefs.") |
| 409 | 427 | ||