[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

switch-buffer to use other window if dedicated window (was: Jumping to C

From: Drew Adams
Subject: switch-buffer to use other window if dedicated window (was: Jumping to C source from *Help*)
Date: Thu, 8 Apr 2004 10:27:13 -0700

Forgive me if this is not too germane or up-to-date.

To me, it makes sense for `switch-to-buffer' to use another window if the
selected window is dedicated.

FWIW, here's the redefinition of `switch-to-buffer' that I use (Emacs 20 -

;; 1) Uses `read-buffer' in interactive spec.
;; 2) If current window is dedicated, then use another window.
;;    NOTE: Emacs versions >= 19.34 signal an error if dedicated window,
;;          instead of using another one.  Don't know what the 19.28 version
;; 3) `fit-frame-if-one-window' if `fit-frame-when-switch-to-p'.

(defun switch-to-buffer (buffer &optional norecord)
  "Select buffer BUFFER in current window, unless the window is dedicated.
If current window is dedicated (`window-dedicated-p'), then another window
is used.  BUFFER may be a buffer or its name.

Optional second arg NORECORD non-nil =>
   Do not put BUFFER at front of list of recently selected buffers.

*WARNING*: This is NOT the way to work on another buffer temporarily
within a Lisp program!  Use `set-buffer' instead, to avoid messing
with window-buffer correspondences.

`fit-frame-if-one-window' if `fit-frame-when-switch-to-p'."

   (list (read-buffer "Switch to buffer: " nil 'existing)))
  (if (window-dedicated-p (selected-window))
      (switch-to-buffer-other-window buffer)
    (old-switch-to-buffer buffer norecord))
  (fit-frame-if-one-window-and-cond fit-frame-when-switch-to-p))

[FYI -

Function `fit-frame-if-one-window-and-cond' shrink-wraps the frame of the
selected window if variable (user option) `fit-frame-when-switch-to-p' is

Function `read-buffer' reads the name of a buffer and returns it as a
Prompts with first arg, PROMPT (a string).
The default buffer is named by the optional 2nd arg, DEFAULT, if a
string or buffer, or by `another-buffer' if nil.
Non-nil optional 3rd arg, EXISTING, means to allow only names of
existing buffers.]

 - Drew

-----Original Message-----
From: address@hidden
[mailto:address@hidden Behalf Of
Stefan Monnier
Sent: Thursday, April 08, 2004 9:47 AM
To: Juri Linkov
Cc: address@hidden
Subject: Re: Jumping to C source from *Help*

> -                  (pop-to-buffer (car location))
> +                  (switch-to-buffer (car location))

That signals an error when the *Help* buffer is on a dedicated window (as
is the case for me).  I spend a lot of time getting rid of such misuses of
switch-to-buffer, so I strongly oppose this patch.

Of course, the right way to fix it might be to make switch-to-buffer
delegate to pop-to-buffer rather than signal an error.  But last time
I suggested it, Richard did not like it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]