diff --git a/src/ChangeLog b/src/ChangeLog index 0806cc0ff95ef7e5a2f72f17d30315b09b892df9..889c8efebdbb8434a1a61022d6408b1f7cef70bb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2012-08-28 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. + 2012-08-28 Dmitry Antipov Fix usage of set_buffer_internal. diff --git a/src/buffer.c b/src/buffer.c index 5185e6c89f1e25f9110a72b59d7ed977505e72b2..61ec736ad1a8d3c41566d2f498a012c31247b281 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -2204,7 +2204,7 @@ ends when the current command terminates. Use `switch-to-buffer' or 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 set_buffer_if_live (Lisp_Object buffer) diff --git a/src/buffer.h b/src/buffer.h index 929da3c4791818e9411d655faa9637539a4c1b18..3acf142381605155c9962c410d3946ea950dca4e 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1038,6 +1038,15 @@ set_buffer_internal (struct buffer *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. If NEXTP is non-NULL, return next overlay there. See overlay_at arg CHANGE_REQ for meaning of CHRQ arg. */ diff --git a/src/bytecode.c b/src/bytecode.c index 753f149ae01091cd6872ef486ea6747b2a83d1d2..40729cbd45364f6e285c2cae62009d2f8e6d2d77 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -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_1): - record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); + record_unwind_current_buffer (); NEXT; CASE (Bsave_window_excursion): /* Obsolete since 24.1. */ diff --git a/src/dispnew.c b/src/dispnew.c index f37b872274a5d76eb63dfbf2093087ca14007f8c..4e3078801117e4c110e89250d15aedb0bb4498eb 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -5762,7 +5762,7 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth, UNBLOCK_INPUT; - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); run_window_configuration_change_hook (f); diff --git a/src/editfns.c b/src/editfns.c index 0bd632d14b74a8729ec4ed8150e06ee221b4758b..7b451e4e443d402065a1ef4c13ab8c5e0ab972e3 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -946,13 +946,10 @@ BODY is executed just like `progn'. usage: (save-current-buffer &rest BODY) */) (Lisp_Object args) { - Lisp_Object val; ptrdiff_t count = SPECPDL_INDEX (); - record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); - - val = Fprogn (args); - return unbind_to (count, val); + record_unwind_current_buffer (); + return unbind_to (count, Fprogn (args)); } DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0, diff --git a/src/fileio.c b/src/fileio.c index 44696cc8e623b9e93a659e08caddaac1a0954e0c..7466914af1cf13cf4082130ccd511f0ea41a0030 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3480,7 +3480,7 @@ variable `last-coding-system-used' to the coding system actually used. */) Lisp_Object workbuf; struct buffer *buf; - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); workbuf = Fget_buffer_create (build_string (" *code-converting-work*")); buf = XBUFFER (workbuf); diff --git a/src/fns.c b/src/fns.c index b13311e26d0ebe3c36f4665724d2e20c741fdc30..f6acdcada3f5aed996452bb5cc1cdc3911f36ccc 100644 --- a/src/fns.c +++ b/src/fns.c @@ -4656,7 +4656,7 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_ { struct buffer *prev = current_buffer; - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); CHECK_BUFFER (object); diff --git a/src/insdel.c b/src/insdel.c index 53a3a1370cd35acf9c154262a33e16c0efe65479..8cb98566085b98767b42113388c00eb7df60eaf1 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -2117,7 +2117,7 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute, return Qnil; } - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); Fset_buffer (combine_after_change_buffer); diff --git a/src/keyboard.c b/src/keyboard.c index f31480e3b88bdf6a9a1945b8cbcc09701103f225..d9b88a8a91120d070b2618b4e45ee2dd18ba999f 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -9572,7 +9572,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, because we may get input from a subprocess which wants to change the selected window and stuff (say, emacsclient). */ - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); if (! FRAME_LIVE_P (XFRAME (selected_frame))) Fkill_emacs (Qnil); diff --git a/src/keymap.c b/src/keymap.c index 21f7dcb5d37f0162a62f1a9bb27149ec973137eb..4031091501cf8b961268ed48d378e91c994c8843 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -1570,9 +1570,7 @@ like in the respective argument of `key-binding'. */) would not be a problem here, but it is easier to keep things the same. */ - - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); - + record_unwind_current_buffer (); set_buffer_internal (XBUFFER (XWINDOW (window)->buffer)); } } diff --git a/src/minibuf.c b/src/minibuf.c index 2154d1654dfdd8e0f4fd4d275e18339de88451e5..41cc48017eb111d4c728ff5737d67b4776d31e76 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -817,7 +817,7 @@ get_minibuffer (EMACS_INT depth) while the buffer doesn't know about them any more. */ delete_all_overlays (XBUFFER (buf)); reset_buffer (XBUFFER (buf)); - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); Fset_buffer (buf); if (!NILP (Ffboundp (intern ("minibuffer-inactive-mode")))) call0 (intern ("minibuffer-inactive-mode")); diff --git a/src/print.c b/src/print.c index 36d0b5dce9d0bd55d9a782d01d7e7c1133d29c1b..52c07c79122627dabbcede750747e902e933c37e 100644 --- a/src/print.c +++ b/src/print.c @@ -487,7 +487,7 @@ temp_output_buffer_setup (const char *bufname) register struct buffer *old = current_buffer; 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))); diff --git a/src/process.c b/src/process.c index 64c70c49590896ac62d26c0a64442417d9439ade..fbe56ebcb549ac6021abc47b382df426f0baa8fe 100644 --- a/src/process.c +++ b/src/process.c @@ -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 buffer, and many callers of accept-process-output, sit-for, and 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. */ outstream = p->filter; @@ -6587,7 +6587,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason) /* There's no good reason to let sentinels change the current buffer, and many callers of accept-process-output, sit-for, and 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; if (NILP (sentinel)) diff --git a/src/textprop.c b/src/textprop.c index 20d98b0e6f31b42e2a4e7420d7793cc59a5997f7..b6895fc426a0ad8dc7e73c2669a2cf0768705ccd 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -760,7 +760,7 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */) if (BUFFERP (object) && current_buffer != XBUFFER (object)) { - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); Fset_buffer (object); } @@ -843,7 +843,7 @@ position LIMIT; return LIMIT if nothing is found before reaching LIMIT. */) if (BUFFERP (object) && current_buffer != XBUFFER (object)) { - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); Fset_buffer (object); } diff --git a/src/undo.c b/src/undo.c index 777e3291806246a48615297dd628e34d354889fc..9cd1d5f9f67b8a57b3eb54679f96fd635c7b77ab 100644 --- a/src/undo.c +++ b/src/undo.c @@ -324,7 +324,7 @@ truncate_undo_list (struct buffer *b) /* Make the buffer current to get its local values of variables such as undo_limit. Also so that Vundo_outer_limit_function can tell which buffer to operate on. */ - record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); + record_unwind_current_buffer (); set_buffer_internal (b); list = BVAR (b, undo_list); diff --git a/src/window.c b/src/window.c index 330636efed93dd9e5d7477797544fb043d3bdcf6..ba1ec2544f8177527faca36d67b150e80c58076d 100644 --- a/src/window.c +++ b/src/window.c @@ -3101,7 +3101,7 @@ run_window_configuration_change_hook (struct frame *f) /* Use the right buffer. Matters when running the local hooks. */ if (current_buffer != XBUFFER (Fwindow_buffer (Qnil))) { - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); Fset_buffer (Fwindow_buffer (Qnil)); } @@ -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. */ if (window_initialized) { - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); Fset_buffer (buffer); }