diff options
| author | Dmitry Gutov | 2015-07-19 20:40:18 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2015-07-19 20:51:28 +0300 |
| commit | 50ad176d2868a6bc622014ebe49b5bad45d0372c (patch) | |
| tree | b15a8668ebc7ad773b90ab7ab26adfe761ca4235 | |
| parent | a46d268d28d278a6940679fc0d77d037aa52836f (diff) | |
| download | emacs-50ad176d2868a6bc622014ebe49b5bad45d0372c.tar.gz emacs-50ad176d2868a6bc622014ebe49b5bad45d0372c.zip | |
Add xref-after-jump-hook and xref-after-return-hook
* lisp/progmodes/xref.el (xref-after-jump-hook)
(xref-after-return-hook): New hooks.
(xref-pulse-on-jump): Remove, in favor of the above.
(xref-pulse-momentarily): Rename from xref--maybe-pulse.
(xref--pop-to-location, xref--display-position)
(xref-pop-marker-stack): Use the new hooks, as requested in
http://lists.gnu.org/archive/html/emacs-devel/2015-07/msg00213.html
| -rw-r--r-- | lisp/progmodes/xref.el | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 1caded0ea5a..8d9a7823024 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -253,8 +253,7 @@ backward." | |||
| 253 | 253 | ||
| 254 | (defcustom xref-marker-ring-length 16 | 254 | (defcustom xref-marker-ring-length 16 |
| 255 | "Length of the xref marker ring." | 255 | "Length of the xref marker ring." |
| 256 | :type 'integer | 256 | :type 'integer) |
| 257 | :version "25.1") | ||
| 258 | 257 | ||
| 259 | (defcustom xref-prompt-for-identifier '(not xref-find-definitions | 258 | (defcustom xref-prompt-for-identifier '(not xref-find-definitions |
| 260 | xref-find-definitions-other-window | 259 | xref-find-definitions-other-window |
| @@ -274,13 +273,16 @@ elements is negated." | |||
| 274 | (set :menu-tag "command specific" :tag "commands" | 273 | (set :menu-tag "command specific" :tag "commands" |
| 275 | :value (not) | 274 | :value (not) |
| 276 | (const :tag "Except" not) | 275 | (const :tag "Except" not) |
| 277 | (repeat :inline t (symbol :tag "command")))) | 276 | (repeat :inline t (symbol :tag "command"))))) |
| 278 | :version "25.1") | ||
| 279 | 277 | ||
| 280 | (defcustom xref-pulse-on-jump t | 278 | (defcustom xref-after-jump-hook '(recenter |
| 281 | "When non-nil, momentarily highlight jump locations." | 279 | xref-pulse-momentarily) |
| 282 | :type 'boolean | 280 | "Functions called after jumping to an xref." |
| 283 | :version "25.1") | 281 | :type 'hook) |
| 282 | |||
| 283 | (defcustom xref-after-return-hook '(xref-pulse-momentarily) | ||
| 284 | "Functions called after returning to a pre-jump location." | ||
| 285 | :type 'hook) | ||
| 284 | 286 | ||
| 285 | (defvar xref--marker-ring (make-ring xref-marker-ring-length) | 287 | (defvar xref--marker-ring (make-ring xref-marker-ring-length) |
| 286 | "Ring of markers to implement the marker stack.") | 288 | "Ring of markers to implement the marker stack.") |
| @@ -301,19 +303,18 @@ elements is negated." | |||
| 301 | (error "The marked buffer has been deleted"))) | 303 | (error "The marked buffer has been deleted"))) |
| 302 | (goto-char (marker-position marker)) | 304 | (goto-char (marker-position marker)) |
| 303 | (set-marker marker nil nil) | 305 | (set-marker marker nil nil) |
| 304 | (xref--maybe-pulse)))) | 306 | (run-hooks 'xref-after-return-hook)))) |
| 305 | 307 | ||
| 306 | (defun xref--maybe-pulse () | 308 | (defun xref-pulse-momentarily () |
| 307 | (when xref-pulse-on-jump | 309 | (let (beg end) |
| 308 | (let (beg end) | 310 | (save-excursion |
| 309 | (save-excursion | 311 | (back-to-indentation) |
| 310 | (back-to-indentation) | 312 | (if (eolp) |
| 311 | (if (eolp) | 313 | (setq beg (line-beginning-position) |
| 312 | (setq beg (line-beginning-position) | 314 | end (1+ (point))) |
| 313 | end (1+ (point))) | 315 | (setq beg (point) |
| 314 | (setq beg (point) | 316 | end (line-end-position)))) |
| 315 | end (line-end-position)))) | 317 | (pulse-momentary-highlight-region beg end 'next-error))) |
| 316 | (pulse-momentary-highlight-region beg end 'next-error)))) | ||
| 317 | 318 | ||
| 318 | ;; etags.el needs this | 319 | ;; etags.el needs this |
| 319 | (defun xref-clear-marker-stack () | 320 | (defun xref-clear-marker-stack () |
| @@ -349,7 +350,7 @@ WINDOW controls how the buffer is displayed: | |||
| 349 | ((nil) (switch-to-buffer (current-buffer))) | 350 | ((nil) (switch-to-buffer (current-buffer))) |
| 350 | (window (pop-to-buffer (current-buffer) t)) | 351 | (window (pop-to-buffer (current-buffer) t)) |
| 351 | (frame (let ((pop-up-frames t)) (pop-to-buffer (current-buffer) t)))) | 352 | (frame (let ((pop-up-frames t)) (pop-to-buffer (current-buffer) t)))) |
| 352 | (xref--maybe-pulse)) | 353 | (run-hooks 'xref-after-jump-hook)) |
| 353 | 354 | ||
| 354 | 355 | ||
| 355 | ;;; XREF buffer (part of the UI) | 356 | ;;; XREF buffer (part of the UI) |
| @@ -380,12 +381,11 @@ Used for temporary buffers.") | |||
| 380 | (when (and restore (not (eq (car restore) 'same))) | 381 | (when (and restore (not (eq (car restore) 'same))) |
| 381 | (push (cons buf win) xref--display-history)))) | 382 | (push (cons buf win) xref--display-history)))) |
| 382 | 383 | ||
| 383 | (defun xref--display-position (pos other-window recenter-arg xref-buf) | 384 | (defun xref--display-position (pos other-window xref-buf) |
| 384 | ;; Show the location, but don't hijack focus. | 385 | ;; Show the location, but don't hijack focus. |
| 385 | (with-selected-window (display-buffer (current-buffer) other-window) | 386 | (with-selected-window (display-buffer (current-buffer) other-window) |
| 386 | (goto-char pos) | 387 | (goto-char pos) |
| 387 | (recenter recenter-arg) | 388 | (run-hooks 'xref-after-jump-hook) |
| 388 | (xref--maybe-pulse) | ||
| 389 | (let ((buf (current-buffer)) | 389 | (let ((buf (current-buffer)) |
| 390 | (win (selected-window))) | 390 | (win (selected-window))) |
| 391 | (with-current-buffer xref-buf | 391 | (with-current-buffer xref-buf |
| @@ -404,7 +404,7 @@ Used for temporary buffers.") | |||
| 404 | (add-hook 'buffer-list-update-hook #'xref--mark-selected nil t) | 404 | (add-hook 'buffer-list-update-hook #'xref--mark-selected nil t) |
| 405 | (with-current-buffer xref-buf | 405 | (with-current-buffer xref-buf |
| 406 | (push buf xref--temporary-buffers)))) | 406 | (push buf xref--temporary-buffers)))) |
| 407 | (xref--display-position (point) t 1 xref-buf)) | 407 | (xref--display-position (point) t xref-buf)) |
| 408 | (user-error (message (error-message-string err))))) | 408 | (user-error (message (error-message-string err))))) |
| 409 | 409 | ||
| 410 | (defun xref-show-location-at-point () | 410 | (defun xref-show-location-at-point () |