From 2594e0fdb5d92efc775ee9ecc14fc8a0201855c7 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 5 Aug 1999 19:38:34 +0000 Subject: (switch_to_buffer_1): New subroutine, taken out from Fswitch_to_buffer. (no_switch_buffer): New function. (Fswitch_to_buffer): Call them. Don't get confused by "same-window" buffers in a dedicated frame. --- src/buffer.c | 58 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index d6989697a7..5bd83ceb53 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1320,26 +1320,30 @@ the current buffer's major mode.") return unbind_to (count, Qnil); } -DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ", - "Select buffer BUFFER in the current window.\n\ -BUFFER may be a buffer or a buffer name.\n\ -Optional second arg NORECORD non-nil means\n\ -do not put this buffer at the front of the list of recently selected ones.\n\ -\n\ -WARNING: This is NOT the way to work on another buffer temporarily\n\ -within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\ -the window-buffer correspondences.") - (buffer, norecord) - Lisp_Object buffer, norecord; +/* If switching buffers in WINDOW would be an error, return + a C string saying what the error would be. */ + +char * +no_switch_window (window) + Lisp_Object window; { - register Lisp_Object buf; Lisp_Object tem; - - if (EQ (minibuf_window, selected_window)) - error ("Cannot switch buffers in minibuffer window"); - tem = Fwindow_dedicated_p (selected_window); + if (EQ (minibuf_window, window)) + return "Cannot switch buffers in minibuffer window"; + tem = Fwindow_dedicated_p (window); if (!NILP (tem)) - error ("Cannot switch buffers in a dedicated window"); + return "Cannot switch buffers in a dedicated window"; + return NULL; +} + +/* Switch to buffer BUFFER in the selected window. + If NORECORD is non-nil, don't call record_buffer. */ + +Lisp_Object +switch_to_buffer_1 (buffer, norecord) + Lisp_Object buffer, norecord; +{ + register Lisp_Object buf; if (NILP (buffer)) buf = Fother_buffer (Fcurrent_buffer (), Qnil, Qnil); @@ -1364,6 +1368,26 @@ the window-buffer correspondences.") return buf; } +DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ", + "Select buffer BUFFER in the current window.\n\ +BUFFER may be a buffer or a buffer name.\n\ +Optional second arg NORECORD non-nil means\n\ +do not put this buffer at the front of the list of recently selected ones.\n\ +\n\ +WARNING: This is NOT the way to work on another buffer temporarily\n\ +within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\ +the window-buffer correspondences.") + (buffer, norecord) + Lisp_Object buffer, norecord; +{ + char *err; + + err = no_switch_window (selected_window); + if (err) error (err); + + return switch_to_buffer_1 (buffer, norecord); +} + DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 3, 0, "Select buffer BUFFER in some window, preferably a different one.\n\ If BUFFER is nil, then some other buffer is chosen.\n\ -- cgit v1.2.3