Function: window-normalize-buffer-to-switch-to
window-normalize-buffer-to-switch-to is a byte-compiled function
defined in window.el.gz.
Signature
(window-normalize-buffer-to-switch-to BUFFER-OR-NAME)
Documentation
Normalize BUFFER-OR-NAME argument of buffer switching functions.
If BUFFER-OR-NAME is nil, return the buffer returned by
other-buffer. Else, if a buffer specified by BUFFER-OR-NAME
exists, return that buffer. If no such buffer exists, create a
buffer with the name BUFFER-OR-NAME and return that buffer.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun window-normalize-buffer-to-switch-to (buffer-or-name)
"Normalize BUFFER-OR-NAME argument of buffer switching functions.
If BUFFER-OR-NAME is nil, return the buffer returned by
`other-buffer'. Else, if a buffer specified by BUFFER-OR-NAME
exists, return that buffer. If no such buffer exists, create a
buffer with the name BUFFER-OR-NAME and return that buffer."
(pcase buffer-or-name
('nil (other-buffer))
("*scratch*" (get-scratch-buffer-create))
(_ (or (get-buffer buffer-or-name)
(let ((buffer (get-buffer-create buffer-or-name)))
(set-buffer-major-mode buffer)
buffer)))))