]> git.eshelyaron.com Git - emacs.git/commitdiff
Add an optional parameter to kill-all-local-variables
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 6 Oct 2021 10:53:07 +0000 (12:53 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 6 Oct 2021 10:55:21 +0000 (12:55 +0200)
* doc/lispref/variables.texi (Creating Buffer-Local): Document it
(bug#30204).

* src/buffer.c (Fkill_all_local_variables): Allow killing
permanent local variables, too.

* src/print.c (temp_output_buffer_setup):
* src/minibuf.c (set_minibuffer_mode): Adjust callers.

doc/lispref/variables.texi
etc/NEWS
src/buffer.c
src/minibuf.c
src/print.c

index a1d1919b4bffc974875c89f84d3fb9ffeb08ef2f..d2247004bcbccc5ed9acf00d8d7c92185d7fd140 100644 (file)
@@ -1695,12 +1695,14 @@ buffer-local variables interactively.
 @end deffn
 
 @cindex local variables, killed by major mode
-@defun kill-all-local-variables
+@defun kill-all-local-variables &optional kill-permanent
 This function eliminates all the buffer-local variable bindings of the
-current buffer except for variables marked as permanent and local
-hook functions that have a non-@code{nil} @code{permanent-local-hook}
-property (@pxref{Setting Hooks}).  As a result, the buffer will see
-the default values of most variables.
+current buffer.  As a result, the buffer will see the default values
+of most variables.  By default, for variables marked as permanent and
+local hook functions that have a non-@code{nil}
+@code{permanent-local-hook} property (@pxref{Setting Hooks}) won't be
+killed, but if the optional @var{kill-permanent} argument is
+non-@code{nil}, even these variables will be killed.
 
 This function also resets certain other information pertaining to the
 buffer: it sets the local keymap to @code{nil}, the syntax table to the
index ae3bba4f786aaecaefeae5f6f9e00898532884bd..7360bb79852b1d66b92261846e49f67395d201f1 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -125,6 +125,11 @@ with recent versions of Firefox.
 \f
 * Lisp Changes in Emacs 29.1
 
++++
+** 'kill-all-local-variables' can now kill all local variables.
+If given the new optional KILL-PERMANENT argument, also kill permanent
+local variables.
+
 +++
 ** Third 'mapconcat' argument 'separator' is now optional.
 An explicit nil always meant the empty string, now it can be left out.
index 4eb7ab6d6baa73a9f4d3884a5ca78700b2910e17..c5b2736ae3ae13f004494fa494da8bacaf5b9c8b 100644 (file)
@@ -2805,7 +2805,7 @@ current buffer is cleared.  */)
 }
 \f
 DEFUN ("kill-all-local-variables", Fkill_all_local_variables,
-       Skill_all_local_variables, 0, 0, 0,
+       Skill_all_local_variables, 0, 1, 0,
        doc: /* Switch to Fundamental mode by killing current buffer's local variables.
 Most local variable bindings are eliminated so that the default values
 become effective once more.  Also, the syntax table is set from
@@ -2816,18 +2816,20 @@ This function also forces redisplay of the mode line.
 Every function to select a new major mode starts by
 calling this function.
 
-As a special exception, local variables whose names have
-a non-nil `permanent-local' property are not eliminated by this function.
+As a special exception, local variables whose names have a non-nil
+`permanent-local' property are not eliminated by this function.  If
+the optional KILL-PERMANENT argument is non-nil, clear out these local
+variables, too.
 
 The first thing this function does is run
 the normal hook `change-major-mode-hook'.  */)
-  (void)
+  (Lisp_Object kill_permanent)
 {
   run_hook (Qchange_major_mode_hook);
 
   /* Actually eliminate all local bindings of this buffer.  */
 
-  reset_buffer_local_variables (current_buffer, 0);
+  reset_buffer_local_variables (current_buffer, !NILP (kill_permanent));
 
   /* Force mode-line redisplay.  Useful here because all major mode
      commands call this function.  */
index 4b72d3e896bf6958c46b957eb1e10a18effdbf0d..5455a93f69447ad8624b486e28f900c292ae4dbf 100644 (file)
@@ -1005,7 +1005,7 @@ set_minibuffer_mode (Lisp_Object buf, EMACS_INT depth)
       if (!NILP (Ffboundp (Qminibuffer_inactive_mode)))
        call0 (Qminibuffer_inactive_mode);
       else
-       Fkill_all_local_variables ();
+       Fkill_all_local_variables (Qnil);
     }
   buf = unbind_to (count, buf);
 }
index 9f684bbeb538c628a3671e120cf318726eab72c8..c13294c8e62323bd5d8ab903b7160d23bb759d6a 100644 (file)
@@ -564,7 +564,7 @@ temp_output_buffer_setup (const char *bufname)
 
   Fset_buffer (Fget_buffer_create (build_string (bufname), Qnil));
 
-  Fkill_all_local_variables ();
+  Fkill_all_local_variables (Qnil);
   delete_all_overlays (current_buffer);
   bset_directory (current_buffer, BVAR (old, directory));
   bset_read_only (current_buffer, Qnil);