aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2018-05-30 10:24:46 -0500
committerRoland Winkler2018-05-30 10:24:46 -0500
commitadc20d64eb551349f628040c7d04f0edf1c76493 (patch)
treea9165bcae56a2d9f2af6f53f98b01dd629602c75
parentec129c194725c5617a32037d2ab8b0df09bcac0f (diff)
downloademacs-adc20d64eb551349f628040c7d04f0edf1c76493.tar.gz
emacs-adc20d64eb551349f628040c7d04f0edf1c76493.zip
bibtex-search-entry: Reuse the window displaying the buffer.
* textmodes/bibtex.el (bibtex-reposition-window): New optional arg pos. (bibtex-search-crossref, bibtex-search-entry): Use it. (bibtex-search-entry): If possible, reuse the window displaying the buffer that contains the entry found.
-rw-r--r--lisp/textmodes/bibtex.el20
1 files changed, 13 insertions, 7 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index dc19c3c0b98..50a30cf6c36 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -3850,11 +3850,13 @@ Return the new location of point."
3850 (re-search-forward "[\n\C-m]" nil 'end (1- arg)) 3850 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
3851 (forward-line (1- arg)))) 3851 (forward-line (1- arg))))
3852 3852
3853(defun bibtex-reposition-window () 3853(defun bibtex-reposition-window (&optional pos)
3854 "Make the current BibTeX entry visible. 3854 "Make the current BibTeX entry visible.
3855If entry is smaller than `window-body-height', entry is centered in window. 3855If entry is smaller than `window-body-height', entry is centered in window.
3856Otherwise display the beginning of entry." 3856Otherwise display the beginning of entry.
3857Optional arg POS is the position of the BibTeX entry to use."
3857 (interactive) 3858 (interactive)
3859 (if pos (goto-char pos))
3858 (let ((pnt (point)) 3860 (let ((pnt (point))
3859 (beg (line-number-at-pos (bibtex-beginning-of-entry))) 3861 (beg (line-number-at-pos (bibtex-beginning-of-entry)))
3860 (end (line-number-at-pos (bibtex-end-of-entry)))) 3862 (end (line-number-at-pos (bibtex-end-of-entry))))
@@ -4063,8 +4065,7 @@ for a crossref key, t otherwise."
4063 (message "Key `%s' is current entry" crossref-key) 4065 (message "Key `%s' is current entry" crossref-key)
4064 (if eqb (select-window (split-window)) 4066 (if eqb (select-window (split-window))
4065 (pop-to-buffer buffer)) 4067 (pop-to-buffer buffer))
4066 (goto-char pos) 4068 (bibtex-reposition-window pos)
4067 (bibtex-reposition-window)
4068 (beginning-of-line) 4069 (beginning-of-line)
4069 (if (and eqb (> pnt pos) (not noerror)) 4070 (if (and eqb (> pnt pos) (not noerror))
4070 (error "The referencing entry must precede the crossrefed entry!")))) 4071 (error "The referencing entry must precede the crossrefed entry!"))))
@@ -4112,9 +4113,14 @@ A prefix arg negates the value of `bibtex-search-entry-globally'."
4112 (if (cdr (assoc-string key bibtex-reference-keys)) 4113 (if (cdr (assoc-string key bibtex-reference-keys))
4113 (setq found (bibtex-search-entry key))))) 4114 (setq found (bibtex-search-entry key)))))
4114 (cond ((and found display) 4115 (cond ((and found display)
4115 (switch-to-buffer buffer) 4116 ;; If possible, reuse the window displaying BUFFER.
4116 (goto-char found) 4117 (let ((window (get-buffer-window buffer t)))
4117 (bibtex-reposition-window)) 4118 (if window
4119 (progn
4120 (select-frame-set-input-focus (window-frame window))
4121 (select-window window))
4122 (switch-to-buffer buffer)))
4123 (bibtex-reposition-window found))
4118 (found (set-buffer buffer)) 4124 (found (set-buffer buffer))
4119 (display (message "Key `%s' not found" key))) 4125 (display (message "Key `%s' not found" key)))
4120 found) 4126 found)