GNU bug report logs -
#46982
28.0.50; after-change-functions in an indirect buffer are not called if the change is done while base buffer is active (and vice versa)
Previous Next
To reply to this bug, email your comments to 46982 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Sun, 07 Mar 2021 04:33:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Ihor Radchenko <yantar92 <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 07 Mar 2021 04:33:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Steps to reproduce:
1. emacs -Q
2. M-x clone-indirect-buffer <RET>
3. M-: (setq-local after-change-functions (append after-change-functions
'((lambda (&rest _) (message "Buffer 1"))))) <RET>
4. C-x o
5. M-: (setq-local after-change-functions (append after-change-functions
'((lambda (&rest _) (message "Buffer 2"))))) <RET>
6. Type something. "Buffer 2" message is displayed. "Buffer 1" message
is _not_ displayed.
7. C-x o
8. Type something. "Buffer 1" message is displayed. "Buffer 2" message
is _not_ displayed.
Expected behaviour:
Since changes in direct buffer would automatically change text in the
indirect buffer, I expect the changes to trigger all the
after-change-functions in all the indirect buffers and the base buffer,
regardless of which buffer was active when changes were made.
The current behaviour can potentially break major modes using
after-change-functions if base buffer and indirect buffer do not have
the same major mode.
For my use-case, an after-change-function I want to implement depends on
buffer-local variable (which is set to different values in the base and
indirect buffers) and I expect it to run in both buffers. Current Emacs
behaviour leaves me with no options to handle changes made not in
current buffer, even though they do change the text in other (indirect
or base) buffer.
On the other hand, running after-change-functions in every indirect/base
buffer may lead to multiple invocations of the same function.
Maybe, Emacs can examine something like 'run-indirect symbol for each
element in after-change-functions and run the functions containing the
symbol in all the connected buffers upon change.
Best,
Ihor
In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, cairo version 1.16.0)
of 2021-02-20 built on localhost
Repository revision: 39792cf62987ecc1a772f6a2027d6b32c70e8312
Repository branch: feature/native-comp
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: Gentoo/Linux
Configured using:
'configure --prefix=/usr --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --mandir=/usr/share/man
--infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc
--localstatedir=/var/lib --disable-silent-rules
--docdir=/usr/share/doc/emacs-28.0.9999
--htmldir=/usr/share/doc/emacs-28.0.9999/html --libdir=/usr/lib64
--program-suffix=-emacs-28-vcs --includedir=/usr/include/emacs-28-vcs
--infodir=/usr/share/info/emacs-28-vcs --localstatedir=/var
--enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
--without-compress-install --without-hesiod --without-pop
--with-file-notification=inotify --with-pdumper --enable-acl
--with-dbus --with-modules --without-gameuser --with-libgmp
--without-gpm --with-json --without-kerberos --without-kerberos5
--without-lcms2 --with-xml2 --without-mailutils --with-selinux
--with-gnutls --without-libsystemd --with-threads --with-wide-int
--with-zlib --with-sound=oss --with-x --without-ns --without-gconf
--without-gsettings --without-toolkit-scroll-bars --with-gif
--with-jpeg --with-png --with-rsvg --with-tiff --with-xpm
--with-imagemagick --with-xft --with-cairo --with-harfbuzz
--without-libotf --without-m17n-flt --with-x-toolkit=no
--with-dumping=pdumper --with-nativecomp 'CFLAGS=-march=native -pipe
-O2' CPPFLAGS= 'LDFLAGS=-Wl,-O1 -Wl,--as-needed''
Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS HARFBUZZ IMAGEMAGICK JPEG
JSON LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY OLDXMENU
PDUMPER PNG RSVG SOUND THREADS TIFF X11 XDBE XIM XPM ZLIB
Important settings:
value of $LC_COLLATE: C
value of $LANG: en_US.utf8
locale-coding-system: utf-8-unix
Major mode: Lisp Interaction
Minor modes in effect:
org-edna-mode: t
eros-mode: t
pdf-occur-global-minor-mode: t
TeX-PDF-mode: t
which-key-mode: t
global-aggressive-indent-mode: t
aggressive-indent-mode: t
diredfl-global-mode: t
dired-async-mode: t
winner-mode: t
recentf-mode: t
helm-adaptive-mode: t
helm-global-mode: t
helm-mode: t
helm--remap-mouse-mode: t
async-bytecomp-package-mode: t
eval-sexp-fu-flash-mode: t
global-highlight-parentheses-mode: t
highlight-parentheses-mode: t
el-patch-use-package-mode: t
global-git-commit-mode: t
magit-auto-revert-mode: t
shell-dirtrack-mode: t
hl-todo-mode: t
pretty-symbols-mode: t
company-mode: t
persistent-scratch-autosave-mode: t
savehist-mode: t
boon-mode: t
boon-local-mode: t
global-hl-line-mode: t
global-page-break-lines-mode: t
page-break-lines-mode: t
shackle-mode: t
golden-ratio-mode: t
gcmh-mode: t
override-global-mode: t
straight-use-package-mode: t
straight-package-neutering-mode: t
global-eldoc-mode: t
eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
global-prettify-symbols-mode: t
prettify-symbols-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
window-divider-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
abbrev-mode: t
Features:
(shadow emacsbug sendmail helm-misc avy font-latex context-en context
plain-tex tex-buf ...)
Memory information:
((conses 16 32697775 2032831)
(symbols 48 96430 1)
(strings 32 2157335 426732)
(string-bytes 1 82214460)
(vectors 16 799796)
(vector-slots 8 11991333 1566948)
(floats 8 211915 16922)
(intervals 56 1417577 35086)
(buffers 992 180))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Fri, 17 Jun 2022 02:37:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 46982 <at> debbugs.gnu.org (full text, mbox):
> 1. emacs -Q
> 2. M-x clone-indirect-buffer <RET>
> 3. M-: (setq-local after-change-functions (append after-change-functions
> '((lambda (&rest _) (message "Buffer 1"))))) <RET>
> 4. C-x o
> 5. M-: (setq-local after-change-functions (append after-change-functions
> '((lambda (&rest _) (message "Buffer 2"))))) <RET>
> 6. Type something. "Buffer 2" message is displayed. "Buffer 1" message
> is _not_ displayed.
> 7. C-x o
> 8. Type something. "Buffer 1" message is displayed. "Buffer 2" message
> is _not_ displayed.
That's on purpose, yes.
> The current behaviour can potentially break major modes using
> after-change-functions if base buffer and indirect buffer do not have
> the same major mode.
It's currently the responsibility of the code that sets up the indirect
buffer(s) to setup a `before/after-change-functions` in the base buffer
that runs (some of) the `before/after-change-functions` in the indirect
buffer(s) where they are needed.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Fri, 17 Jun 2022 05:43:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 46982 <at> debbugs.gnu.org (full text, mbox):
> Cc: 46982 <at> debbugs.gnu.org
> Date: Thu, 16 Jun 2022 22:36:29 -0400
> From: Stefan Monnier via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> It's currently the responsibility of the code that sets up the indirect
> buffer(s) to setup a `before/after-change-functions` in the base buffer
> that runs (some of) the `before/after-change-functions` in the indirect
> buffer(s) where they are needed.
Do you think we should document this caveat in the ELisp manual?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Fri, 17 Jun 2022 13:31:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 46982 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii [2022-06-17 08:42:33] wrote:
>> It's currently the responsibility of the code that sets up the indirect
>> buffer(s) to setup a `before/after-change-functions` in the base buffer
>> that runs (some of) the `before/after-change-functions` in the indirect
>> buffer(s) where they are needed.
>
> Do you think we should document this caveat in the ELisp manual?
It might be a good thing to mention somewhere around
`clone-buffer`, yes. I'll see what I can come up with.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Fri, 17 Jun 2022 15:29:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 46982 <at> debbugs.gnu.org (full text, mbox):
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: yantar92 <at> gmail.com, 46982 <at> debbugs.gnu.org
> Date: Fri, 17 Jun 2022 09:29:54 -0400
>
> Eli Zaretskii [2022-06-17 08:42:33] wrote:
> >> It's currently the responsibility of the code that sets up the indirect
> >> buffer(s) to setup a `before/after-change-functions` in the base buffer
> >> that runs (some of) the `before/after-change-functions` in the indirect
> >> buffer(s) where they are needed.
> >
> > Do you think we should document this caveat in the ELisp manual?
>
> It might be a good thing to mention somewhere around
> `clone-buffer`, yes. I'll see what I can come up with.
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Tue, 21 Jun 2022 20:22:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 46982 <at> debbugs.gnu.org (full text, mbox):
> It might be a good thing to mention somewhere around
> `clone-buffer`, yes. I'll see what I can come up with.
Hmm... we don't document `clone-buffer` anywhere that I can see.
Any suggestion where I could put that kind of info?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Tue, 21 Jun 2022 23:28:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 46982 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> It might be a good thing to mention somewhere around
>> `clone-buffer`, yes. I'll see what I can come up with.
>
> Hmm... we don't document `clone-buffer` anywhere that I can see.
> Any suggestion where I could put that kind of info?
`clone-indirect-buffer' I think. For example, in 19.6 Indirect Buffers
section of the manual.
Best,
Ihor
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Wed, 22 Jun 2022 02:37:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 46982 <at> debbugs.gnu.org (full text, mbox):
> From: Ihor Radchenko <yantar92 <at> gmail.com>
> Cc: Eli Zaretskii <eliz <at> gnu.org>, 46982 <at> debbugs.gnu.org
> Date: Wed, 22 Jun 2022 07:29:05 +0800
>
> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>
> >> It might be a good thing to mention somewhere around
> >> `clone-buffer`, yes. I'll see what I can come up with.
> >
> > Hmm... we don't document `clone-buffer` anywhere that I can see.
> > Any suggestion where I could put that kind of info?
>
> `clone-indirect-buffer' I think. For example, in 19.6 Indirect Buffers
> section of the manual.
Yes, there, please.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Wed, 22 Jun 2022 23:53:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 46982 <at> debbugs.gnu.org (full text, mbox):
>> Hmm... we don't document `clone-buffer` anywhere that I can see.
>> Any suggestion where I could put that kind of info?
> `clone-indirect-buffer' I think.
Duh! I need more sleep, sorry,
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Wed, 29 Jun 2022 15:20:01 GMT)
Full text and
rfc822 format available.
Message #32 received at 46982 <at> debbugs.gnu.org (full text, mbox):
>> >> It might be a good thing to mention somewhere around
>> >> `clone-buffer`, yes. I'll see what I can come up with.
>> > Hmm... we don't document `clone-buffer` anywhere that I can see.
>> > Any suggestion where I could put that kind of info?
>> `clone-indirect-buffer' I think. For example, in 19.6 Indirect Buffers
>> section of the manual.
> Yes, there, please.
How does the patch below sound to you?
Stefan
diff --git a/doc/emacs/buffers.texi b/doc/emacs/buffers.texi
index 94e9d2760ec..c07f3990ee8 100644
--- a/doc/emacs/buffers.texi
+++ b/doc/emacs/buffers.texi
@@ -616,10 +616,11 @@ Indirect Buffers
The text of the indirect buffer is always identical to the text of its
base buffer; changes made by editing either one are visible immediately
-in the other. But in all other respects, the indirect buffer and its
+in the other. ``Text'' here includes both the characters and their text
+properties. But in all other respects, the indirect buffer and its
base buffer are completely separate. They can have different names,
different values of point, different narrowing, different markers,
-different major modes, and different local variables.
+different overlays, different major modes, and different local variables.
An indirect buffer cannot visit a file, but its base buffer can. If
you try to save the indirect buffer, that actually works by saving the
@@ -649,6 +650,14 @@ Indirect Buffers
When this hook runs, the newly created indirect buffer is the current
buffer.
+Note: When a modification is made to the text of a buffer, the
+modification hooks are only run in the base buffer, because most of
+the functions on those hooks are not prepared to work correctly in
+indirect buffers. So if you need a modification hook function in an
+indirect buffer, you need to manually add that function to the hook
+@emph{in the base buffer} and then make the function operate in the
+desired indirect buffer.
+
@node Buffer Convenience
@section Convenience Features and Customization of Buffer Handling
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Wed, 29 Jun 2022 16:09:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 46982 <at> debbugs.gnu.org (full text, mbox):
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Ihor Radchenko <yantar92 <at> gmail.com>, 46982 <at> debbugs.gnu.org
> Date: Wed, 29 Jun 2022 11:19:37 -0400
>
> >> >> It might be a good thing to mention somewhere around
> >> >> `clone-buffer`, yes. I'll see what I can come up with.
> >> > Hmm... we don't document `clone-buffer` anywhere that I can see.
> >> > Any suggestion where I could put that kind of info?
> >> `clone-indirect-buffer' I think. For example, in 19.6 Indirect Buffers
> >> section of the manual.
> > Yes, there, please.
>
> How does the patch below sound to you?
LGTM, thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Wed, 29 Jun 2022 17:17:01 GMT)
Full text and
rfc822 format available.
Message #38 received at 46982 <at> debbugs.gnu.org (full text, mbox):
>> How does the patch below sound to you?
> LGTM, thanks.
IIUC 28.2 is super-near so I assume I should only push this to
`master`, right? Or should I wait for 28.2 and then push to `emacs-28`?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Wed, 29 Jun 2022 17:31:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 46982 <at> debbugs.gnu.org (full text, mbox):
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: yantar92 <at> gmail.com, 46982 <at> debbugs.gnu.org
> Date: Wed, 29 Jun 2022 13:16:15 -0400
>
> >> How does the patch below sound to you?
> > LGTM, thanks.
>
> IIUC 28.2 is super-near so I assume I should only push this to
> `master`, right? Or should I wait for 28.2 and then push to `emacs-28`?
You can install on the emacs-28 branch now.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46982
; Package
emacs
.
(Wed, 29 Jun 2022 17:43:02 GMT)
Full text and
rfc822 format available.
Message #44 received at 46982 <at> debbugs.gnu.org (full text, mbox):
> You can install on the emacs-28 branch now.
Done, thanks,
Stefan
This bug report was last modified 3 years and 83 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.