aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/src/buffer.c b/src/buffer.c
index dc6bcd8f6d3..6a11569c85a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -146,6 +146,9 @@ Lisp_Object Vinhibit_read_only;
146Lisp_Object Vkill_buffer_query_functions; 146Lisp_Object Vkill_buffer_query_functions;
147Lisp_Object Qkill_buffer_query_functions; 147Lisp_Object Qkill_buffer_query_functions;
148 148
149/* Hook run before changing a major mode. */
150Lisp_Object Vchange_major_mode_hook, Qchange_major_mode_hook;
151
149/* List of functions to call before changing an unmodified buffer. */ 152/* List of functions to call before changing an unmodified buffer. */
150Lisp_Object Vfirst_change_hook; 153Lisp_Object Vfirst_change_hook;
151 154
@@ -1711,9 +1714,18 @@ the window-buffer correspondences. */)
1711 char *err; 1714 char *err;
1712 1715
1713 if (EQ (buffer, Fwindow_buffer (selected_window))) 1716 if (EQ (buffer, Fwindow_buffer (selected_window)))
1714 /* Basically a NOP. Avoid signalling an error if the selected window 1717 {
1715 is dedicated, or a minibuffer, ... */ 1718 /* Basically a NOP. Avoid signalling an error in the case where
1716 return Fset_buffer (buffer); 1719 the selected window is dedicated, or a minibuffer. */
1720
1721 /* But do put this buffer at the front of the buffer list,
1722 unless that has been inhibited. Note that even if
1723 BUFFER is at the front of the main buffer-list already,
1724 we still want to move it to the front of the frame's buffer list. */
1725 if (NILP (norecord))
1726 record_buffer (buffer);
1727 return Fset_buffer (buffer);
1728 }
1717 1729
1718 err = no_switch_window (selected_window); 1730 err = no_switch_window (selected_window);
1719 if (err) error (err); 1731 if (err) error (err);
@@ -2142,10 +2154,11 @@ current buffer is cleared. */)
2142{ 2154{
2143 struct Lisp_Marker *tail, *markers; 2155 struct Lisp_Marker *tail, *markers;
2144 struct buffer *other; 2156 struct buffer *other;
2145 int undo_enabled_p = !EQ (current_buffer->undo_list, Qt);
2146 int begv, zv; 2157 int begv, zv;
2147 int narrowed = (BEG != BEGV || Z != ZV); 2158 int narrowed = (BEG != BEGV || Z != ZV);
2148 int modified_p = !NILP (Fbuffer_modified_p (Qnil)); 2159 int modified_p = !NILP (Fbuffer_modified_p (Qnil));
2160 Lisp_Object old_undo = current_buffer->undo_list;
2161 struct gcpro gcpro1;
2149 2162
2150 if (current_buffer->base_buffer) 2163 if (current_buffer->base_buffer)
2151 error ("Cannot do `set-buffer-multibyte' on an indirect buffer"); 2164 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
@@ -2154,10 +2167,11 @@ current buffer is cleared. */)
2154 if (NILP (flag) == NILP (current_buffer->enable_multibyte_characters)) 2167 if (NILP (flag) == NILP (current_buffer->enable_multibyte_characters))
2155 return flag; 2168 return flag;
2156 2169
2157 /* It would be better to update the list, 2170 GCPRO1 (old_undo);
2158 but this is good enough for now. */ 2171
2159 if (undo_enabled_p) 2172 /* Don't record these buffer changes. We will put a special undo entry
2160 current_buffer->undo_list = Qt; 2173 instead. */
2174 current_buffer->undo_list = Qt;
2161 2175
2162 /* If the cached position is for this buffer, clear it out. */ 2176 /* If the cached position is for this buffer, clear it out. */
2163 clear_charpos_cache (current_buffer); 2177 clear_charpos_cache (current_buffer);
@@ -2357,8 +2371,17 @@ current buffer is cleared. */)
2357 set_intervals_multibyte (1); 2371 set_intervals_multibyte (1);
2358 } 2372 }
2359 2373
2360 if (undo_enabled_p) 2374 if (!EQ (old_undo, Qt))
2361 current_buffer->undo_list = Qnil; 2375 {
2376 /* Represent all the above changes by a special undo entry. */
2377 extern Lisp_Object Qapply;
2378 current_buffer->undo_list = Fcons (list3 (Qapply,
2379 intern ("set-buffer-multibyte"),
2380 NILP (flag) ? Qt : Qnil),
2381 old_undo);
2382 }
2383
2384 UNGCPRO;
2362 2385
2363 /* Changing the multibyteness of a buffer means that all windows 2386 /* Changing the multibyteness of a buffer means that all windows
2364 showing that buffer must be updated thoroughly. */ 2387 showing that buffer must be updated thoroughly. */
@@ -2416,7 +2439,7 @@ the normal hook `change-major-mode-hook'. */)
2416 Lisp_Object oalist; 2439 Lisp_Object oalist;
2417 2440
2418 if (!NILP (Vrun_hooks)) 2441 if (!NILP (Vrun_hooks))
2419 call1 (Vrun_hooks, intern ("change-major-mode-hook")); 2442 call1 (Vrun_hooks, Qchange_major_mode_hook);
2420 oalist = current_buffer->local_var_alist; 2443 oalist = current_buffer->local_var_alist;
2421 2444
2422 /* Make sure none of the bindings in oalist 2445 /* Make sure none of the bindings in oalist
@@ -6028,6 +6051,13 @@ t means to use hollow box cursor. See `cursor-type' for other values. */);
6028 doc: /* List of functions called with no args to query before killing a buffer. */); 6051 doc: /* List of functions called with no args to query before killing a buffer. */);
6029 Vkill_buffer_query_functions = Qnil; 6052 Vkill_buffer_query_functions = Qnil;
6030 6053
6054 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook,
6055 doc: /* Normal hook run before changing the major mode of a buffer.
6056The function `kill-all-local-variables' runs this before doing anything else. */);
6057 Vchange_major_mode_hook = Qnil;
6058 Qchange_major_mode_hook = intern ("change-major-mode-hook");
6059 staticpro (&Qchange_major_mode_hook);
6060
6031 defsubr (&Sbuffer_live_p); 6061 defsubr (&Sbuffer_live_p);
6032 defsubr (&Sbuffer_list); 6062 defsubr (&Sbuffer_list);
6033 defsubr (&Sget_buffer); 6063 defsubr (&Sget_buffer);