GNU bug report logs -
#33492
buffer-local-variables does not include buffer-undo-list
Previous Next
Reported by: Terje Larsen <terlar <at> gmail.com>
Date: Sat, 24 Nov 2018 20:55:02 UTC
Severity: normal
Tags: confirmed
Found in versions 27.0.50, 24.3
Fixed in version 28.1
Done: Glenn Morris <rgm <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 33492 in the body.
You can then email your comments to 33492 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#33492
; Package
emacs
.
(Sat, 24 Nov 2018 20:55:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Terje Larsen <terlar <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 24 Nov 2018 20:55:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#33492
; Package
emacs
.
(Wed, 28 Nov 2018 01:24:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 33492 <at> debbugs.gnu.org (full text, mbox):
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.
bug Marked as found in versions 24.3.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Wed, 28 Nov 2018 01:25:01 GMT)
Full text and
rfc822 format available.
Changed bug title to 'buffer-local-variables does not include buffer-undo-list' from '27.0.50; desktop-locals-to-save won't consider buffer-undo-list as local'
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Wed, 28 Nov 2018 01:25:01 GMT)
Full text and
rfc822 format available.
Added tag(s) confirmed.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Wed, 28 Nov 2018 01:25:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#33492
; Package
emacs
.
(Wed, 28 Nov 2018 21:50:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 33492 <at> debbugs.gnu.org (full text, mbox):
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;
}
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#33492
; Package
emacs
.
(Wed, 30 Jan 2019 00:32:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 33492 <at> debbugs.gnu.org (full text, mbox):
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.
Reply sent
to
Glenn Morris <rgm <at> gnu.org>
:
You have taken responsibility.
(Mon, 18 May 2020 17:59:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Terje Larsen <terlar <at> gmail.com>
:
bug acknowledged by developer.
(Mon, 18 May 2020 17:59:02 GMT)
Full text and
rfc822 format available.
Message #25 received at 33492-done <at> debbugs.gnu.org (full text, mbox):
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
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 16 Jun 2020 11:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 191 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.