]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix kill-all-local-variables
authorEshel Yaron <me@eshelyaron.com>
Mon, 11 Nov 2024 10:24:59 +0000 (11:24 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 11 Nov 2024 10:24:59 +0000 (11:24 +0100)
lisp/emacs-lisp/subr-x.el
src/buffer.c

index b5cbe28afad108d9a7ecc92b4689592afb6807b7..5b47deb880e2cd14e82471201ef9d2de74bccba3 100644 (file)
@@ -361,7 +361,7 @@ automatically killed, which means that in a such case
           (erase-buffer))
         (delete-all-overlays)
         (let (change-major-mode-hook)
-          (kill-all-local-variables))
+          (kill-all-local-variables t))
         ;; Make the buffer available again.
         (push buffer work-buffer--list)))
   ;; If the maximum number of reusable work buffers is exceeded, kill
index 90c5efdfbf7da8670c3a0f1c7a970cb90b1d8fa7..2955ee6399bde0808c86987a92f0e40f248c02c7 100644 (file)
@@ -111,7 +111,7 @@ static int last_per_buffer_idx;
 static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
                                     bool after, Lisp_Object arg1,
                                     Lisp_Object arg2, Lisp_Object arg3);
-static void reset_buffer_local_variables (struct buffer *, bool);
+static void reset_buffer_local_variables (struct buffer *, int);
 
 /* Alist of all buffer names vs the buffers.  This used to be
    a Lisp-visible variable, but is no longer, to prevent lossage
@@ -1110,10 +1110,11 @@ reset_buffer (register struct buffer *b)
    Instead, use Fkill_all_local_variables.
 
    If PERMANENT_TOO, reset permanent buffer-local variables.
-   If not, preserve those.  */
+   If not, preserve those.  PERMANENT_TOO = 2 means ignore
+   the permanent-local property of non-builtin variables.  */
 
 static void
-reset_buffer_local_variables (struct buffer *b, bool permanent_too)
+reset_buffer_local_variables (struct buffer *b, int permanent_too)
 {
   int offset, i;
 
@@ -1139,7 +1140,7 @@ reset_buffer_local_variables (struct buffer *b, bool permanent_too)
   bset_invisibility_spec (b, Qt);
 
   /* Reset all (or most) per-buffer variables to their defaults.  */
-  if (permanent_too)
+  if (permanent_too == 1)
     bset_local_var_alist (b, Qnil);
   else
     {
@@ -1168,7 +1169,7 @@ reset_buffer_local_variables (struct buffer *b, bool permanent_too)
              swap_in_global_binding (XSYMBOL (sym));
            }
 
-          if (!NILP (prop))
+          if (!NILP (prop) && !permanent_too)
             {
               /* If permanent-local, keep it.  */
               last = tmp;
@@ -3006,7 +3007,7 @@ the normal hook `change-major-mode-hook'.  */)
 
   /* Actually eliminate all local bindings of this buffer.  */
 
-  reset_buffer_local_variables (current_buffer, !NILP (kill_permanent));
+  reset_buffer_local_variables (current_buffer, !NILP (kill_permanent) ? 2 : 0);
 
   /* Force mode-line redisplay.  Useful here because all major mode
      commands call this function.  */