From unknown Fri Jun 20 05:34:46 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#77221 <77221@debbugs.gnu.org> To: bug#77221 <77221@debbugs.gnu.org> Subject: Status: [PATCH] modification hooks are called 3x for each yank Reply-To: bug#77221 <77221@debbugs.gnu.org> Date: Fri, 20 Jun 2025 12:34:46 +0000 retitle 77221 [PATCH] modification hooks are called 3x for each yank reassign 77221 emacs submitter 77221 JD Smith severity 77221 normal tag 77221 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Mar 23 18:14:30 2025 Received: (at submit) by debbugs.gnu.org; 23 Mar 2025 22:14:30 +0000 Received: from localhost ([127.0.0.1]:52953 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1twTaQ-0000BX-2D for submit@debbugs.gnu.org; Sun, 23 Mar 2025 18:14:30 -0400 Received: from lists.gnu.org ([2001:470:142::17]:37928) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1twTaN-0000BG-8Q for submit@debbugs.gnu.org; Sun, 23 Mar 2025 18:14:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1twTaF-0000yi-OV for bug-gnu-emacs@gnu.org; Sun, 23 Mar 2025 18:14:19 -0400 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1twTaD-0003EA-Ov for bug-gnu-emacs@gnu.org; Sun, 23 Mar 2025 18:14:19 -0400 Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-3d43c972616so9701435ab.0 for ; Sun, 23 Mar 2025 15:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742768055; x=1743372855; darn=gnu.org; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=kLetKmDSOYTdpqAFRUpwwffNeZbKvL+5d9ugd2n+KLo=; b=IkP1O7kL3fYq7lUxG0pJGg9N+6+xiPMB3pjrprDfinwgKINUrNnTTMEx9LGqDrJohm 7MYWFGpIu3Lff4H6sO5/TpTaljNRKxxSacc9tCQ1rT7E1zBSQL/x79FHp8KXzHc7mQh4 Y/qOUQ9igyBx2uhR+4U+nByOlax0roBWJYdKkzON2AWRSWAj4kPiCuMSEOMgU94Io7kJ zaDjHOqwg1+0PJubnJMDzfRsZAtUyTj9AhNpnxkShJGeEsSQH1W5StjrAKEKk46xtsCo OmEaroTQRIIQz5SImoPtUw4oAzstE8JkIi9x0ayeJSKf4nEf5VxpV53zTt2nQuOaNlhk ZTOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742768055; x=1743372855; h=to:date:message-id:subject:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=kLetKmDSOYTdpqAFRUpwwffNeZbKvL+5d9ugd2n+KLo=; b=OaFKh+4ge40gIaZrcb38xFTe8N9jWspYrZhQl+2x0jkyXgh9SIDCmrnyYL6qT87nID eYrEJxvSLkklxlyao2AsrP/t8U8q5MdYil5AWjn9XdgWqgX9FWPWDBSeVpFFjWTuHF0j 28LHoCsEGFM1gw9oI3DdCbwYQBvKClgf57Y3IYIRqQXvkRq65AoGK5vgSAY26hkXa49I 295WZU1vWYcwm5/J7KMWf0vBwWzTaaNnSTJKU75qHc9329QiCb6Qh0tbh2nQiOLvg5NE 3NHFDlK4jv27iM9NXcj38I+xt3cMT4bnDCd7/fzAZURIA3VBTmLybyBev+ZadXmaPhYw 6Kmg== X-Gm-Message-State: AOJu0Yzpbi+ovoYSPQHd6oES9wnPyOl4B/IEb3CimZ7s5m9l9g9kETqt SeLIKOh+yU4VpJ0zX0irr8GKeUNpU79ZaVFvcgT5iMZDpVm/mTAUPA9dyQ== X-Gm-Gg: ASbGncu7YcezuMoQDt0KSApb6GV3GXL02LoJTVjeAFGfWYzKmcsGwHswhXl2Jw/385K er05LCDvN9ooCkGq0JJzNUfebt2QLpBZnFPaRmI4t4FuQdcjKFhzJuv6qBmFrNh4A6XYDaWlG58 uSTNWvRQ2354/6j6xxYe1Qxx44bqlqqOsK7b2EXSSkGc3W1yDs2fpDeKZjDYN2oC2CFfnUQseHE WzN8h0DfFJEt4UKlpqTMW8lvJh6aLig5AcQzuVxvzgLNpTpSRS/XRlsZzakYQZoKaoEzGATreX9 DIh0vqAr5VMKxcxFyY2mNs8Hnr4x07isEUVBTjjcpM5YgretT+eerEOSe5l9oQz6frdJKfYorOt e1Lr6lAkcncAhc8He X-Google-Smtp-Source: AGHT+IHwb/qqGbgcYEe8Dpiwyyk5ia/+SEa6ZQQNMTTo4UxMpuocbKyXOdABwAfystI4BfMVD6HYNQ== X-Received: by 2002:a05:6e02:9d:b0:3d4:44:958a with SMTP id e9e14a558f8ab-3d595edd857mr108160325ab.3.1742768054972; Sun, 23 Mar 2025 15:14:14 -0700 (PDT) Received: from smtpclient.apple (cm-24-53-185-196.buckeyecom.net. [24.53.185.196]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3d5960f108asm14916445ab.71.2025.03.23.15.14.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Mar 2025 15:14:14 -0700 (PDT) From: JD Smith Content-Type: multipart/mixed; boundary="Apple-Mail=_9A275733-6DBC-46A1-8F90-54435E93CFF6" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\)) Subject: [PATCH] modification hooks are called 3x for each yank Message-Id: <5895689B-8F41-475A-B0A4-CF815EF154DD@gmail.com> Date: Sun, 23 Mar 2025 18:14:03 -0400 To: bug-gnu-emacs@gnu.org X-Mailer: Apple Mail (2.3826.400.131.1.6) Received-SPF: pass client-ip=2607:f8b0:4864:20::130; envelope-from=jdtsmith@gmail.com; helo=mail-il1-x130.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --Apple-Mail=_9A275733-6DBC-46A1-8F90-54435E93CFF6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Evaluate: (add-hook 'after-change-functions (lambda (beg end len) (message "GOT = %s->%s [%s]" beg end len)) nil t) Then yank text. You'll see the before/after change functions are called = 3x upon each yank. This is due to the final text property changes made = by `insert-for-yank-1'. For substantial amounts of yanked text, this is = inefficient. =20 Patch attached. --Apple-Mail=_9A275733-6DBC-46A1-8F90-54435E93CFF6 Content-Disposition: attachment; filename=0001-Limit-yanks-to-a-single-set-of-modification-hook-cal.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Limit-yanks-to-a-single-set-of-modification-hook-cal.patch" Content-Transfer-Encoding: quoted-printable =46rom=20c6263834d480aa5b2490c65756e5bb875fdd5d21=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20JD=20Smith=20= <93749+jdtsmith@users.noreply.github.com>=0ADate:=20Sun,=2023=20Mar=20= 2025=2018:02:54=20-0400=0ASubject:=20[PATCH]=20Limit=20yanks=20to=20a=20= single=20set=20of=20modification=20hook=20calls=0A=0A*=20lisp/subr.el=20= (insert-for-yank-1):=20Locally=20set=0A`inhibit-modification-hooks'=20to=20= t=20prior=20to=20change=20yanked=20text=0Aproperties.=0A---=0A=20= lisp/subr.el=20|=208=20+++++---=0A=201=20file=20changed,=205=20= insertions(+),=203=20deletions(-)=0A=0Adiff=20--git=20a/lisp/subr.el=20= b/lisp/subr.el=0Aindex=2037a3f9efe6b..1c16cf4b078=20100644=0A---=20= a/lisp/subr.el=0A+++=20b/lisp/subr.el=0A@@=20-4585,6=20+4585,7=20@@=20= insert-for-yank-1=0A=20=09=20(param=20(or=20(nth=201=20handler)=20= string))=0A=20=09=20(opoint=20(point))=0A=20=09=20(inhibit-read-only=20= inhibit-read-only)=0A+=20=20=20=20=20=20=20=20=20= (inhibit-modification-hooks=20inhibit-modification-hooks)=0A=20=09=20= end)=0A=20=0A=20=20=20=20=20;;=20FIXME:=20This=20throws=20away=20any=20= yank-undo-function=20set=20by=20previous=20calls=0A@@=20-4595,9=20= +4596,10=20@@=20insert-for-yank-1=0A=20=20=20=20=20=20=20(insert=20= param))=0A=20=20=20=20=20(setq=20end=20(point))=0A=20=0A-=20=20=20=20;;=20= Prevent=20read-only=20properties=20from=20interfering=20with=20the=0A-=20= =20=20=20;;=20following=20text=20property=20changes.=0A-=20=20=20=20= (setq=20inhibit-read-only=20t)=0A+=20=20=20=20;;=20Prevent=20read-only=20= properties=20from=20interfering=20with=20the=20following=0A+=20=20=20=20= ;;=20text=20property=20changes,=20and=20inhibit=20further=20modification=20= hook=0A+=20=20=20=20;;=20calls.=0A+=20=20=20=20(setq=20inhibit-read-only=20= t=20inhibit-modification-hooks=20t)=0A=20=0A=20=20=20=20=20(unless=20= (nth=202=20handler)=20;=20NOEXCLUDE=0A=20=20=20=20=20=20=20= (remove-yank-excluded-properties=20opoint=20end))=0A--=20=0A2.48.1=0A=0A= --Apple-Mail=_9A275733-6DBC-46A1-8F90-54435E93CFF6--