GNU bug report logs - #74091
31.0.50; string-pixel-width in mode line disables region

Previous Next

Package: emacs;

Reported by: Eshel Yaron <me <at> eshelyaron.com>

Date: Tue, 29 Oct 2024 17:28:02 UTC

Severity: normal

Found in version 31.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: monnier <at> iro.umontreal.ca
Cc: me <at> eshelyaron.com, 74091 <at> debbugs.gnu.org
Subject: bug#74091: 31.0.50; string-pixel-width in mode line disables region
Date: Sat, 09 Nov 2024 20:35:40 +0200
> Cc: me <at> eshelyaron.com, 74091 <at> debbugs.gnu.org
> Date: Sat, 09 Nov 2024 20:14:43 +0200
> From: Eli Zaretskii <eliz <at> gnu.org>
> 
> > From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> > Cc: me <at> eshelyaron.com,  74091 <at> debbugs.gnu.org
> > Date: Sat, 09 Nov 2024 13:06:13 -0500
> > 
> > AFAICT the problem is new with the addition of the `kill-permanent`
> > arg to `kill-all-local-variables`.
> > 
> > Here's an example of a problem:
> > 
> >     src/emacs -Q --batch --eval '(message "%s" (list (setq-default foo nil) (setq-local foo t) (kill-all-local-variables t) (local-variable-p `foo) foo (default-value `foo) (with-temp-buffer foo) foo))'
> > 
> > =>
> > 
> >     (nil t nil t t nil nil nil)
> > 
> > If we call `kill-all-local-variables` without the additional argument, we
> > get the correct answer:
> > 
> >     (nil t nil nil nil nil nil nil)
> 
> This feature was introduced in Emacs 29, so we should preferably fix
> it in Emacs 30.  Any suggestions?

I think calling reset_buffer_local_variables with 2nd arg non-zero is
not TRT to implement this new argument of kill-all-local-variables,
because it does this:

  /* Reset all (or most) per-buffer variables to their defaults.  */
  if (permanent_too)
    bset_local_var_alist (b, Qnil);

I think we should instead ignore the permanent-local property of
variables.  How about the patch below?

diff --git a/src/buffer.c b/src/buffer.c
index 744b0ef..9e93e0f 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -113,7 +113,7 @@ #define OVERLAY_COUNT_MAX						\
 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
@@ -1112,10 +1112,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;
 
@@ -1141,7 +1142,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
     {
@@ -1170,7 +1171,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;
@@ -3001,7 +3002,7 @@ DEFUN ("kill-all-local-variables", Fkill_all_local_variables,
 
   /* 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.  */




This bug report was last modified 194 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.