Commit 66322887 authored by Dmitry Antipov's avatar Dmitry Antipov

Always use set_buffer_if_live to restore original buffer at unwind.

* buffer.h (record_unwind_current_buffer): New function.
* bytecode.c, dispnew.c, editfns.c, fileio.c, fns.c, insdel.c:
* keyboard.c, keymap.c, minibuf.c, print.c, process.c, textprop.c:
* undo.c, window.c: Adjust users.
* buffer.c (set_buffer_if_live): Fix comment.
parent a3d794a1
2012-08-28 Dmitry Antipov <dmantipov@yandex.ru>
Always use set_buffer_if_live to restore original buffer at unwind.
* buffer.h (record_unwind_current_buffer): New function.
* bytecode.c, dispnew.c, editfns.c, fileio.c, fns.c, insdel.c:
* keyboard.c, keymap.c, minibuf.c, print.c, process.c, textprop.c:
* undo.c, window.c: Adjust users.
* buffer.c (set_buffer_if_live): Fix comment.
2012-08-28 Dmitry Antipov <dmantipov@yandex.ru> 2012-08-28 Dmitry Antipov <dmantipov@yandex.ru>
Fix usage of set_buffer_internal. Fix usage of set_buffer_internal.
......
...@@ -2204,7 +2204,7 @@ ends when the current command terminates. Use `switch-to-buffer' or ...@@ -2204,7 +2204,7 @@ ends when the current command terminates. Use `switch-to-buffer' or
return buffer; return buffer;
} }
/* Set the current buffer to BUFFER provided it is alive. */ /* Set the current buffer to BUFFER provided if it is alive. */
Lisp_Object Lisp_Object
set_buffer_if_live (Lisp_Object buffer) set_buffer_if_live (Lisp_Object buffer)
......
...@@ -1038,6 +1038,15 @@ set_buffer_internal (struct buffer *b) ...@@ -1038,6 +1038,15 @@ set_buffer_internal (struct buffer *b)
set_buffer_internal_1 (b); set_buffer_internal_1 (b);
} }
/* Arrange to go back to the original buffer after the next
call to unbind_to if the original buffer is still alive. */
BUFFER_INLINE void
record_unwind_current_buffer (void)
{
record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
}
/* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements. /* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements.
If NEXTP is non-NULL, return next overlay there. If NEXTP is non-NULL, return next overlay there.
See overlay_at arg CHANGE_REQ for meaning of CHRQ arg. */ See overlay_at arg CHANGE_REQ for meaning of CHRQ arg. */
......
...@@ -1051,7 +1051,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, ...@@ -1051,7 +1051,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
CASE (Bsave_current_buffer): /* Obsolete since ??. */ CASE (Bsave_current_buffer): /* Obsolete since ??. */
CASE (Bsave_current_buffer_1): CASE (Bsave_current_buffer_1):
record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); record_unwind_current_buffer ();
NEXT; NEXT;
CASE (Bsave_window_excursion): /* Obsolete since 24.1. */ CASE (Bsave_window_excursion): /* Obsolete since 24.1. */
......
...@@ -5762,7 +5762,7 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth, ...@@ -5762,7 +5762,7 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth,
UNBLOCK_INPUT; UNBLOCK_INPUT;
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
run_window_configuration_change_hook (f); run_window_configuration_change_hook (f);
......
...@@ -946,13 +946,10 @@ BODY is executed just like `progn'. ...@@ -946,13 +946,10 @@ BODY is executed just like `progn'.
usage: (save-current-buffer &rest BODY) */) usage: (save-current-buffer &rest BODY) */)
(Lisp_Object args) (Lisp_Object args)
{ {
Lisp_Object val;
ptrdiff_t count = SPECPDL_INDEX (); ptrdiff_t count = SPECPDL_INDEX ();
record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); record_unwind_current_buffer ();
return unbind_to (count, Fprogn (args));
val = Fprogn (args);
return unbind_to (count, val);
} }
DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0, DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0,
......
...@@ -3480,7 +3480,7 @@ variable `last-coding-system-used' to the coding system actually used. */) ...@@ -3480,7 +3480,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
Lisp_Object workbuf; Lisp_Object workbuf;
struct buffer *buf; struct buffer *buf;
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
workbuf = Fget_buffer_create (build_string (" *code-converting-work*")); workbuf = Fget_buffer_create (build_string (" *code-converting-work*"));
buf = XBUFFER (workbuf); buf = XBUFFER (workbuf);
......
...@@ -4656,7 +4656,7 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_ ...@@ -4656,7 +4656,7 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
{ {
struct buffer *prev = current_buffer; struct buffer *prev = current_buffer;
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
CHECK_BUFFER (object); CHECK_BUFFER (object);
......
...@@ -2117,7 +2117,7 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute, ...@@ -2117,7 +2117,7 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute,
return Qnil; return Qnil;
} }
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
Fset_buffer (combine_after_change_buffer); Fset_buffer (combine_after_change_buffer);
......
...@@ -9572,7 +9572,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, ...@@ -9572,7 +9572,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
because we may get input from a subprocess which because we may get input from a subprocess which
wants to change the selected window and stuff (say, wants to change the selected window and stuff (say,
emacsclient). */ emacsclient). */
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
if (! FRAME_LIVE_P (XFRAME (selected_frame))) if (! FRAME_LIVE_P (XFRAME (selected_frame)))
Fkill_emacs (Qnil); Fkill_emacs (Qnil);
......
...@@ -1570,9 +1570,7 @@ like in the respective argument of `key-binding'. */) ...@@ -1570,9 +1570,7 @@ like in the respective argument of `key-binding'. */)
would not be a problem here, but it is easier to keep would not be a problem here, but it is easier to keep
things the same. things the same.
*/ */
record_unwind_current_buffer ();
record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
set_buffer_internal (XBUFFER (XWINDOW (window)->buffer)); set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
} }
} }
......
...@@ -817,7 +817,7 @@ get_minibuffer (EMACS_INT depth) ...@@ -817,7 +817,7 @@ get_minibuffer (EMACS_INT depth)
while the buffer doesn't know about them any more. */ while the buffer doesn't know about them any more. */
delete_all_overlays (XBUFFER (buf)); delete_all_overlays (XBUFFER (buf));
reset_buffer (XBUFFER (buf)); reset_buffer (XBUFFER (buf));
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
Fset_buffer (buf); Fset_buffer (buf);
if (!NILP (Ffboundp (intern ("minibuffer-inactive-mode")))) if (!NILP (Ffboundp (intern ("minibuffer-inactive-mode"))))
call0 (intern ("minibuffer-inactive-mode")); call0 (intern ("minibuffer-inactive-mode"));
......
...@@ -487,7 +487,7 @@ temp_output_buffer_setup (const char *bufname) ...@@ -487,7 +487,7 @@ temp_output_buffer_setup (const char *bufname)
register struct buffer *old = current_buffer; register struct buffer *old = current_buffer;
register Lisp_Object buf; register Lisp_Object buf;
record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); record_unwind_current_buffer ();
Fset_buffer (Fget_buffer_create (build_string (bufname))); Fset_buffer (Fget_buffer_create (build_string (bufname)));
......
...@@ -5196,7 +5196,7 @@ read_process_output (Lisp_Object proc, register int channel) ...@@ -5196,7 +5196,7 @@ read_process_output (Lisp_Object proc, register int channel)
/* There's no good reason to let process filters change the current /* There's no good reason to let process filters change the current
buffer, and many callers of accept-process-output, sit-for, and buffer, and many callers of accept-process-output, sit-for, and
friends don't expect current-buffer to be changed from under them. */ friends don't expect current-buffer to be changed from under them. */
record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); record_unwind_current_buffer ();
/* Read and dispose of the process output. */ /* Read and dispose of the process output. */
outstream = p->filter; outstream = p->filter;
...@@ -6587,7 +6587,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason) ...@@ -6587,7 +6587,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason)
/* There's no good reason to let sentinels change the current /* There's no good reason to let sentinels change the current
buffer, and many callers of accept-process-output, sit-for, and buffer, and many callers of accept-process-output, sit-for, and
friends don't expect current-buffer to be changed from under them. */ friends don't expect current-buffer to be changed from under them. */
record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); record_unwind_current_buffer ();
sentinel = p->sentinel; sentinel = p->sentinel;
if (NILP (sentinel)) if (NILP (sentinel))
......
...@@ -760,7 +760,7 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */) ...@@ -760,7 +760,7 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */)
if (BUFFERP (object) && current_buffer != XBUFFER (object)) if (BUFFERP (object) && current_buffer != XBUFFER (object))
{ {
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
Fset_buffer (object); Fset_buffer (object);
} }
...@@ -843,7 +843,7 @@ position LIMIT; return LIMIT if nothing is found before reaching LIMIT. */) ...@@ -843,7 +843,7 @@ position LIMIT; return LIMIT if nothing is found before reaching LIMIT. */)
if (BUFFERP (object) && current_buffer != XBUFFER (object)) if (BUFFERP (object) && current_buffer != XBUFFER (object))
{ {
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
Fset_buffer (object); Fset_buffer (object);
} }
......
...@@ -324,7 +324,7 @@ truncate_undo_list (struct buffer *b) ...@@ -324,7 +324,7 @@ truncate_undo_list (struct buffer *b)
/* Make the buffer current to get its local values of variables such /* Make the buffer current to get its local values of variables such
as undo_limit. Also so that Vundo_outer_limit_function can as undo_limit. Also so that Vundo_outer_limit_function can
tell which buffer to operate on. */ tell which buffer to operate on. */
record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); record_unwind_current_buffer ();
set_buffer_internal (b); set_buffer_internal (b);
list = BVAR (b, undo_list); list = BVAR (b, undo_list);
......
...@@ -3101,7 +3101,7 @@ run_window_configuration_change_hook (struct frame *f) ...@@ -3101,7 +3101,7 @@ run_window_configuration_change_hook (struct frame *f)
/* Use the right buffer. Matters when running the local hooks. */ /* Use the right buffer. Matters when running the local hooks. */
if (current_buffer != XBUFFER (Fwindow_buffer (Qnil))) if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
{ {
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
Fset_buffer (Fwindow_buffer (Qnil)); Fset_buffer (Fwindow_buffer (Qnil));
} }
...@@ -3205,7 +3205,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int ...@@ -3205,7 +3205,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
because that might itself be a local variable. */ because that might itself be a local variable. */
if (window_initialized) if (window_initialized)
{ {
record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); record_unwind_current_buffer ();
Fset_buffer (buffer); Fset_buffer (buffer);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment