aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDmitry Gutov2015-08-05 15:18:25 +0300
committerDmitry Gutov2015-08-05 15:19:04 +0300
commitee50e62a44d18be697917e1ea708db1c06f590fb (patch)
tree480c9e1c04f5ab8cb6a4ccdaa7399c90d0f3a1ec /lisp
parent8dbae880947dc7c9f1e8a6be41d3ba18306c1aed (diff)
downloademacs-ee50e62a44d18be697917e1ea708db1c06f590fb.tar.gz
emacs-ee50e62a44d18be697917e1ea708db1c06f590fb.zip
Preserve window point in xref-find-definitions-other-window
Fix the problem reported by Ingo Logmar in http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00152.html * lisp/progmodes/xref.el (xref--goto-char): Extract from xref--goto-location. (xref--pop-to-location): Use it. Replace xref--goto-location with a direct xref-location-marker call. (xref--show-location): Likewise. (xref--display-position): Use xref--goto-char.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/xref.el47
1 files changed, 26 insertions, 21 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 27e56f2f94f..c37a4aafe97 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -65,8 +65,6 @@
65(defclass xref-location () () 65(defclass xref-location () ()
66 :documentation "A location represents a position in a file or buffer.") 66 :documentation "A location represents a position in a file or buffer.")
67 67
68;; If a backend decides to subclass xref-location it can provide
69;; methods for some of the following functions:
70(cl-defgeneric xref-location-marker (location) 68(cl-defgeneric xref-location-marker (location)
71 "Return the marker for LOCATION.") 69 "Return the marker for LOCATION.")
72 70
@@ -372,14 +370,19 @@ elements is negated."
372 (ring-empty-p xref--marker-ring)) 370 (ring-empty-p xref--marker-ring))
373 371
374 372
373
374(defun xref--goto-char (pos)
375 (cond
376 ((and (<= (point-min) pos) (<= pos (point-max))))
377 (widen-automatically (widen))
378 (t (user-error "Position is outside accessible part of buffer")))
379 (goto-char pos))
380
375(defun xref--goto-location (location) 381(defun xref--goto-location (location)
376 "Set buffer and point according to xref-location LOCATION." 382 "Set buffer and point according to xref-location LOCATION."
377 (let ((marker (xref-location-marker location))) 383 (let ((marker (xref-location-marker location)))
378 (set-buffer (marker-buffer marker)) 384 (set-buffer (marker-buffer marker))
379 (cond ((and (<= (point-min) marker) (<= marker (point-max)))) 385 (xref--goto-char marker)))
380 (widen-automatically (widen))
381 (t (error "Location is outside accessible part of buffer")))
382 (goto-char marker)))
383 386
384(defun xref--pop-to-location (item &optional window) 387(defun xref--pop-to-location (item &optional window)
385 "Go to the location of ITEM and display the buffer. 388 "Go to the location of ITEM and display the buffer.
@@ -387,11 +390,14 @@ WINDOW controls how the buffer is displayed:
387 nil -- switch-to-buffer 390 nil -- switch-to-buffer
388 'window -- pop-to-buffer (other window) 391 'window -- pop-to-buffer (other window)
389 'frame -- pop-to-buffer (other frame)" 392 'frame -- pop-to-buffer (other frame)"
390 (xref--goto-location (xref-item-location item)) 393 (let* ((marker (save-excursion
391 (cl-ecase window 394 (xref-location-marker (xref-item-location item))))
392 ((nil) (switch-to-buffer (current-buffer))) 395 (buf (marker-buffer marker)))
393 (window (pop-to-buffer (current-buffer) t)) 396 (cl-ecase window
394 (frame (let ((pop-up-frames t)) (pop-to-buffer (current-buffer) t)))) 397 ((nil) (switch-to-buffer buf))
398 (window (pop-to-buffer buf t))
399 (frame (let ((pop-up-frames t)) (pop-to-buffer buf t))))
400 (xref--goto-char marker))
395 (let ((xref--current-item item)) 401 (let ((xref--current-item item))
396 (run-hooks 'xref-after-jump-hook))) 402 (run-hooks 'xref-after-jump-hook)))
397 403
@@ -427,7 +433,7 @@ Used for temporary buffers.")
427(defun xref--display-position (pos other-window xref-buf) 433(defun xref--display-position (pos other-window xref-buf)
428 ;; Show the location, but don't hijack focus. 434 ;; Show the location, but don't hijack focus.
429 (with-selected-window (display-buffer (current-buffer) other-window) 435 (with-selected-window (display-buffer (current-buffer) other-window)
430 (goto-char pos) 436 (xref--goto-char pos)
431 (run-hooks 'xref-after-jump-hook) 437 (run-hooks 'xref-after-jump-hook)
432 (let ((buf (current-buffer)) 438 (let ((buf (current-buffer))
433 (win (selected-window))) 439 (win (selected-window)))
@@ -437,17 +443,15 @@ Used for temporary buffers.")
437 443
438(defun xref--show-location (location) 444(defun xref--show-location (location)
439 (condition-case err 445 (condition-case err
440 (let ((xref-buf (current-buffer)) 446 (let ((bl (buffer-list))
441 (bl (buffer-list)) 447 (xref--inhibit-mark-current t)
442 (xref--inhibit-mark-current t)) 448 (marker (xref-location-marker location)))
443 (xref--goto-location location) 449 (let ((buf (marker-buffer marker)))
444 (let ((buf (current-buffer)))
445 (unless (memq buf bl) 450 (unless (memq buf bl)
446 ;; Newly created. 451 ;; Newly created.
447 (add-hook 'buffer-list-update-hook #'xref--mark-selected nil t) 452 (add-hook 'buffer-list-update-hook #'xref--mark-selected nil t)
448 (with-current-buffer xref-buf 453 (push buf xref--temporary-buffers)))
449 (push buf xref--temporary-buffers)))) 454 (xref--display-position (point) t (current-buffer)))
450 (xref--display-position (point) t xref-buf))
451 (user-error (message (error-message-string err))))) 455 (user-error (message (error-message-string err)))))
452 456
453(defun xref-show-location-at-point () 457(defun xref-show-location-at-point ()
@@ -504,6 +508,8 @@ Used for temporary buffers.")
504 (while (setq item (xref--search-property 'xref-item)) 508 (while (setq item (xref--search-property 'xref-item))
505 (when (xref-match-bounds item) 509 (when (xref-match-bounds item)
506 (save-excursion 510 (save-excursion
511 ;; FIXME: Get rid of xref--goto-location, by making
512 ;; xref-match-bounds return markers already.
507 (xref--goto-location (xref-item-location item)) 513 (xref--goto-location (xref-item-location item))
508 (let ((bounds (xref--match-buffer-bounds item)) 514 (let ((bounds (xref--match-buffer-bounds item))
509 (beg (make-marker)) 515 (beg (make-marker))
@@ -849,7 +855,6 @@ and just use etags."
849 (cdr xref-etags-mode--saved)))) 855 (cdr xref-etags-mode--saved))))
850 856
851(declare-function semantic-symref-find-references-by-name "semantic/symref") 857(declare-function semantic-symref-find-references-by-name "semantic/symref")
852(declare-function semantic-symref-find-text "semantic/symref")
853(declare-function semantic-find-file-noselect "semantic/fw") 858(declare-function semantic-find-file-noselect "semantic/fw")
854(declare-function grep-read-files "grep") 859(declare-function grep-read-files "grep")
855(declare-function grep-expand-template "grep") 860(declare-function grep-expand-template "grep")