* 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
+2011-09-22 Chong Yidong <cyd@stupidchicken.com>
+
+ * 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 <rms@gnu.org>
* textmodes/paragraphs.el (forward-sentence): When setting PAR-BEG,
(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.
(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)
(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)
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
(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
(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."
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
"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)
;; 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))
(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.