From 72258fe58401a16ab2ff671601c6d6068eb8b799 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Thu, 22 Sep 2011 12:15:52 -0400 Subject: [PATCH] Reintroduce pop-to-buffer-same-window; use it for previous users of same-window-*. * window.el (pop-to-buffer-same-window): New (reinstated) fun. * cmuscheme.el (run-scheme, switch-to-scheme): * cus-edit.el (customize-group, custom-buffer-create) (customize-browse): * info.el (info): * shell.el (shell): * mail/sendmail.el (mail): * progmodes/inf-lisp.el (inferior-lisp): Use it. Fixes: debbugs:9532 --- lisp/ChangeLog | 12 ++++++++++++ lisp/cmuscheme.el | 4 ++-- lisp/cus-edit.el | 14 +++++++++----- lisp/info.el | 3 ++- lisp/mail/sendmail.el | 4 ++-- lisp/progmodes/inf-lisp.el | 2 +- lisp/shell.el | 2 +- lisp/window.el | 22 ++++++++++++++++++++++ 8 files changed, 51 insertions(+), 12 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5278fb3a6b..8017e71120 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2011-09-22 Chong Yidong + + * window.el (pop-to-buffer-same-window): New (reinstated) fun. + + * cmuscheme.el (run-scheme, switch-to-scheme): + * cus-edit.el (customize-group, custom-buffer-create) + (customize-browse): + * info.el (info): + * shell.el (shell): + * mail/sendmail.el (mail): + * progmodes/inf-lisp.el (inferior-lisp): Use it (Bug#9532). + 2011-09-22 Richard Stallman * textmodes/paragraphs.el (forward-sentence): When setting PAR-BEG, diff --git a/lisp/cmuscheme.el b/lisp/cmuscheme.el index 6eb2aa7613..7c1351eefd 100644 --- a/lisp/cmuscheme.el +++ b/lisp/cmuscheme.el @@ -246,7 +246,7 @@ is run). (inferior-scheme-mode))) (setq scheme-program-name cmd) (setq scheme-buffer "*scheme*") - (switch-to-buffer "*scheme*")) + (pop-to-buffer-same-window "*scheme*")) (defun scheme-start-file (prog) "Return the name of the start file corresponding to PROG. @@ -371,7 +371,7 @@ With argument, position cursor at end of buffer." (interactive "P") (if (or (and scheme-buffer (get-buffer scheme-buffer)) (scheme-interactively-start-process)) - (switch-to-buffer scheme-buffer) + (pop-to-buffer-same-window scheme-buffer) (error "No current process buffer. See variable `scheme-buffer'")) (when eob-p (push-mark) diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 620ecdba40..9ba8b27c69 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -1111,15 +1111,19 @@ If OTHER-WINDOW is non-nil, display in another window." (setq group (intern group)))) (let ((name (format "*Customize Group: %s*" (custom-unlispify-tag-name group)))) - (if (get-buffer name) - (switch-to-buffer name other-window) + (cond + ((null (get-buffer name)) (funcall (if other-window 'custom-buffer-create-other-window 'custom-buffer-create) (list (list group 'custom-group)) name (concat " for group " - (custom-unlispify-tag-name group)))))) + (custom-unlispify-tag-name group)))) + (other-window + (switch-to-buffer-other-window name)) + (t + (pop-to-buffer-same-window name))))) ;;;###autoload (defun customize-group-other-window (&optional group) @@ -1533,7 +1537,7 @@ Optional NAME is the name of the buffer. OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where SYMBOL is a customization option, and WIDGET is a widget for editing that option." - (switch-to-buffer (custom-get-fresh-buffer (or name "*Customization*"))) + (pop-to-buffer-same-window (custom-get-fresh-buffer (or name "*Customization*"))) (custom-buffer-create-internal options description)) ;;;###autoload @@ -1721,7 +1725,7 @@ Otherwise use brackets." (unless group (setq group 'emacs)) (let ((name "*Customize Browser*")) - (switch-to-buffer (custom-get-fresh-buffer name))) + (pop-to-buffer-same-window (custom-get-fresh-buffer name))) (Custom-mode) (widget-insert (format "\ %s buttons; type RET or click mouse-1 diff --git a/lisp/info.el b/lisp/info.el index ea23cf3556..4ccbeba2a4 100644 --- a/lisp/info.el +++ b/lisp/info.el @@ -649,7 +649,8 @@ See a list of available Info commands in `Info-mode'." (read-file-name "Info file name: " nil nil t)) (if (numberp current-prefix-arg) (format "*info*<%s>" current-prefix-arg)))) - (info-setup file-or-node (switch-to-buffer (or buffer "*info*")))) + (info-setup file-or-node + (pop-to-buffer-same-window (or buffer "*info*")))) (defun info-setup (file-or-node buffer) "Display Info node FILE-OR-NODE in BUFFER." diff --git a/lisp/mail/sendmail.el b/lisp/mail/sendmail.el index 6bcf65945b..dedb571993 100644 --- a/lisp/mail/sendmail.el +++ b/lisp/mail/sendmail.el @@ -1785,11 +1785,11 @@ The seventh argument ACTIONS is a list of actions to take This is how Rmail arranges to mark messages `answered'." (interactive "P") (if (eq noerase 'new) - (switch-to-buffer (generate-new-buffer "*mail*")) + (pop-to-buffer-same-window (generate-new-buffer "*mail*")) (and noerase (not (get-buffer "*mail*")) (setq noerase nil)) - (switch-to-buffer "*mail*")) + (pop-to-buffer-same-window "*mail*")) ;; Avoid danger that the auto-save file can't be written. (let ((dir (expand-file-name diff --git a/lisp/progmodes/inf-lisp.el b/lisp/progmodes/inf-lisp.el index 0765f74a1c..636766b36e 100644 --- a/lisp/progmodes/inf-lisp.el +++ b/lisp/progmodes/inf-lisp.el @@ -297,7 +297,7 @@ of `inferior-lisp-program'). Runs the hooks from "inferior-lisp" (car cmdlist) nil (cdr cmdlist))) (inferior-lisp-mode))) (setq inferior-lisp-buffer "*inferior-lisp*") - (switch-to-buffer "*inferior-lisp*")) + (pop-to-buffer-same-window "*inferior-lisp*")) ;;;###autoload (defalias 'run-lisp 'inferior-lisp) diff --git a/lisp/shell.el b/lisp/shell.el index 8c5781f933..96c0d27372 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -652,7 +652,7 @@ Otherwise, one argument `-i' is passed to the shell. ;; The buffer's window must be correctly set when we call comint (so ;; that comint sets the COLUMNS env var properly). - (switch-to-buffer buffer) + (pop-to-buffer-same-window buffer) (unless (comint-check-proc buffer) (let* ((prog (or explicit-shell-file-name (getenv "ESHELL") shell-file-name)) diff --git a/lisp/window.el b/lisp/window.el index 843115d2e5..fb74c43924 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4861,6 +4861,28 @@ at the front of the list of recently selected ones." (select-frame-set-input-focus frame norecord)) buffer)) +(defun pop-to-buffer-same-window (buffer &optional norecord) + "Select buffer BUFFER in some window, preferably the same one. +This function behaves much like `switch-to-buffer', except it +displays with `special-display-function' if BUFFER has a match in +`special-display-buffer-names' or `special-display-regexps'. + +Unlike `pop-to-buffer', this function prefers using the selected +window over popping up a new window or frame. + +BUFFER may be a buffer, a string (a buffer name), or nil. If it +is a string not naming an existent buffer, create a buffer with +that name. If BUFFER is nil, choose some other buffer. Return +the buffer. + +NORECORD, if non-nil means do not put this buffer at the front of +the list of recently selected ones." + (pop-to-buffer buffer + '((display-buffer--special + display-buffer-same-window) + (inhibit-same-window . nil)) + norecord)) + (defun read-buffer-to-switch (prompt) "Read the name of a buffer to switch to, prompting with PROMPT. Return the neame of the buffer as a string. -- 2.20.1