aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorJoakim Verona2015-01-20 00:54:09 +0100
committerJoakim Verona2015-01-20 00:54:09 +0100
commitfee879f0a00bbe3f3389509874ee30a9cbc24cd4 (patch)
tree5bc4dc325818bec8a6a4cf20b1c907d23e24425a /lisp/progmodes
parent395a90fee92a836f55df0b879f8ee3d862d648ac (diff)
parentfb6462f056f616f3da8ae18037c7c2137fecb6fd (diff)
downloademacs-fee879f0a00bbe3f3389509874ee30a9cbc24cd4.tar.gz
emacs-fee879f0a00bbe3f3389509874ee30a9cbc24cd4.zip
Merge branch 'master' into xwidget
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/xref.el56
1 files changed, 38 insertions, 18 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 7f77d218a48..12123c8f2e2 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,32 @@ 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 (setq-local other-window-scroll-buffer buf)
356 (xref--save-to-history buf win)))))
343 357
344(defun xref--show-location (location) 358(defun xref--show-location (location)
345 (condition-case err 359 (condition-case err
346 (progn 360 (let ((xref-buf (current-buffer)))
347 (xref--goto-location location) 361 (xref--goto-location location)
348 (xref--display-position (point) t 1)) 362 (xref--display-position (point) t 1 xref-buf))
349 (user-error (message (error-message-string err))))) 363 (user-error (message (error-message-string err)))))
350 364
351(defun xref-show-location-at-point () 365(defun xref-show-location-at-point ()
@@ -353,14 +367,8 @@ WINDOW controls how the buffer is displayed:
353 (interactive) 367 (interactive)
354 (let ((loc (xref--location-at-point))) 368 (let ((loc (xref--location-at-point)))
355 (when loc 369 (when loc
356 (setq xref--window-configuration (current-window-configuration))
357 (xref--show-location loc)))) 370 (xref--show-location loc))))
358 371
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 () 372(defun xref-next-line ()
365 "Move to the next xref and display its source in the other window." 373 "Move to the next xref and display its source in the other window."
366 (interactive) 374 (interactive)
@@ -379,21 +387,21 @@ WINDOW controls how the buffer is displayed:
379(defvar-local xref--window nil) 387(defvar-local xref--window nil)
380 388
381(defun xref-goto-xref () 389(defun xref-goto-xref ()
382 "Jump to the xref at point and bury the xref buffer." 390 "Jump to the xref on the current line and bury the xref buffer."
383 (interactive) 391 (interactive)
392 (back-to-indentation)
384 (let ((loc (or (xref--location-at-point) 393 (let ((loc (or (xref--location-at-point)
385 (error "No reference at point"))) 394 (user-error "No reference at point")))
386 (window xref--window)) 395 (window xref--window))
387 (quit-window) 396 (xref--quit)
388 (xref--pop-to-location loc window))) 397 (xref--pop-to-location loc window)))
389 398
390(define-derived-mode xref--xref-buffer-mode fundamental-mode "XREF" 399(define-derived-mode xref--xref-buffer-mode fundamental-mode "XREF"
391 "Mode for displaying cross-references." 400 "Mode for displaying cross-references."
392 (setq buffer-read-only t) 401 (setq buffer-read-only t))
393 (add-hook 'pre-command-hook #'xref--restore-window-configuration nil t))
394 402
395(let ((map xref--xref-buffer-mode-map)) 403(let ((map xref--xref-buffer-mode-map))
396 (define-key map (kbd "q") #'quit-window) 404 (define-key map (kbd "q") #'xref--quit)
397 (define-key map (kbd "n") #'xref-next-line) 405 (define-key map (kbd "n") #'xref-next-line)
398 (define-key map (kbd "p") #'xref-prev-line) 406 (define-key map (kbd "p") #'xref-prev-line)
399 (define-key map (kbd "RET") #'xref-goto-xref) 407 (define-key map (kbd "RET") #'xref-goto-xref)
@@ -403,6 +411,18 @@ WINDOW controls how the buffer is displayed:
403 (define-key map (kbd ".") #'xref-next-line) 411 (define-key map (kbd ".") #'xref-next-line)
404 (define-key map (kbd ",") #'xref-prev-line)) 412 (define-key map (kbd ",") #'xref-prev-line))
405 413
414(defun xref--quit ()
415 "Quit all windows in `xref--display-history', then quit current window."
416 (interactive)
417 (let ((window (selected-window))
418 (history xref--display-history))
419 (setq xref--display-history nil)
420 (pcase-dolist (`(,buf . ,win) history)
421 (when (and (window-live-p win)
422 (eq buf (window-buffer win)))
423 (quit-window nil win)))
424 (quit-window nil window)))
425
406(defconst xref-buffer-name "*xref*" 426(defconst xref-buffer-name "*xref*"
407 "The name of the buffer to show xrefs.") 427 "The name of the buffer to show xrefs.")
408 428