From 32b24bc8d1653cab931b09570bbfc4249993b945 Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Tue, 11 Jan 2011 16:55:59 +0100 Subject: [PATCH] Sanitize some buffer display calls with new method specifiers. * buff-menu.el (Buffer-menu-mode-map): Bind "q" to quit-restore-window. (buffer-menu): Call pop-to-buffer-same-window. (buffer-menu-other-window): Call pop-to-buffer-other-window. (Buffer-menu-select): Rewrite using display-buffer-same-window and display-buffer. (Buffer-menu-1-window, Buffer-menu-mouse-select) (Buffer-menu-this-window): Call pop-to-buffer-same-window. (Buffer-menu-other-window): Call pop-to-buffer-other-window. (Buffer-menu-switch-other-window): Call display-buffer-same-frame-other-window. (Buffer-menu-2-window): Add label argument in calls of display-buffer-same-window and pop-to-buffer-same-frame-other-window. * mail/reporter.el (reporter-submit-bug-report): Use display-buffer-same-frame-other-window. * progmodes/compile.el (compilation-find-file): Use display-buffer-same-frame. * progmodes/inf-lisp.el (switch-to-lisp): Rewrite with new buffer display method specifiers. * vc/ediff-ptch.el (ediff-get-patch-buffer): Use pop-to-buffer-other-window. (ediff-patch-file-internal): Replace switch-to-buffer by pop-to-buffer-same-window and switch-to-buffer-other-window by pop-to-buffer-other-window. * vc/pcvs.el (cvs-ediff-exit-hook): Call pop-to-buffer-same-window instead of switch-to-buffer. (cvs-mode-find-file): Replace switch-to-buffer and switch-to-buffer-other-window by pop-to-buffer-same-window and pop-to-buffer-other-window. Replace call to dired-other-window by call to display-buffer-other-window. (cvs-temp-buffer): Call display-buffer-other-window instead of display-buffer. * vc/pcvs-util.el (cvs-bury-buffer): Call quit-restore-window. --- lisp/ChangeLog | 43 +++++++++++++++++ lisp/buff-menu.el | 99 +++++++++++++++++--------------------- lisp/mail/reporter.el | 4 +- lisp/progmodes/compile.el | 4 +- lisp/progmodes/inf-lisp.el | 5 +- lisp/vc/ediff-ptch.el | 6 +-- lisp/vc/pcvs-util.el | 15 ++---- lisp/vc/pcvs.el | 18 ++++--- 8 files changed, 112 insertions(+), 82 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0dcfc47d460..de6afa11057 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,46 @@ +2011-01-11 Martin Rudalics + + * buff-menu.el (Buffer-menu-mode-map): Bind "q" to + quit-restore-window. + (buffer-menu): Call pop-to-buffer-same-window. + (buffer-menu-other-window): Call pop-to-buffer-other-window. + (Buffer-menu-select): Rewrite using display-buffer-same-window + and display-buffer. + (Buffer-menu-1-window, Buffer-menu-mouse-select) + (Buffer-menu-this-window): Call pop-to-buffer-same-window. + (Buffer-menu-other-window): Call pop-to-buffer-other-window. + (Buffer-menu-switch-other-window): Call + display-buffer-same-frame-other-window. + (Buffer-menu-2-window): Add label argument in calls of + display-buffer-same-window and + pop-to-buffer-same-frame-other-window. + + * mail/reporter.el (reporter-submit-bug-report): Use + display-buffer-same-frame-other-window. + + * progmodes/compile.el (compilation-find-file): Use + display-buffer-same-frame. + + * progmodes/inf-lisp.el (switch-to-lisp): Rewrite with new buffer + display method specifiers. + + * vc/ediff-ptch.el (ediff-get-patch-buffer): Use + pop-to-buffer-other-window. + (ediff-patch-file-internal): Replace switch-to-buffer by + pop-to-buffer-same-window and switch-to-buffer-other-window by + pop-to-buffer-other-window. + + * vc/pcvs.el (cvs-ediff-exit-hook): Call + pop-to-buffer-same-window instead of switch-to-buffer. + (cvs-mode-find-file): Replace switch-to-buffer and + switch-to-buffer-other-window by pop-to-buffer-same-window and + pop-to-buffer-other-window. Replace call to dired-other-window + by call to display-buffer-other-window. + (cvs-temp-buffer): Call display-buffer-other-window instead of + display-buffer. + + * vc/pcvs-util.el (cvs-bury-buffer): Call quit-restore-window. + 2011-01-09 Martin Rudalics * dired.el (dired-pop-to-buffer): Call diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el index b5e8db7dae7..7600e661463 100644 --- a/lisp/buff-menu.el +++ b/lisp/buff-menu.el @@ -47,20 +47,6 @@ ;;; Code: -;;Trying to preserve the old window configuration works well in -;;simple scenarios, when you enter the buffer menu, use it, and exit it. -;;But it does strange things when you switch back to the buffer list buffer -;;with C-x b, later on, when the window configuration is different. -;;The choice seems to be, either restore the window configuration -;;in all cases, or in no cases. -;;I decided it was better not to restore the window config at all. -- rms. - -;;But since then, I changed buffer-menu to use the selected window, -;;so q now once again goes back to the previous window configuration. - -;;(defvar Buffer-menu-window-config nil -;; "Window configuration saved from entry to `buffer-menu'.") - ;; Put buffer *Buffer List* into proper mode right away ;; so that from now on even list-buffers is enough to get a buffer menu. @@ -155,7 +141,7 @@ Auto Revert Mode.") (define-key map (kbd "M-s a M-C-s") 'Buffer-menu-isearch-buffers-regexp) (define-key map [menu-bar Buffer-menu-mode] (cons (purecopy "Buffer-Menu") menu-map)) (define-key menu-map [quit] - `(menu-item ,(purecopy "Quit") quit-window + `(menu-item ,(purecopy "Quit") quit-restore-window :help ,(purecopy "Remove the buffer menu from the display"))) (define-key menu-map [rev] `(menu-item ,(purecopy "Refresh") revert-buffer @@ -335,8 +321,8 @@ or `S' if you have marked it for saving. After this come the buffer name, its size in characters, its major mode, and the visited file name (if any)." (interactive "P") -;;; (setq Buffer-menu-window-config (current-window-configuration)) - (switch-to-buffer (list-buffers-noselect arg)) + (pop-to-buffer-same-window + (list-buffers-noselect arg) nil 'buffer-menu) (message "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) @@ -348,8 +334,8 @@ Type ? after invocation to get help on commands available. Type q to remove the buffer menu from the display. For more information, see the function `buffer-menu'." (interactive "P") -;;; (setq Buffer-menu-window-config (current-window-configuration)) - (switch-to-buffer-other-window (list-buffers-noselect arg)) + (pop-to-buffer-other-window + (list-buffers-noselect arg) nil 'buffer-menu-other-window) (message "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) @@ -484,8 +470,7 @@ in the selected frame." (interactive) (let ((buff (Buffer-menu-buffer t)) (menu (current-buffer)) - (others ()) - tem) + others tem buff-window) (Buffer-menu-beginning) (while (re-search-forward "^>" nil t) (setq tem (Buffer-menu-buffer t)) @@ -493,28 +478,27 @@ in the selected frame." (delete-char -1) (insert ?\s)) (or (eq tem buff) (memq tem others) (setq others (cons tem others)))) - (setq others (nreverse others) - tem (/ (1- (frame-height)) (1+ (length others)))) + (setq others (nreverse others)) + ;; Now start displaying the buffers. (delete-other-windows) - (switch-to-buffer buff) - (or (eq menu buff) - (bury-buffer menu)) - (if (equal (length others) 0) - (progn -;;; ;; Restore previous window configuration before displaying -;;; ;; selected buffers. -;;; (if Buffer-menu-window-config -;;; (progn -;;; (set-window-configuration Buffer-menu-window-config) -;;; (setq Buffer-menu-window-config nil))) - (switch-to-buffer buff)) - (while others - (split-window nil tem) - (other-window 1) - (switch-to-buffer (car others)) - (setq others (cdr others))) - (other-window 1) ;back to the beginning! -))) + (setq buff-window (display-buffer-same-window + buff 'Buffer-menu-select-buff)) + (unless (eq menu buff) + (bury-buffer menu)) + (when others + ;; Never rebind `window-splits' to anything but 'binary ... + (let ((window-splits 'resize) + (window buff-window) + other) + (while (and window others) + (setq other (car others)) + ;; Try to always split the last window, so we get them in the + ;; appropriate order. This will fail when the frame is full, + ;; which means that the user has marked too many buffers. + (setq window (display-buffer + other `((pop-up-window (,window . below))) + 'Buffer-menu-select-other)) + (setq others (cdr others))))))) (defun Buffer-menu-marked-buffers () "Return a list of buffers marked with the \\\\[Buffer-menu-mark] command." @@ -546,9 +530,11 @@ in the selected frame." (defun Buffer-menu-1-window () "Select this line's buffer, alone, in full frame." (interactive) - (switch-to-buffer (Buffer-menu-buffer t)) - (bury-buffer (other-buffer)) - (delete-other-windows)) + (let ((menu (current-buffer))) + (pop-to-buffer-same-window + (Buffer-menu-buffer t) nil 'buffer-menu-1-window) + (bury-buffer menu) + (delete-other-windows))) (defun Buffer-menu-mouse-select (event) "Select the buffer whose line you click on." @@ -559,26 +545,28 @@ in the selected frame." (goto-char (posn-point (event-end event))) (setq buffer (Buffer-menu-buffer t)))) (select-window (posn-window (event-end event))) - (if (and (window-dedicated-p (selected-window)) - (eq (selected-window) (frame-root-window))) - (switch-to-buffer-other-frame buffer) - (switch-to-buffer buffer)))) + (pop-to-buffer-same-window buffer nil 'Buffer-menu-mouse-select))) (defun Buffer-menu-this-window () "Select this line's buffer in this window." (interactive) - (switch-to-buffer (Buffer-menu-buffer t))) + (pop-to-buffer-same-window + (Buffer-menu-buffer t) nil 'Buffer-menu-this-window)) (defun Buffer-menu-other-window () "Select this line's buffer in other window, leaving buffer menu visible." (interactive) - (switch-to-buffer-other-window (Buffer-menu-buffer t))) + (pop-to-buffer-other-window + (Buffer-menu-buffer t) nil 'Buffer-menu-other-window)) +;; Name and doc-string of this function are confusing. (defun Buffer-menu-switch-other-window () "Make the other window select this line's buffer. The current window remains selected." (interactive) - (display-buffer-same-frame-other-window (Buffer-menu-buffer t))) + (display-buffer-same-frame-other-window + ;; Maybe we should insist on reusing another window here. + (Buffer-menu-buffer t) 'Buffer-menu-switch-other-window)) (defun Buffer-menu-2-window () "Select this line's buffer, with previous buffer in second window." @@ -586,8 +574,11 @@ The current window remains selected." (let ((buff (Buffer-menu-buffer t)) (menu (current-buffer))) (delete-other-windows) - (display-buffer-same-window (other-buffer)) - (pop-to-buffer-same-frame-other-window buff) + ;; It's very difficult to understand where we want to display what. + (display-buffer-same-window + (other-buffer) 'Buffer-menu-2-window-first) + (pop-to-buffer-same-frame-other-window + buff 'Buffer-menu-2-window-second) (bury-buffer menu))) (defun Buffer-menu-toggle-read-only () diff --git a/lisp/mail/reporter.el b/lisp/mail/reporter.el index 90fd09b12ee..8f091e7d3db 100644 --- a/lisp/mail/reporter.el +++ b/lisp/mail/reporter.el @@ -337,9 +337,7 @@ mail-sending package is used for editing and sending the message." (pop-to-buffer-other-window mailbuf) ;; Just in case the original buffer is not visible now, bring it ;; back somewhere. - (display-buffer - reporter-eval-buffer - '(same-frame-other-window (reuse-window 'other 'same 0))) + (display-buffer-same-frame-other-window reporter-eval-buffer) (goto-char (point-min)) (mail-position-on-field "to") (insert address) diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 1094f8b50ed..43375e84d39 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -2225,8 +2225,8 @@ attempts to find a file whose name is produced by (format FMT FILENAME)." (compilation-set-window ;; Apparently the window should be made on the same frame. If ;; it should be made in another window but the selected one - ;; replace same-frame by t. - (display-buffer (marker-buffer marker) 'same-frame) marker) + ;; call display-buffer-same-frame-other-window. + (display-buffer-same-frame (marker-buffer marker)) marker) (let* ((name (read-file-name (format "Find this %s in (default %s): " compilation-error filename) diff --git a/lisp/progmodes/inf-lisp.el b/lisp/progmodes/inf-lisp.el index 818ed8c9539..c04dce3c2d2 100644 --- a/lisp/progmodes/inf-lisp.el +++ b/lisp/progmodes/inf-lisp.el @@ -374,8 +374,9 @@ With argument, positions cursor at end of buffer." (interactive "P") (if (get-buffer-process inferior-lisp-buffer) (pop-to-buffer - ;; Trying to guess what was here previously. - inferior-lisp-buffer '(other-frame (reuse-buffer-window . t) same-window)) + ;; Try to reuse some window showing inferior-lisp-buffer on a + ;; visible frame, else stay on the selected frame. + inferior-lisp-buffer '((reuse-window nil same visible) same-frame)) (run-lisp inferior-lisp-program)) (when eob-p (push-mark) diff --git a/lisp/vc/ediff-ptch.el b/lisp/vc/ediff-ptch.el index 393bdcb673c..dda60ace88e 100644 --- a/lisp/vc/ediff-ptch.el +++ b/lisp/vc/ediff-ptch.el @@ -547,7 +547,7 @@ optional argument, then use it." (goto-char (point-min)) (or (ediff-get-visible-buffer-window patch-buf) (progn - (pop-to-buffer patch-buf 'other-window) + (pop-to-buffer-other-window patch-buf) (select-window (previous-window))))) (ediff-map-patch-buffer patch-buf) patch-buf)) @@ -712,7 +712,7 @@ optional argument, then use it." (message "Applying patch ... done") (message "") - (switch-to-buffer patch-diagnostics) + (pop-to-buffer-same-window patch-diagnostics) (sit-for 0) ; synchronize - let the user see diagnostics (or (and (ediff-patch-return-code-ok patch-return-code) @@ -751,7 +751,7 @@ you can still examine the changes via M-x ediff-files" (progn (select-window aux-wind) (goto-char (point-max)))) - (switch-to-buffer-other-window patch-diagnostics) + (pop-to-buffer-other-window patch-diagnostics) (error "Patch appears to have failed"))) ;; If black magic is involved, apply patch to a temp copy of the diff --git a/lisp/vc/pcvs-util.el b/lisp/vc/pcvs-util.el index bc527350879..78089e3e904 100644 --- a/lisp/vc/pcvs-util.el +++ b/lisp/vc/pcvs-util.el @@ -86,23 +86,16 @@ the other elements. The ordering among elements is maintained." BUF is assumed to be a temporary buffer used from the buffer MAINBUF." (interactive (list (current-buffer))) (save-current-buffer - (let ((win (if (eq buf (window-buffer (selected-window))) (selected-window) + (let ((win (if (eq buf (window-buffer)) + (selected-window) (get-buffer-window buf t)))) (when win (if (window-dedicated-p win) (condition-case () (delete-window win) (error (iconify-frame (window-frame win)))) -;;; (if (and mainbuf (get-buffer-window mainbuf)) -;;; ;; FIXME: if the buffer popped into a pre-existing window, -;;; ;; we don't want to delete that window. -;;; t ;;(delete-window win) -;;; ) - ))) - (with-current-buffer buf - (bury-buffer (unless (and (eq buf (window-buffer (selected-window))) - (not (window-dedicated-p (selected-window)))) - buf))) + (quit-restore-window win)))) + (when mainbuf (let ((mainwin (or (get-buffer-window mainbuf) (get-buffer-window mainbuf 'visible)))) diff --git a/lisp/vc/pcvs.el b/lisp/vc/pcvs.el index c13565f500c..d2e1e024b4d 100644 --- a/lisp/vc/pcvs.el +++ b/lisp/vc/pcvs.el @@ -380,7 +380,8 @@ from the current buffer." ;; Strangely, if no window is created, `display-buffer' ends up ;; doing a `switch-to-buffer' which does a `set-buffer', hence ;; the need for `save-excursion'. - (unless nosetup (save-excursion (display-buffer buf))) + (unless nosetup (save-excursion + (display-buffer-other-window buf))) ;; FIXME: this doesn't do the right thing if the user later on ;; does a `find-file-other-window' and `scroll-other-window' (set (make-local-variable 'other-window-scroll-buffer) buf)) @@ -1709,7 +1710,7 @@ Signal an error if there is no backup file." ;; switch back to the *cvs* buffer (when (and cvs-buf (buffer-live-p cvs-buf) (not (get-buffer-window cvs-buf t))) - (ignore-errors (switch-to-buffer cvs-buf)))) + (ignore-errors (pop-to-buffer-same-window cvs-buf)))) (defun cvs-ediff-diff (b1 b2) (let ((ediff-after-quit-destination-buffer (current-buffer)) @@ -2018,7 +2019,7 @@ to hear about anymore." (string-to-number (match-string 1)) 1))) - +;; Someone should explain what these arguments are. (defun cvs-mode-find-file (e &optional other view) "Select a buffer containing the file. With a prefix, opens the buffer in an OTHER window." @@ -2040,7 +2041,7 @@ With a prefix, opens the buffer in an OTHER window." (cvs-expand-dir-name (cvs-fileinfo->dir fi))) (cond ((eq other 'dont-select) (display-buffer (find-file-noselect default-directory))) - (other (dired-other-window default-directory)) + (other (display-buffer-other-window default-directory)) (t (dired default-directory))) (set-buffer cvs-buf) (setq default-directory odir)) @@ -2048,9 +2049,12 @@ With a prefix, opens the buffer in an OTHER window." (find-file-noselect (cvs-fileinfo->full-name fi))))) (funcall (cond ((eq other 'dont-select) 'display-buffer) (other - (if view 'view-buffer-other-window - 'switch-to-buffer-other-window)) - (t (if view 'view-buffer 'switch-to-buffer))) + (if view + 'view-buffer-other-window + 'pop-to-buffer-other-window)) + (t (if view + 'view-buffer + 'pop-to-buffer-same-window))) buf) (when (and cvs-find-file-and-jump (cvs-applicable-p fi 'diff-base)) (save-restriction -- 2.39.5