Ignore fixed-sizeness when getting a window's state.
[bpt/emacs.git] / lisp / window.el
index 2885c3a..8e2c945 100644 (file)
@@ -1,6 +1,6 @@
 ;;; window.el --- GNU Emacs window commands aside from those written in C
 
-;; Copyright (C) 1985, 1989, 1992-1994, 2000-2011
+;; Copyright (C) 1985, 1989, 1992-1994, 2000-2012
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -170,7 +170,7 @@ Applications should never rebind this variable.  To resize a
 window to a height less than the one specified here, an
 application should instead call `window-resize' with a non-nil
 IGNORE argument.  In order to have `split-window' make a window
-shorter, explictly specify the SIZE argument of that function."
+shorter, explicitly specify the SIZE argument of that function."
   :type 'integer
   :version "24.1"
   :group 'windows)
@@ -190,7 +190,7 @@ Applications should never rebind this variable.  To resize a
 window to a width less than the one specified here, an
 application should instead call `window-resize' with a non-nil
 IGNORE argument.  In order to have `split-window' make a window
-narrower, explictly specify the SIZE argument of that function."
+narrower, explicitly specify the SIZE argument of that function."
   :type 'integer
   :version "24.1"
   :group 'windows)
@@ -296,7 +296,7 @@ is unpredictable."
   "Return first window on FRAME with PARAMETER non-nil.
 FRAME defaults to the selected frame.  Optional argument VALUE
 non-nil means only return a window whose window-parameter value
-for PARAMETER equals VALUE \(comparison is done with `equal').
+for PARAMETER equals VALUE (comparison is done with `equal').
 Optional argument ANY non-nil means consider internal windows
 too."
   (let (this-value windows)
@@ -312,7 +312,7 @@ too."
 (defun window-atom-root (&optional window)
   "Return root of atomic window WINDOW is a part of.
 WINDOW can be any window and defaults to the selected one.
-Return nil if WINDOW is not part of a atomic window."
+Return nil if WINDOW is not part of an atomic window."
   (setq window (window-normalize-window window))
   (let (root)
     (while (and window (window-parameter window 'window-atom))
@@ -380,7 +380,7 @@ Otherwise, top and bottom side windows are full width."
 (defcustom window-sides-slots '(nil nil nil nil)
   "Maximum number of side window slots.
 The value is a list of four elements specifying the number of
-side window slots on \(in this order) the left, top, right and
+side window slots on (in this order) the left, top, right and
 bottom side of each frame.  If an element is a number, this means
 to display at most that many side windows on the corresponding
 side.  If an element is nil, this means there's no bound on the
@@ -504,7 +504,7 @@ If the value is `width', then only the window's width is fixed.
 Any other non-nil value fixes both the width and the height.
 
 Emacs won't change the size of any window displaying that buffer,
-unless it has no other choice \(like when deleting a neighboring
+unless it has no other choice (like when deleting a neighboring
 window).")
 (make-variable-buffer-local 'window-size-fixed)
 
@@ -749,7 +749,7 @@ Optional argument NOUP non-nil means don't go up in the window
 tree but try to enlarge windows within WINDOW's combination only.
 
 Optional argument NODOWN non-nil means don't check whether WINDOW
-itself \(and its child windows) can be shrunk; check only whether
+itself (and its child windows) can be shrunk; check only whether
 at least one other window can be enlarged appropriately."
   (setq window (window-normalize-window window))
   (let ((size (window-total-size window horizontal))
@@ -831,7 +831,7 @@ tree but try to obtain the entire space from windows within
 WINDOW's combination.
 
 Optional argument NODOWN non-nil means do not check whether
-WINDOW itself \(and its child windows) can be enlarged; check
+WINDOW itself (and its child windows) can be enlarged; check
 only whether other windows can be shrunk appropriately."
   (setq window (window-normalize-window window))
   (if (and (not (window--size-ignore window ignore))
@@ -1211,7 +1211,7 @@ More precisely, cycle through all windows calling the function
 PREDICATE on each one of them with the window as its sole
 argument.  Return the first window for which PREDICATE returns
 non-nil.  Windows are scanned starting with the window following
-the selcted window.  If no window satisfies PREDICATE, return
+the selected window.  If no window satisfies PREDICATE, return
 DEFAULT.
 
 MINIBUF t means include the minibuffer window even if the
@@ -1418,7 +1418,7 @@ windows."
 ;; window and is currently used, for example, by ispell.el.
 (defun window--resize-mini-window (window delta)
   "Resize minibuffer window WINDOW by DELTA lines.
-If WINDOW cannot be resized by DELTA lines make it as large \(or
+If WINDOW cannot be resized by DELTA lines make it as large (or
 as small) as possible but don't signal an error."
   (when (window-minibuffer-p window)
     (let* ((frame (window-frame window))
@@ -1513,12 +1513,12 @@ instead."
   "Recursively set new normal height of child windows of window PARENT.
 HORIZONTAL non-nil means set the new normal width of these
 windows.  WINDOW specifies a child window of PARENT that has been
-resized by THIS-DELTA lines \(columns).
+resized by THIS-DELTA lines (columns).
 
 Optional argument TRAIL either 'before or 'after means set values
 for windows before or after WINDOW only.  Optional argument
-OTHER-DELTA a number specifies that this many lines \(columns)
-have been obtained from \(or returned to) an ancestor window of
+OTHER-DELTA a number specifies that this many lines (columns)
+have been obtained from (or returned to) an ancestor window of
 PARENT in order to resize WINDOW."
   (let* ((delta-normal
          (if (and (= (- this-delta) (window-total-size window horizontal))
@@ -2190,7 +2190,7 @@ for a horizontal split, and t for a vertical split.  EDGES gives
 the combined size and position of the child windows in the split,
 and the rest of the elements are the child windows in the split.
 Each of the child windows may again be a window or a list
-representing a window split, and so on.  EDGES is a list \(LEFT
+representing a window split, and so on.  EDGES is a list (LEFT
 TOP RIGHT BOTTOM) as returned by `window-edges'."
   (setq frame (window-normalize-frame frame))
   (window--subtree (frame-root-window frame) t))
@@ -2204,9 +2204,9 @@ skip -COUNT windows backwards.  COUNT zero means do not skip any
 window, so select the selected window.  In an interactive call,
 COUNT is the numeric prefix argument.  Return nil.
 
-If the `other-window' parameter of WINDOW is a function and
-`ignore-window-parameters' is nil, call that function with the
-arguments COUNT and ALL-FRAMES.
+If the `other-window' parameter of the selected window is a
+function and `ignore-window-parameters' is nil, call that
+function with the arguments COUNT and ALL-FRAMES.
 
 This function does not select a window whose `no-other-window'
 window parameter is non-nil.
@@ -2430,7 +2430,7 @@ the value returned by that function.
 Otherwise, if WINDOW is part of an atomic window, call this
 function with the root of the atomic window as its argument.  If
 WINDOW is a non-side window, make WINDOW the only non-side window
-on the frame.  Side windows are not deleted. If WINDOW is a side
+on the frame.  Side windows are not deleted.  If WINDOW is a side
 window signal an error."
   (interactive)
   (setq window (window-normalize-window window))
@@ -2455,7 +2455,7 @@ window signal an error."
        (throw 'done (delete-other-windows atom-root)))
        ((eq window-side 'none)
        ;; Set side-main to the major non-side window.
-       (setq side-main (window-with-parameter 'window-side 'none nil t)))
+       (setq side-main (window-with-parameter 'window-side 'none frame t)))
        ((memq window-side window-sides)
        (error "Cannot make side window the only window")))
       ;; If WINDOW is the main non-side window, do nothing.
@@ -2938,9 +2938,9 @@ With prefix argument KILL non-nil, kill the buffer instead of
 burying it.
 
 According to information stored in WINDOW's `quit-restore' window
-parameter either \(1) delete WINDOW and its frame, \(2) delete
-WINDOW, \(3) restore the buffer previously displayed in WINDOW,
-or \(4) make WINDOW display some other buffer than the present
+parameter either (1) delete WINDOW and its frame, (2) delete
+WINDOW, (3) restore the buffer previously displayed in WINDOW,
+or (4) make WINDOW display some other buffer than the present
 one.  If non-nil, reset `quit-restore' parameter to nil."
   (interactive "P")
   (setq window (window-normalize-window window t))
@@ -3047,14 +3047,14 @@ WINDOW's size.  Interactively, SIZE is the prefix argument.
 Optional third argument SIDE nil (or `below') specifies that the
 new window shall be located below WINDOW.  SIDE `above' means the
 new window shall be located above WINDOW.  In both cases SIZE
-specifies the new number of lines for WINDOW \(or the new window
+specifies the new number of lines for WINDOW (or the new window
 if SIZE is negative) including space reserved for the mode and/or
 header line.
 
 SIDE t (or `right') specifies that the new window shall be
 located on the right side of WINDOW.  SIDE `left' means the new
 window shall be located on the left of WINDOW.  In both cases
-SIZE specifies the new number of columns for WINDOW \(or the new
+SIZE specifies the new number of columns for WINDOW (or the new
 window provided SIZE is negative) including space reserved for
 fringes and the scrollbar or a divider column.  Any other non-nil
 value for SIDE is currently handled like t (or `right').
@@ -3568,10 +3568,7 @@ specific buffers."
     ))
 
 ;;; Window states, how to get them and how to put them in a window.
-(defvar window-state-ignored-parameters '(quit-restore)
-  "List of window parameters ignored by `window-state-get'.")
-
-(defun window--state-get-1 (window &optional markers)
+(defun window--state-get-1 (window &optional writable)
   "Helper function for `window-state-get'."
   (let* ((type
          (cond
@@ -3588,58 +3585,62 @@ specific buffers."
             (normal-height . ,(window-normal-size window))
             (normal-width . ,(window-normal-size window t))
             (combination-limit . ,(window-combination-limit window))
-            ,@(let (list)
-                (dolist (parameter (window-parameters window))
-                  (unless (memq (car parameter)
-                                window-state-ignored-parameters)
-                    (setq list (cons parameter list))))
-                (unless (window-parameter window 'clone-of)
-                  ;; Make a clone-of parameter.
-                  (setq list (cons (cons 'clone-of window) list)))
+            ,@(let ((parameters (window-parameters window))
+                   list)
+               ;; Make copies of those window parameters whose
+               ;; persistence property is `writable' if WRITABLE is
+               ;; non-nil and non-nil if WRITABLE is nil.
+                (dolist (par parameters)
+                 (let ((pers (cdr (assq (car par)
+                                        window-persistent-parameters))))
+                   (when (and pers (or (not writable) (eq pers 'writable)))
+                     (setq list (cons (cons (car par) (cdr par)) list)))))
+               ;; Add `clone-of' parameter if necessary.
+               (let ((pers (cdr (assq 'clone-of
+                                      window-persistent-parameters))))
+                 (when (and pers (or (not writable) (eq pers 'writable))
+                            (not (assq 'clone-of list)))
+                   (setq list (cons (cons 'clone-of window) list))))
                 (when list
                   `((parameters . ,list))))
             ,@(when buffer
-                ;; All buffer related things go in here - make the buffer
-                ;; current when retrieving `point' and `mark'.
-                (with-current-buffer (window-buffer window)
-                  (let ((point (window-point-1 window))
-                        (start (window-start window))
-                        (mark (mark)))
-                    `((buffer
-                       ,(buffer-name buffer)
-                       (selected . ,selected)
-                       ,@(when window-size-fixed
-                           `((size-fixed . ,window-size-fixed)))
-                       (hscroll . ,(window-hscroll window))
-                       (fringes . ,(window-fringes window))
-                       (margins . ,(window-margins window))
-                       (scroll-bars . ,(window-scroll-bars window))
-                       (vscroll . ,(window-vscroll window))
-                       (dedicated . ,(window-dedicated-p window))
-                       (point . ,(if markers (copy-marker point) point))
-                       (start . ,(if markers (copy-marker start) start))
-                       ,@(when mark
-                           `((mark . ,(if markers
-                                          (copy-marker mark) mark)))))))))))
+                ;; All buffer related things go in here.
+               (let ((point (window-point-1 window))
+                     (start (window-start window)))
+                 `((buffer
+                    ,(buffer-name buffer)
+                    (selected . ,selected)
+                    (hscroll . ,(window-hscroll window))
+                    (fringes . ,(window-fringes window))
+                    (margins . ,(window-margins window))
+                    (scroll-bars . ,(window-scroll-bars window))
+                    (vscroll . ,(window-vscroll window))
+                    (dedicated . ,(window-dedicated-p window))
+                    (point . ,(if writable point (copy-marker point)))
+                    (start . ,(if writable start (copy-marker start)))))))))
         (tail
          (when (memq type '(vc hc))
            (let (list)
              (setq window (window-child window))
              (while window
-               (setq list (cons (window--state-get-1 window markers) list))
+               (setq list (cons (window--state-get-1 window writable) list))
                (setq window (window-right window)))
              (nreverse list)))))
     (append head tail)))
 
-(defun window-state-get (&optional window markers)
+(defun window-state-get (&optional window writable)
   "Return state of WINDOW as a Lisp object.
 WINDOW can be any window and defaults to the root window of the
 selected frame.
 
-Optional argument MARKERS non-nil means use markers for sampling
-positions like `window-point' or `window-start'.  MARKERS should
-be non-nil only if the value is used for putting the state back
-in the same session (note that markers slow down processing).
+Optional argument WRITABLE non-nil means do not use markers for
+sampling `window-point' and `window-start'.  Together, WRITABLE
+and the variable `window-persistent-parameters' specify which
+window parameters are saved by this function.  WRITABLE should be
+non-nil when the return value shall be written to a file and read
+back in another session.  Otherwise, an application may run into
+an `invalid-read-syntax' error while attempting to read back the
+value from file.
 
 The return value can be used as argument for `window-state-put'
 to put the state recorded here into an arbitrary window.  The
@@ -3661,11 +3662,8 @@ value can be also stored on disk and read back in a new session."
      (min-height-ignore . ,(window-min-size window nil t))
      (min-width-ignore  . ,(window-min-size window t t))
      (min-height-safe   . ,(window-min-size window nil 'safe))
-     (min-width-safe    . ,(window-min-size window t 'safe))
-     ;; These are probably not needed.
-     ,@(when (window-size-fixed-p window) `((fixed-height . t)))
-     ,@(when (window-size-fixed-p window t) `((fixed-width . t))))
-   (window--state-get-1 window markers)))
+     (min-width-safe    . ,(window-min-size window t 'safe)))
+   (window--state-get-1 window writable)))
 
 (defvar window-state-put-list nil
   "Helper variable for `window-state-put'.")
@@ -3713,7 +3711,7 @@ value can be also stored on disk and read back in a new session."
              (if (window-sizable-p window (- size) horizontal 'safe)
                  (let* ((window-combination-limit
                          (assq 'combination-limit item)))
-                   ;; We must inherit the combiantion limit, otherwise
+                   ;; We must inherit the combination limit, otherwise
                    ;; we might mess up handling of atomic and side
                    ;; window.
                    (setq new (split-window window size horizontal)))
@@ -3744,7 +3742,10 @@ value can be also stored on disk and read back in a new session."
          (state (cdr (assq 'buffer item))))
       (when combination-limit
        (set-window-combination-limit window combination-limit))
-      ;; Process parameters.
+      ;; Reset window's parameters and assign saved ones (we might want
+      ;; a `remove-window-parameters' function here).
+      (dolist (parameter (window-parameters window))
+       (set-window-parameter window (car parameter) nil))
       (when parameters
        (dolist (parameter parameters)
          (set-window-parameter window (car parameter) (cdr parameter))))
@@ -3797,11 +3798,7 @@ value can be also stored on disk and read back in a new session."
          ;; have been created and sized).
          (ignore-errors
            (set-window-start window (cdr (assq 'start state)))
-           (set-window-point window (cdr (assq 'point state)))
-           ;; I'm not sure whether we should set the mark here, but maybe
-           ;; it can be used.
-           (let ((mark (cdr (assq 'mark state))))
-             (when mark (set-mark mark))))
+           (set-window-point window (cdr (assq 'point state))))
          ;; Select window if it's the selected one.
          (when (cdr (assq 'selected state))
            (select-window window)))))))
@@ -3870,10 +3867,10 @@ windows can get as small as `window-safe-min-height' and
 (defun display-buffer-record-window (type window buffer)
   "Record information for window used by `display-buffer'.
 TYPE specifies the type of the calling operation and must be one
-of the symbols 'reuse \(when WINDOW existed already and was
-reused for displaying BUFFER), 'window \(when WINDOW was created
-on an already existing frame), or 'frame \(when WINDOW was
-created on a new frame). WINDOW is the window used for or created
+of the symbols 'reuse (when WINDOW existed already and was
+reused for displaying BUFFER), 'window (when WINDOW was created
+on an already existing frame), or 'frame (when WINDOW was
+created on a new frame).  WINDOW is the window used for or created
 by the `display-buffer' routines.  BUFFER is the buffer that
 shall be displayed.
 
@@ -3968,7 +3965,7 @@ the buffer as first, and nil as second argument.
 
 Alternatively, an element of this list can be specified as
 \(BUFFER-NAME FRAME-PARAMETERS), where BUFFER-NAME is a buffer
-name and FRAME-PARAMETERS an alist of \(PARAMETER . VALUE) pairs.
+name and FRAME-PARAMETERS an alist of (PARAMETER . VALUE) pairs.
 `special-display-popup-frame' will interpret such pairs as frame
 parameters when it creates a special frame, overriding the
 corresponding values from `special-display-frame-alist'.
@@ -4044,7 +4041,7 @@ name matches REGEXP, overriding the corresponding values from
 
 As a special case, if FRAME-PARAMETERS contains (same-window . t)
 `special-display-popup-frame' displays buffers matching REGEXP in
-the selected window.  \(same-frame . t) in FRAME-PARAMETERS means
+the selected window.  (same-frame . t) in FRAME-PARAMETERS means
 to display such buffers in a window on the selected frame.
 
 If `special-display-function' specifies some other function than
@@ -4139,8 +4136,8 @@ Optional argument ARGS is a list specifying additional
 information.
 
 If ARGS is an alist, use it as a list of frame parameters.  If
-these parameters contain \(same-window . t), display BUFFER in
-the selected window.  If they contain \(same-frame . t), display
+these parameters contain (same-window . t), display BUFFER in
+the selected window.  If they contain (same-frame . t), display
 BUFFER in a window of the selected frame.
 
 If ARGS is a list whose car is a symbol, use (car ARGS) as a
@@ -4234,7 +4231,7 @@ See also `same-window-buffer-names'."
   "Return non-nil if a buffer named BUFFER-NAME would be shown in the \"same\" window.
 This function returns non-nil if `display-buffer' or
 `pop-to-buffer' would show a buffer named BUFFER-NAME in the
-selected rather than \(as usual\) some other window.  See
+selected rather than (as usual) some other window.  See
 `same-window-buffer-names' and `same-window-regexps'."
   (cond
    ((not (stringp buffer-name)))
@@ -4396,11 +4393,11 @@ the largest or least recently used window.  To change the default
 customize the option `split-window-preferred-function'.
 
 You can enforce this function to not split WINDOW horizontally,
-by setting \(or binding) the variable `split-width-threshold' to
+by setting (or binding) the variable `split-width-threshold' to
 nil.  If, in addition, you set `split-height-threshold' to zero,
 chances increase that this function does split WINDOW vertically.
 
-In order to not split WINDOW vertically, set \(or bind) the
+In order to not split WINDOW vertically, set (or bind) the
 variable `split-height-threshold' to nil.  Additionally, you can
 set `split-width-threshold' to zero to make a horizontal split
 more likely to occur.
@@ -4515,24 +4512,17 @@ Return WINDOW."
       (set-window-dedicated-p window dedicated))
     (window--display-buffer-1 window)))
 
+;; FIXME: Not implemented.
+;; FIXME: By the way, there could be more levels of dedication:
+;; - `barely' dedicated doesn't prevent reuse of the window, only records that
+;;   the window hasn't been used for something else yet.
+;; - `softly' dedicated only allows reuse when asked explicitly.
+;; - `strongly' never allows reuse.
 (defvar display-buffer-mark-dedicated nil
   "If non-nil, `display-buffer' marks the windows it creates as dedicated.
 The actual non-nil value of this variable will be copied to the
 `window-dedicated-p' flag.")
 
-(defun window-normalize-buffer-to-display (buffer-or-name)
-  "Normalize BUFFER-OR-NAME argument for buffer display functions.
-If BUFFER-OR-NAME is nil, return the curent 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."
-  (if buffer-or-name
-      (or (get-buffer buffer-or-name)
-         (let ((buffer (get-buffer-create buffer-or-name)))
-           (set-buffer-major-mode buffer)
-           buffer))
-    (current-buffer)))
-
 (defconst display-buffer--action-function-custom-type
   '(choice :tag "Function"
           (const :tag "--" ignore) ; default for insertion
@@ -4559,7 +4549,7 @@ BUFFER-OR-NAME and return that buffer."
 (defvar display-buffer-overriding-action '(nil . nil)
   "Overriding action to perform to display a buffer.
 It should be a cons cell (FUNCTION . ALIST), where FUNCTION is a
-function or a list of functions.  Each function should accept 2
+function or a list of functions.  Each function should accept two
 arguments: a buffer to display and an alist similar to ALIST.
 See `display-buffer' for details.")
 (put 'display-buffer-overriding-action 'risky-local-variable t)
@@ -4573,7 +4563,7 @@ This is a list of elements (CONDITION . ACTION), where:
 
  ACTION is a cons cell (FUNCTION . ALIST), where FUNCTION is a
   function or a list of functions.  Each such function should
-  accept 2 arguments: a buffer to display and an alist of the
+  accept two arguments: a buffer to display and an alist of the
   same form as ALIST.  See `display-buffer' for details."
   :type `(alist :key-type
                (choice :tag "Condition"
@@ -4587,7 +4577,7 @@ This is a list of elements (CONDITION . ACTION), where:
 (defcustom display-buffer-base-action '(nil . nil)
   "User-specified default action for `display-buffer'.
 It should be a cons cell (FUNCTION . ALIST), where FUNCTION is a
-function or a list of functions.  Each function should accept 2
+function or a list of functions.  Each function should accept two
 arguments: a buffer to display and an alist similar to ALIST.
 See `display-buffer' for details."
   :type display-buffer--action-custom-type
@@ -4634,7 +4624,7 @@ specified, e.g. by the user options `display-buffer-alist' or
   "A `display-buffer' action for displaying in another frame.")
 (put 'display-buffer--other-frame-action 'risky-local-variable t)
 
-(defun display-buffer (&optional buffer-or-name action frame)
+(defun display-buffer (buffer-or-name &optional action frame)
   "Display BUFFER-OR-NAME in some window, without selecting it.
 BUFFER-OR-NAME must be a buffer or the name of an existing
 buffer.  Return the window chosen for displaying BUFFER-OR-NAME,
@@ -4642,8 +4632,8 @@ or nil if no such window is found.
 
 Optional argument ACTION should have the form (FUNCTION . ALIST).
 FUNCTION is either a function or a list of functions.  Each such
-function is called with 2 arguments: the buffer to display and an
-alist.  It should either display the buffer and return the
+function is called with two arguments: the buffer to display and
+an alist.  It should either display the buffer and return the
 window, or return nil if unable to display the buffer.
 
 The `display-buffer' function builds a function list and an alist
@@ -4682,7 +4672,9 @@ search for a window that is already displaying the buffer.  See
 `display-buffer-reuse-window'."
   (interactive (list (read-buffer "Display buffer: " (other-buffer))
                     (if current-prefix-arg t)))
-  (let ((buffer (window-normalize-buffer-to-display buffer-or-name))
+  (let ((buffer (if (bufferp buffer-or-name)
+                   buffer-or-name
+                 (get-buffer buffer-or-name)))
        ;; Handle the old form of the first argument.
        (inhibit-same-window (and action (not (listp action)))))
     (unless (listp action) (setq action nil))
@@ -4786,9 +4778,10 @@ terminal if either of those variables is non-nil."
       (window--display-buffer-1 window))))
 
 (defun display-buffer--special-action (buffer)
-  "Try to display BUFFER using `special-display-function'.
-Call `special-display-p' on BUFFER's name, and if that returns
-non-nil, call `special-display-function' on BUFFER."
+  "Return special display action for BUFFER, if any.
+If `special-display-p' returns non-nil for BUFFER, return an
+appropriate display action involving `special-display-function'.
+See `display-buffer' for the format of display actions."
   (and special-display-function
        ;; `special-display-p' returns either t or a list of frame
        ;; parameters to pass to `special-display-function'.
@@ -4818,7 +4811,7 @@ return the window used; otherwise return nil."
   "Display BUFFER by popping up a new window.
 The new window is created on the selected frame, or in
 `last-nonminibuffer-frame' if no windows can be created there.
-If sucessful, return the new window; otherwise return nil."
+If successful, return the new window; otherwise return nil."
   (let ((frame (or (window--frame-usable-p (selected-frame))
                   (window--frame-usable-p (last-nonminibuffer-frame))))
        window)
@@ -4944,10 +4937,7 @@ 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-same-window
-                  (inhibit-same-window . nil))
-                norecord))
+  (pop-to-buffer buffer display-buffer--same-window-action norecord))
 
 (defun read-buffer-to-switch (prompt)
   "Read the name of a buffer to switch to, prompting with PROMPT.
@@ -4992,7 +4982,7 @@ minibuffer.  The variable `confirm-nonexistent-file-or-buffer'
 determines whether to request confirmation before creating a new
 buffer.
 
-BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
+BUFFER-OR-NAME may be a buffer, a string (a buffer name), or
 nil.  If BUFFER-OR-NAME is a string that does not identify an
 existing buffer, create a buffer with that name.  If
 BUFFER-OR-NAME is nil, switch to the buffer returned by
@@ -5012,25 +5002,27 @@ Return the buffer switched to."
   (interactive
    (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window))
   (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)))
-    (if (null force-same-window)
-       (pop-to-buffer buffer display-buffer--same-window-action norecord)
-      (cond
-       ;; Don't call set-window-buffer if it's not needed since it
-       ;; might signal an error (e.g. if the window is dedicated).
-       ((eq buffer (window-buffer)))
-       ((window-minibuffer-p)
-       (error "Cannot switch buffers in minibuffer window"))
-       ((eq (window-dedicated-p) t)
-       (error "Cannot switch buffers in a dedicated window"))
-       (t (set-window-buffer nil buffer)))
-
-      (unless norecord
-       (select-window (selected-window)))
-      (set-buffer buffer))))
+    (cond
+     ;; Don't call set-window-buffer if it's not needed since it
+     ;; might signal an error (e.g. if the window is dedicated).
+     ((eq buffer (window-buffer)))
+     ((window-minibuffer-p)
+      (if force-same-window
+          (error "Cannot switch buffers in minibuffer window")
+        (pop-to-buffer buffer norecord)))
+     ((eq (window-dedicated-p) t)
+      (if force-same-window
+          (error "Cannot switch buffers in a dedicated window")
+        (pop-to-buffer buffer norecord)))
+     (t (set-window-buffer nil buffer)))
+
+    (unless norecord
+      (select-window (selected-window)))
+    (set-buffer buffer)))
 
 (defun switch-to-buffer-other-window (buffer-or-name &optional norecord)
   "Select the buffer specified by BUFFER-OR-NAME in another window.
-BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
+BUFFER-OR-NAME may be a buffer, a string (a buffer name), or
 nil.  Return the buffer switched to.
 
 If called interactively, prompt for the buffer name using the
@@ -5054,7 +5046,7 @@ documentation for additional customization information."
 
 (defun switch-to-buffer-other-frame (buffer-or-name &optional norecord)
   "Switch to buffer BUFFER-OR-NAME in another frame.
-BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
+BUFFER-OR-NAME may be a buffer, a string (a buffer name), or
 nil.  Return the buffer switched to.
 
 If called interactively, prompt for the buffer name using the
@@ -5163,7 +5155,7 @@ WINDOW can be any live window and defaults to the selected one.
 Optional argument MAX-HEIGHT specifies the maximum height of
 WINDOW and defaults to the height of WINDOW's frame.  Optional
 argument MIN-HEIGHT specifies the minimum height of WINDOW and
-defaults to `window-min-height'.  Both, MAX-HEIGHT and MIN-HEIGHT
+defaults to `window-min-height'.  Both MAX-HEIGHT and MIN-HEIGHT
 are specified in lines and include the mode line and header line,
 if any.
 
@@ -5228,7 +5220,7 @@ WINDOW was scrolled."
        ;; This `condition-case' shouldn't be necessary, but who knows?
        (condition-case nil
            (if (zerop delta)
-               ;; Return zero if DELTA became zero in the proces.
+               ;; Return zero if DELTA became zero in the process.
                0
              ;; Don't try to redisplay with the cursor at the end on its
              ;; own line--that would force a scroll and spoil things.
@@ -5326,7 +5318,7 @@ A list of elements with possible values `top', `middle', `bottom',
 integer or float numbers that define the cycling order for
 the command `recenter-top-bottom'.
 
-Top and bottom destinations are `scroll-margin' lines the from true
+Top and bottom destinations are `scroll-margin' lines from the true
 window top and bottom.  Middle redraws the frame and centers point
 vertically within the window.  Integer number moves current line to
 the specified absolute window-line.  Float number between 0.0 and 1.0
@@ -5565,9 +5557,9 @@ With arg N, put point N/10 of the way from the true end."
 
 (defvar mouse-autoselect-window-state nil
   "When non-nil, special state of delayed window autoselection.
-Possible values are `suspend' \(suspend autoselection after a menu or
-scrollbar interaction\) and `select' \(the next invocation of
-'handle-select-window' shall select the window immediately\).")
+Possible values are `suspend' (suspend autoselection after a menu or
+scrollbar interaction) and `select' (the next invocation of
+`handle-select-window' shall select the window immediately).")
 
 (defun mouse-autoselect-window-cancel (&optional force)
   "Cancel delayed window autoselection.
@@ -5604,8 +5596,8 @@ means suspend autoselection."
 (defun mouse-autoselect-window-select ()
   "Select window with delayed window autoselection.
 If the mouse position has stabilized in a non-selected window, select
-that window.  The minibuffer window is selected only if the minibuffer is
-active.  This function is run by `mouse-autoselect-window-timer'."
+that window.  The minibuffer window is selected only if the minibuffer
+is active.  This function is run by `mouse-autoselect-window-timer'."
   (ignore-errors
    (let* ((mouse-position (mouse-position))
          (window