diff options
| author | Dmitry Gutov | 2015-01-22 04:09:23 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2015-01-22 04:09:23 +0200 |
| commit | a17a5daebf50f9abd00341f606eae8aff73e9737 (patch) | |
| tree | d42c0858004b01546840786df952b02f468f407b | |
| parent | 20f66485526b69eb26f2e70bd835a5e1333559d5 (diff) | |
| download | emacs-a17a5daebf50f9abd00341f606eae8aff73e9737.tar.gz emacs-a17a5daebf50f9abd00341f606eae8aff73e9737.zip | |
xref: Input history and minor tweaks
* lisp/progmodes/xref.el (xref--current): Rename from `xref--selected'.
(xref--inhibit-mark-current): Rename from
`xref--inhibit-mark-selected'. Update the usages.
(xref-quit): Reword the docstring. Kill buffers after quitting
windows instead of before.
(xref--insert-xrefs): Tweak help-echo.
(xref--read-identifier-history, xref--read-pattern-history):
New variables.
(xref--read-identifier, xref-find-apropos): Use them.
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 55 |
2 files changed, 44 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7aa66bf9ad5..9b50a66a39d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2015-01-22 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * progmodes/xref.el (xref--current): Rename from `xref--selected'. | ||
| 4 | (xref--inhibit-mark-current): Rename from | ||
| 5 | `xref--inhibit-mark-selected'. Update the usages. | ||
| 6 | (xref-quit): Reword the docstring. Kill buffers after quitting | ||
| 7 | windows instead of before. | ||
| 8 | (xref--insert-xrefs): Tweak help-echo. | ||
| 9 | (xref--read-identifier-history, xref--read-pattern-history): | ||
| 10 | New variables. | ||
| 11 | (xref--read-identifier, xref-find-apropos): Use them. | ||
| 12 | |||
| 1 | 2015-01-21 Ulrich Müller <ulm@gentoo.org> | 13 | 2015-01-21 Ulrich Müller <ulm@gentoo.org> |
| 2 | 14 | ||
| 3 | * play/gamegrid.el (gamegrid-add-score-with-update-game-score): | 15 | * play/gamegrid.el (gamegrid-add-score-with-update-game-score): |
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index ee8125073aa..b82cd8eaacb 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -342,15 +342,15 @@ WINDOW controls how the buffer is displayed: | |||
| 342 | (defvar-local xref--temporary-buffers nil | 342 | (defvar-local xref--temporary-buffers nil |
| 343 | "List of buffers created by xref code.") | 343 | "List of buffers created by xref code.") |
| 344 | 344 | ||
| 345 | (defvar-local xref--selected nil | 345 | (defvar-local xref--current nil |
| 346 | "t if the current buffer has ever been selected. | 346 | "Non-nil if this buffer was once current, except while displaying xrefs. |
| 347 | Used for temporary buffers.") | 347 | Used for temporary buffers.") |
| 348 | 348 | ||
| 349 | (defvar xref--inhibit-mark-selected nil) | 349 | (defvar xref--inhibit-mark-current nil) |
| 350 | 350 | ||
| 351 | (defun xref--mark-selected () | 351 | (defun xref--mark-selected () |
| 352 | (unless xref--inhibit-mark-selected | 352 | (unless xref--inhibit-mark-current |
| 353 | (setq xref--selected t)) | 353 | (setq xref--current t)) |
| 354 | (remove-hook 'buffer-list-update-hook #'xref--mark-selected t)) | 354 | (remove-hook 'buffer-list-update-hook #'xref--mark-selected t)) |
| 355 | 355 | ||
| 356 | (defun xref--save-to-history (buf win) | 356 | (defun xref--save-to-history (buf win) |
| @@ -375,7 +375,7 @@ Used for temporary buffers.") | |||
| 375 | (condition-case err | 375 | (condition-case err |
| 376 | (let ((xref-buf (current-buffer)) | 376 | (let ((xref-buf (current-buffer)) |
| 377 | (bl (buffer-list)) | 377 | (bl (buffer-list)) |
| 378 | (xref--inhibit-mark-selected t)) | 378 | (xref--inhibit-mark-current t)) |
| 379 | (xref--goto-location location) | 379 | (xref--goto-location location) |
| 380 | (let ((buf (current-buffer))) | 380 | (let ((buf (current-buffer))) |
| 381 | (unless (memq buf bl) | 381 | (unless (memq buf bl) |
| @@ -438,29 +438,28 @@ Used for temporary buffers.") | |||
| 438 | (setq buffer-read-only t)) | 438 | (setq buffer-read-only t)) |
| 439 | 439 | ||
| 440 | (defun xref-quit (&optional kill) | 440 | (defun xref-quit (&optional kill) |
| 441 | "Perform cleanup, then quit the current window. | 441 | "Bury temporarily displayed buffers, then quit the current window. |
| 442 | The cleanup consists of burying all temporarily displayed | 442 | |
| 443 | buffers, and if KILL is non-nil, of killing all buffers that were | 443 | If KILL is non-nil, kill all buffers that were created in the |
| 444 | created in the process of showing xrefs. | 444 | process of showing xrefs, and also kill the current buffer. |
| 445 | 445 | ||
| 446 | Exceptions are made for buffers switched to by the user in the | 446 | The buffers that the user has otherwise interacted with in the |
| 447 | meantime, and other window configuration changes. These are | 447 | meantime are preserved." |
| 448 | preserved." | ||
| 449 | (interactive "P") | 448 | (interactive "P") |
| 450 | (let ((window (selected-window)) | 449 | (let ((window (selected-window)) |
| 451 | (history xref--display-history)) | 450 | (history xref--display-history)) |
| 452 | (setq xref--display-history nil) | 451 | (setq xref--display-history nil) |
| 452 | (pcase-dolist (`(,buf . ,win) history) | ||
| 453 | (when (and (window-live-p win) | ||
| 454 | (eq buf (window-buffer win))) | ||
| 455 | (quit-window nil win))) | ||
| 453 | (when kill | 456 | (when kill |
| 454 | (let ((xref--inhibit-mark-selected t) | 457 | (let ((xref--inhibit-mark-current t) |
| 455 | kill-buffer-query-functions) | 458 | kill-buffer-query-functions) |
| 456 | (dolist (buf xref--temporary-buffers) | 459 | (dolist (buf xref--temporary-buffers) |
| 457 | (unless (buffer-local-value 'xref--selected buf) | 460 | (unless (buffer-local-value 'xref--current buf) |
| 458 | (kill-buffer buf))) | 461 | (kill-buffer buf))) |
| 459 | (setq xref--temporary-buffers nil))) | 462 | (setq xref--temporary-buffers nil))) |
| 460 | (pcase-dolist (`(,buf . ,win) history) | ||
| 461 | (when (and (window-live-p win) | ||
| 462 | (eq buf (window-buffer win))) | ||
| 463 | (quit-window nil win))) | ||
| 464 | (quit-window kill window))) | 463 | (quit-window kill window))) |
| 465 | 464 | ||
| 466 | (defconst xref-buffer-name "*xref*" | 465 | (defconst xref-buffer-name "*xref*" |
| @@ -496,7 +495,9 @@ GROUP is a string for decoration purposes and XREF is an | |||
| 496 | 'face 'font-lock-keyword-face | 495 | 'face 'font-lock-keyword-face |
| 497 | 'mouse-face 'highlight | 496 | 'mouse-face 'highlight |
| 498 | 'keymap xref--button-map | 497 | 'keymap xref--button-map |
| 499 | 'help-echo "mouse-2: display in another window, RET or mouse-1: navigate") | 498 | 'help-echo |
| 499 | (concat "mouse-2: display in another window, " | ||
| 500 | "RET or mouse-1: follow reference")) | ||
| 500 | description)) | 501 | description)) |
| 501 | (when (or more1 more2) | 502 | (when (or more1 more2) |
| 502 | (insert "\n"))))) | 503 | (insert "\n"))))) |
| @@ -535,6 +536,10 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 535 | (defvar xref-show-xrefs-function 'xref--show-xref-buffer | 536 | (defvar xref-show-xrefs-function 'xref--show-xref-buffer |
| 536 | "Function to display a list of xrefs.") | 537 | "Function to display a list of xrefs.") |
| 537 | 538 | ||
| 539 | (defvar xref--read-identifier-history nil) | ||
| 540 | |||
| 541 | (defvar xref--read-pattern-history nil) | ||
| 542 | |||
| 538 | (defun xref--show-xrefs (input kind arg window) | 543 | (defun xref--show-xrefs (input kind arg window) |
| 539 | (let* ((bl (buffer-list)) | 544 | (let* ((bl (buffer-list)) |
| 540 | (xrefs (funcall xref-find-function kind arg)) | 545 | (xrefs (funcall xref-find-function kind arg)) |
| @@ -557,7 +562,8 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 557 | (cond ((or current-prefix-arg (not id)) | 562 | (cond ((or current-prefix-arg (not id)) |
| 558 | (completing-read prompt | 563 | (completing-read prompt |
| 559 | (funcall xref-identifier-completion-table-function) | 564 | (funcall xref-identifier-completion-table-function) |
| 560 | nil t id)) | 565 | nil t id |
| 566 | 'xref--read-identifier-history)) | ||
| 561 | (t id)))) | 567 | (t id)))) |
| 562 | 568 | ||
| 563 | 569 | ||
| @@ -593,12 +599,15 @@ With prefix argument, prompt for the identifier." | |||
| 593 | (interactive (list (xref--read-identifier "Find references of: "))) | 599 | (interactive (list (xref--read-identifier "Find references of: "))) |
| 594 | (xref--show-xrefs identifier 'references identifier nil)) | 600 | (xref--show-xrefs identifier 'references identifier nil)) |
| 595 | 601 | ||
| 602 | (declare-function apropos-parse-pattern "apropos" (pattern)) | ||
| 603 | |||
| 596 | ;;;###autoload | 604 | ;;;###autoload |
| 597 | (defun xref-find-apropos (pattern) | 605 | (defun xref-find-apropos (pattern) |
| 598 | "Find all meaningful symbols that match PATTERN. | 606 | "Find all meaningful symbols that match PATTERN. |
| 599 | The argument has the same meaning as in `apropos'." | 607 | The argument has the same meaning as in `apropos'." |
| 600 | (interactive (list (read-from-minibuffer | 608 | (interactive (list (read-from-minibuffer |
| 601 | "Search for pattern (word list or regexp): "))) | 609 | "Search for pattern (word list or regexp): " |
| 610 | nil nil nil 'xref--read-pattern-history))) | ||
| 602 | (require 'apropos) | 611 | (require 'apropos) |
| 603 | (xref--show-xrefs pattern 'apropos | 612 | (xref--show-xrefs pattern 'apropos |
| 604 | (apropos-parse-pattern | 613 | (apropos-parse-pattern |