all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 36190@debbugs.gnu.org
Subject: bug#36190: 27.0.50; `put-text-property' etc. with buffer argument calls current buffer's `after-change-functions'
Date: Sat, 6 Jul 2019 15:27:41 +0000	[thread overview]
Message-ID: <CAOqdjBcUn4+GQ_Omsx+k=fYSHVJ3KFgJf78mnMmxVv9ZcHoo_A@mail.gmail.com> (raw)
In-Reply-To: <8336jja8l2.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 612 bytes --]

On Sat, Jul 6, 2019 at 8:08 AM Eli Zaretskii <eliz@gnu.org> wrote:
> > Sounds good to me. The attached patch contains the comments and a hint
> > in the documentation. (Maybe the comments should be a FIXME, because
> > there's really no need to switch buffers at all when there are no
> > applicable hooks?)
>
> I'm okay with adding such a FIXME.

Added.


>
> > Obviously, feel free to reword as you consider appropriate.
>
> LGTM, with a couple of minor comments below.  Feel free to push after
> fixing those.

I don't have push access, so I hope it's okay just to send the new patch.

Thanks for the review!

[-- Attachment #2: 0001-Update-current-buffer-when-changing-text-properties.patch --]
[-- Type: text/x-patch, Size: 5401 bytes --]

From 7e3b17ce5704b5327b977673382688f8e7f5b4c9 Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
Date: Sat, 6 Jul 2019 15:21:04 +0000
Subject: [PATCH] Update current buffer when changing text properties.

* src/textprop.c (add_text_properties_1, set_text_properties)
(set_text_properties_1, Fremove_text_properties): Switch buffer if
necessary.

* doc/lispref/text.texi (Examining Properties): Document performance
FIXME.
---
 doc/lispref/text.texi |  2 +-
 src/textprop.c        | 66 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index c4fc5247a1..ca0dd6642d 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -2800,7 +2800,7 @@ Examining Properties
 
   These functions handle both strings and buffers.  Keep in mind that
 positions in a string start from 0, whereas positions in a buffer start
-from 1.
+from 1.  Passing a buffer other than the current buffer may be slow.
 
 @defun get-text-property pos prop &optional object
 This function returns the value of the @var{prop} property of the
diff --git a/src/textprop.c b/src/textprop.c
index 9023f4efa0..44c333256a 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -1142,6 +1142,18 @@ DEFUN ("previous-single-property-change", Fprevious_single_property_change,
 add_text_properties_1 (Lisp_Object start, Lisp_Object end,
 		       Lisp_Object properties, Lisp_Object object,
 		       enum property_set_type set_type) {
+  /* Ensure we run the modification hooks for the right buffer,
+     without switching buffers twice (bug 36190).  FIXME: Switching
+     buffers is slow and often unnecessary.  */
+  if (BUFFERP (object) && XBUFFER (object) != current_buffer)
+    {
+      ptrdiff_t count = SPECPDL_INDEX ();
+      record_unwind_current_buffer ();
+      set_buffer_internal (XBUFFER (object));
+      return unbind_to (count, add_text_properties_1 (start, end, properties,
+						      object, set_type));
+    }
+
   INTERVAL i, unchanged;
   ptrdiff_t s, len;
   bool modified = false;
@@ -1343,6 +1355,19 @@ face(s) are retained.  This is done by setting the `face' property to
 set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
 		     Lisp_Object object, Lisp_Object coherent_change_p)
 {
+  /* Ensure we run the modification hooks for the right buffer,
+     without switching buffers twice (bug 36190).  FIXME: Switching
+     buffers is slow and often unnecessary.  */
+  if (BUFFERP (object) && XBUFFER (object) != current_buffer)
+    {
+      ptrdiff_t count = SPECPDL_INDEX ();
+      record_unwind_current_buffer ();
+      set_buffer_internal (XBUFFER (object));
+      return unbind_to (count,
+			set_text_properties (start, end, properties,
+					     object, coherent_change_p));
+    }
+
   INTERVAL i;
   bool first_time = true;
 
@@ -1413,6 +1438,20 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
 set_text_properties_1 (Lisp_Object start, Lisp_Object end,
 		       Lisp_Object properties, Lisp_Object object, INTERVAL i)
 {
+  /* Ensure we run the modification hooks for the right buffer,
+     without switching buffers twice (bug 36190).  FIXME: Switching
+     buffers is slow and often unnecessary.  */
+  if (BUFFERP (object) && XBUFFER (object) != current_buffer)
+    {
+      ptrdiff_t count = SPECPDL_INDEX ();
+      record_unwind_current_buffer ();
+      set_buffer_internal (XBUFFER (object));
+
+      set_text_properties_1 (start, end, properties, object, i);
+      unbind_to (count, Qnil);
+      return;
+    }
+
   INTERVAL prev_changed = NULL;
   ptrdiff_t s = XFIXNUM (start);
   ptrdiff_t len = XFIXNUM (end) - s;
@@ -1495,6 +1534,19 @@ DEFUN ("remove-text-properties", Fremove_text_properties,
 Use `set-text-properties' if you want to remove all text properties.  */)
   (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object)
 {
+  /* Ensure we run the modification hooks for the right buffer,
+     without switching buffers twice (bug 36190).  FIXME: Switching
+     buffers is slow and often unnecessary.  */
+  if (BUFFERP (object) && XBUFFER (object) != current_buffer)
+    {
+      ptrdiff_t count = SPECPDL_INDEX ();
+      record_unwind_current_buffer ();
+      set_buffer_internal (XBUFFER (object));
+      return unbind_to (count,
+			Fremove_text_properties (start, end, properties,
+						 object));
+    }
+
   INTERVAL i, unchanged;
   ptrdiff_t s, len;
   bool modified = false;
@@ -1607,6 +1659,20 @@ DEFUN ("remove-list-of-text-properties", Fremove_list_of_text_properties,
 Return t if any property was actually removed, nil otherwise.  */)
   (Lisp_Object start, Lisp_Object end, Lisp_Object list_of_properties, Lisp_Object object)
 {
+  /* Ensure we run the modification hooks for the right buffer,
+     without switching buffers twice (bug 36190).  FIXME: Switching
+     buffers is slow and often unnecessary.  */
+  if (BUFFERP (object) && XBUFFER (object) != current_buffer)
+    {
+      ptrdiff_t count = SPECPDL_INDEX ();
+      record_unwind_current_buffer ();
+      set_buffer_internal (XBUFFER (object));
+      return unbind_to (count,
+			Fremove_list_of_text_properties (start, end,
+							 list_of_properties,
+							 object));
+    }
+
   INTERVAL i, unchanged;
   ptrdiff_t s, len;
   bool modified = false;
-- 
2.20.1


  reply	other threads:[~2019-07-06 15:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13 13:48 bug#36190: 27.0.50; `put-text-property' etc. with buffer argument calls current buffer's `after-change-functions' Pip Cet
2019-06-13 16:36 ` Eli Zaretskii
2019-06-13 18:48   ` Pip Cet
2019-06-13 19:05     ` Eli Zaretskii
2019-06-13 19:27       ` Eli Zaretskii
2019-06-13 19:42       ` Pip Cet
2019-06-13 20:01         ` Eli Zaretskii
2019-06-13 20:57           ` Pip Cet
2019-06-13 21:37             ` Pip Cet
2019-06-14  7:41               ` Eli Zaretskii
2019-06-14 11:14                 ` Pip Cet
2019-06-14 12:10                   ` Eli Zaretskii
2019-06-15 15:14                     ` Pip Cet
2019-06-15 15:23                       ` Eli Zaretskii
2019-06-15 19:27                         ` Pip Cet
2019-07-06  8:08                           ` Eli Zaretskii
2019-07-06 15:27                             ` Pip Cet [this message]
2019-07-06 16:22                               ` Eli Zaretskii
2019-06-14  7:36             ` Eli Zaretskii
2019-06-17 11:38               ` Pip Cet
2019-06-17 15:59                 ` Eli Zaretskii
2019-06-18 17:14                   ` Pip Cet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOqdjBcUn4+GQ_Omsx+k=fYSHVJ3KFgJf78mnMmxVv9ZcHoo_A@mail.gmail.com' \
    --to=pipcet@gmail.com \
    --cc=36190@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.