emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c0f7396 1/2: Add an optional parameter to kill-all-local-variable


From: Lars Ingebrigtsen
Subject: master c0f7396 1/2: Add an optional parameter to kill-all-local-variables
Date: Wed, 6 Oct 2021 06:55:27 -0400 (EDT)

branch: master
commit c0f7396588080ac48b72b905880d3f488e5becb3
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add an optional parameter to kill-all-local-variables
    
    * 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 | 12 +++++++-----
 etc/NEWS                   |  5 +++++
 src/buffer.c               | 12 +++++++-----
 src/minibuf.c              |  2 +-
 src/print.c                |  2 +-
 5 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index a1d1919..d224700 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index ae3bba4..7360bb7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -126,6 +126,11 @@ with recent versions of Firefox.
 * 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.
 
diff --git a/src/buffer.c b/src/buffer.c
index 4eb7ab6..c5b2736 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2805,7 +2805,7 @@ current buffer is cleared.  */)
 }
 
 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.  */
diff --git a/src/minibuf.c b/src/minibuf.c
index 4b72d3e..5455a93 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -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);
 }
diff --git a/src/print.c b/src/print.c
index 9f684bb..c13294c 100644
--- a/src/print.c
+++ b/src/print.c
@@ -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);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]