unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#33492: 27.0.50; desktop-locals-to-save won't consider buffer-undo-list as local
@ 2018-11-24 20:54 Terje Larsen
  2018-11-28  1:23 ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Terje Larsen @ 2018-11-24 20:54 UTC (permalink / raw)
  To: 33492

Add buffer-undo-list to be saved by desktop-save:
(cl-pushnew 'buffer-undo-list desktop-locals-to-save :test #'equal)

Open a file:
C-x C-f ~/sample.txt

Input text such as:
Lorem ipsum dolor sit amet

Remove the two last words:
M-2 M-DEL

Save the desktop:
M-x desktop-save

... Restart Emacs ...

Load the desktop:
M-x desktop-read

Execute undo operation:
C-/

At this point I expect the undo operations from the previous session
to be successful.

It seems like this has been mentioned at StackExchange amongst other
places before:
https://emacs.stackexchange.com/questions/3725/why-is-the-buffer-undo-list-excluded-from-buffer-local-variables

I can verify that the issue stems from desktop-save relying on the C-function
buffer-local-variables and this function does not include the variable
buffer-undo-list.
Due to this it will be ignored from being saved by the desktop-save command.

Proposed in the StackExchange post is to append the buffer-undo-list
in the desktop-save
function. But perhaps it should be included in the C-function? Or does
that perhaps cause
other issues?

Personally I have solved it by using an advice:

(defun +append-buffer-undo-list-to-buffer-local-variables-advice
(orig-fn &rest args)
       "Override `buffer-local-variables' and call ORIG-FN with ARGS.
     There is a bug in Emacs where the `buffer-undo-list' data is
     missing from the output of `buffer-local-variables'. This
     advice temporarily overrides the function and appends the
     missing data."
       (let ((orig-buffer-local-variables-fn (symbol-function
'buffer-local-variables)))
         (cl-letf (((symbol-function 'buffer-local-variables)
                    #'(lambda () (append (funcall
orig-buffer-local-variables-fn)
                                    `(,(cons 'buffer-undo-list
buffer-undo-list))))))
           (apply orig-fn args))))
(advice-add #'desktop-buffer-info :around
#'+append-buffer-undo-list-to-buffer-local-variables-advice)

I hope this "long-standing" bug would allow more people to utilize a
persistent undo without
jumping through hoops.

Thanks!


In GNU Emacs 27.0.50 (build 2, x86_64-apple-darwin18.0.0, NS
appkit-1671.00 Version 10.14 (Build 18A391))
of 2018-11-07 built on C02V91MHHV2Q.local
Repository revision: 811d9291fcfb12d87bad277d4e8b25152129d73d
Windowing system distributor 'Apple', version 10.3.1671
System Description:  Mac OS X 10.14.1

Recent messages:
Desktop: 1 frame, 1 buffer restored.
You can run the command ‘desktop-read’ with M-x d-rea RET
Desktop: 1 frame, 1 buffer restored.
user-error: No further undo information [2 times]
user-error: Beginning of history; no preceding item
user-error: End of history; no default available

Configured using:
'configure --disable-dependency-tracking --disable-silent-rules
--enable-locallisppath=/usr/local/share/emacs/site-lisp
--infodir=/usr/local/Cellar/emacs/HEAD-811d929_1/share/info/emacs
--prefix=/usr/local/Cellar/emacs/HEAD-811d929_1 --with-gnutls
--without-x --with-xml2 --without-dbus --with-imagemagick --with-rsvg
--with-ns --disable-ns-self-contained'

Configured features:
RSVG IMAGEMAGICK GLIB NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS NS THREADS LCMS2 GMP

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Text

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny seq byte-opt gv
bytecomp byte-compile cconv dired dired-loaddefs format-spec rfc822 mml
mml-sec password-cache epa derived epg epg-config gnus-util rmail
rmail-loaddefs time-date mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils thingatpt cl-seq cl-extra
help-mode easymenu desktop frameset cl-loaddefs cl-lib elec-pair tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads kqueue cocoa ns
lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 208523 10884)
(symbols 48 20326 1)
(strings 32 30075 1669)
(string-bytes 1 808523)
(vectors 16 35932)
(vector-slots 8 729980 19992)
(floats 8 51 198)
(intervals 56 240 0)
(buffers 992 13))





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#33492: 27.0.50; desktop-locals-to-save won't consider buffer-undo-list as local
  2018-11-24 20:54 bug#33492: 27.0.50; desktop-locals-to-save won't consider buffer-undo-list as local Terje Larsen
@ 2018-11-28  1:23 ` Glenn Morris
  2018-11-28 21:49   ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2018-11-28  1:23 UTC (permalink / raw)
  To: Terje Larsen; +Cc: 33492

Terje Larsen wrote:

> https://emacs.stackexchange.com/questions/3725/why-is-the-buffer-undo-list-excluded-from-buffer-local-variables
>
> I can verify that the issue stems from desktop-save relying on the
> C-function buffer-local-variables and this function does not include
> the variable buffer-undo-list.


Thanks for the report.
This issue (buffer-local-variables does not include buffer-undo-list)
is present since Emacs 24.3, due to 36429c8, which moved undo_list to
the end of struct buffer.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#33492: 27.0.50; desktop-locals-to-save won't consider buffer-undo-list as local
  2018-11-28  1:23 ` Glenn Morris
@ 2018-11-28 21:49   ` Glenn Morris
  2019-01-30  0:30     ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2018-11-28 21:49 UTC (permalink / raw)
  To: Terje Larsen; +Cc: 33492

Glenn Morris wrote:

> This issue (buffer-local-variables does not include buffer-undo-list)
> is present since Emacs 24.3, due to 36429c8, which moved undo_list to
> the end of struct buffer.

The following works, but I don't know if it is the best solution.

--- i/src/buffer.c
+++ w/src/buffer.c
@@ -1266,6 +1266,20 @@ buffer_lisp_local_variables (struct buffer *buf, bool clone)
   return result;
 }
 
+Lisp_Object
+buffer_local_variables_1 (struct buffer *buf, int offset)
+{
+  int idx = PER_BUFFER_IDX (offset);
+  if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
+      && SYMBOLP (PER_BUFFER_SYMBOL (offset)))
+    {
+      Lisp_Object sym = PER_BUFFER_SYMBOL (offset);
+      Lisp_Object val = per_buffer_value (buf, offset);
+      return EQ (val, Qunbound) ? sym : Fcons (sym, val);
+    }
+  return Qnil;
+}
+
 DEFUN ("buffer-local-variables", Fbuffer_local_variables,
        Sbuffer_local_variables, 0, 1, 0,
        doc: /* Return an alist of variables that are buffer-local in BUFFER.
@@ -1277,6 +1291,7 @@ No argument or nil as argument means use current buffer as BUFFER.  */)
 {
   struct buffer *buf = decode_buffer (buffer);
   Lisp_Object result = buffer_lisp_local_variables (buf, 0);
+  Lisp_Object tem;
 
   /* Add on all the variables stored in special slots.  */
   {
@@ -1284,18 +1299,16 @@ No argument or nil as argument means use current buffer as BUFFER.  */)
 
     FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
       {
-	idx = PER_BUFFER_IDX (offset);
-	if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
-	    && SYMBOLP (PER_BUFFER_SYMBOL (offset)))
-	  {
-	    Lisp_Object sym = PER_BUFFER_SYMBOL (offset);
-	    Lisp_Object val = per_buffer_value (buf, offset);
-	    result = Fcons (EQ (val, Qunbound) ? sym : Fcons (sym, val),
-			    result);
-	  }
+        tem = buffer_local_variables_1 (buf, offset);
+        if (!NILP (tem))
+          result = Fcons (tem, result);
       }
   }
 
+  tem = buffer_local_variables_1 (buf, PER_BUFFER_VAR_OFFSET (undo_list));
+  if (!NILP (tem))
+    result = Fcons (tem, result);
+
   return result;
 }





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#33492: 27.0.50; desktop-locals-to-save won't consider buffer-undo-list as local
  2018-11-28 21:49   ` Glenn Morris
@ 2019-01-30  0:30     ` Glenn Morris
  2020-05-18 17:57       ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2019-01-30  0:30 UTC (permalink / raw)
  To: 33492; +Cc: Terje Larsen

Glenn Morris wrote:

>> This issue (buffer-local-variables does not include buffer-undo-list)
>> is present since Emacs 24.3, due to 36429c8, which moved undo_list to
>> the end of struct buffer.
>
> The following works, but I don't know if it is the best solution.
>
> --- i/src/buffer.c
> +++ w/src/buffer.c
> @@ -1266,6 +1266,20 @@ buffer_lisp_local_variables (struct buffer *buf, bool clone)
>    return result;
>  }
>  
> +Lisp_Object
> +buffer_local_variables_1 (struct buffer *buf, int offset)
> +{
> +  int idx = PER_BUFFER_IDX (offset);
> +  if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
> +      && SYMBOLP (PER_BUFFER_SYMBOL (offset)))
> +    {
> +      Lisp_Object sym = PER_BUFFER_SYMBOL (offset);
> +      Lisp_Object val = per_buffer_value (buf, offset);
> +      return EQ (val, Qunbound) ? sym : Fcons (sym, val);
> +    }
> +  return Qnil;
> +}
> +
>  DEFUN ("buffer-local-variables", Fbuffer_local_variables,
>         Sbuffer_local_variables, 0, 1, 0,
>         doc: /* Return an alist of variables that are buffer-local in BUFFER.
> @@ -1277,6 +1291,7 @@ No argument or nil as argument means use current buffer as BUFFER.  */)
>  {
>    struct buffer *buf = decode_buffer (buffer);
>    Lisp_Object result = buffer_lisp_local_variables (buf, 0);
> +  Lisp_Object tem;
>  
>    /* Add on all the variables stored in special slots.  */
>    {
> @@ -1284,18 +1299,16 @@ No argument or nil as argument means use current buffer as BUFFER.  */)
>  
>      FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
>        {
> -	idx = PER_BUFFER_IDX (offset);
> -	if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
> -	    && SYMBOLP (PER_BUFFER_SYMBOL (offset)))
> -	  {
> -	    Lisp_Object sym = PER_BUFFER_SYMBOL (offset);
> -	    Lisp_Object val = per_buffer_value (buf, offset);
> -	    result = Fcons (EQ (val, Qunbound) ? sym : Fcons (sym, val),
> -			    result);
> -	  }
> +        tem = buffer_local_variables_1 (buf, offset);
> +        if (!NILP (tem))
> +          result = Fcons (tem, result);
>        }
>    }
>  
> +  tem = buffer_local_variables_1 (buf, PER_BUFFER_VAR_OFFSET (undo_list));
> +  if (!NILP (tem))
> +    result = Fcons (tem, result);
> +
>    return result;
>  }


I was going to apply this, there having been no comments, but then I
noticed that since the advent of portable dumper (or since 978cf88 at
least), it's not completely right. It adds an entry for buffer-undo-list
to buffer-local-variables, but with key = "nil" rather than
"buffer-undo-list". Which implies that
PER_BUFFER_SYMBOL (PER_BUFFER_VAR_OFFSET (undo_list))
now returns nil instead of 'buffer-undo-list.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#33492: 27.0.50; desktop-locals-to-save won't consider buffer-undo-list as local
  2019-01-30  0:30     ` Glenn Morris
@ 2020-05-18 17:57       ` Glenn Morris
  0 siblings, 0 replies; 5+ messages in thread
From: Glenn Morris @ 2020-05-18 17:57 UTC (permalink / raw)
  To: 33492-done

Version: 28.1

No comments in over a year, so I have pushed a simple-minded fix.
I am sure someone will now fix it properly within a week.

commit 86594a3ddb
Date:   Mon May 18 10:54:14 2020 -0700

Restore buffer-undo-list to buffer-local-variables





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-18 17:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-24 20:54 bug#33492: 27.0.50; desktop-locals-to-save won't consider buffer-undo-list as local Terje Larsen
2018-11-28  1:23 ` Glenn Morris
2018-11-28 21:49   ` Glenn Morris
2019-01-30  0:30     ` Glenn Morris
2020-05-18 17:57       ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).