unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: LensPlaysGames <lensplaysgames@gmail.com>
To: emacs-devel@gnu.org
Subject: [PATCH] iimage-mode: reset point for each regexp
Date: Sun, 5 Feb 2023 13:46:20 -0800	[thread overview]
Message-ID: <CAFV8sdePKeFXreomZeF5rm=T=ph5TJko4BZvQVyGQ=Dji9cAqA@mail.gmail.com> (raw)

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

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.

[-- Attachment #2: iimage.patch --]
[-- Type: application/octet-stream, Size: 558 bytes --]

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)))

             reply	other threads:[~2023-02-05 21:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-05 21:46 LensPlaysGames [this message]
2023-02-08  7:29 ` [PATCH] iimage-mode: reset point for each regexp Juri Linkov
2023-02-08 12:57   ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='CAFV8sdePKeFXreomZeF5rm=T=ph5TJko4BZvQVyGQ=Dji9cAqA@mail.gmail.com' \
    --to=lensplaysgames@gmail.com \
    --cc=emacs-devel@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).