From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] iimage-mode: reset point for each regexp Date: Wed, 08 Feb 2023 09:29:37 +0200 Organization: LINKOV.NET Message-ID: <86ttzw1wji.fsf@mail.linkov.net> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34580"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: LensPlaysGames , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Feb 08 08:37:24 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pPf19-0008pM-Kl for ged-emacs-devel@m.gmane-mx.org; Wed, 08 Feb 2023 08:37:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPf0H-0002iy-R8; Wed, 08 Feb 2023 02:36:29 -0500 Original-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 1pPf0G-0002iG-E3 for emacs-devel@gnu.org; Wed, 08 Feb 2023 02:36:28 -0500 Original-Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPf0D-0007ZH-8P; Wed, 08 Feb 2023 02:36:28 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id BCBE41BF205; Wed, 8 Feb 2023 07:36:18 +0000 (UTC) In-Reply-To: (lensplaysgames@gmail.com's message of "Sun, 5 Feb 2023 13:46:20 -0800") Received-SPF: pass client-ip=2001:4b98:dc4:8::228; envelope-from=juri@linkov.net; helo=relay8-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:303047 Archived-At: > When creating a minor mode that would replace certain regexp matches > with inline images, I was glad to find iimage-mode already existed to > make this process easier; better yet, it's built in to Emacs core. > However, upon customising the functionality of this mode, by altering > iimage-mode-image-regex-alist to contain more than one item, I found > an interesting quirk of the mode's behaviour. If a regular expression > early in the list matched late in the buffer, then regular expression > matches later in the list would no longer replace matches early in the > buffer. I didn't expect the alist to have such strict ordering, and > I'm not sure if that's intentional, especially as the defaults have > only one element in this alist. > > When peering at the source code, I didn't notice any documentation > indicating that this behaviour is expected. I also noticed the cause > of this behaviour: '(goto-char (point-min))' is used outside of the > 'dolist' iteration that loops over regular expressions to match, which > means that each regexp search begins at the end of the last... By > moving this goto-char call one line down, within the 'dolist' body, > each regexp search begins at, well, the beginning. This gives expected > behaviour in my minor mode (such that an alphabetized list of exact > matches can have all occurrences replaced with inline images in a > buffer). If this behaviour is intended, feel free to ignore this post. > > Attached is a patch generated with git that implements the above change. Thanks for the bug report. I'm using iimage-mode-image-regex-alist with a single composite regexp, so I never noticed this problem. Eli, is it ok to push this fix to the emacs-29 branch? > diff --git a/lisp/iimage.el b/lisp/iimage.el > index 96ab963bff..053eb27db7 100644 > --- a/lisp/iimage.el > +++ b/lisp/iimage.el > @@ -112,8 +112,8 @@ Examples of image filename patterns to match: > file) > (with-silent-modifications > (save-excursion > - (goto-char (point-min)) > (dolist (pair iimage-mode-image-regex-alist) > + (goto-char (point-min)) > (while (re-search-forward (car pair) nil t) > (when (and (setq file (match-string (cdr pair))) > (setq file (locate-file file image-path)))