unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: LensPlaysGames <lensplaysgames@gmail.com>,  emacs-devel@gnu.org
Subject: Re: [PATCH] iimage-mode: reset point for each regexp
Date: Wed, 08 Feb 2023 09:29:37 +0200	[thread overview]
Message-ID: <86ttzw1wji.fsf@mail.linkov.net> (raw)
In-Reply-To: <CAFV8sdePKeFXreomZeF5rm=T=ph5TJko4BZvQVyGQ=Dji9cAqA@mail.gmail.com> (lensplaysgames@gmail.com's message of "Sun, 5 Feb 2023 13:46:20 -0800")

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



  reply	other threads:[~2023-02-08  7:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-05 21:46 [PATCH] iimage-mode: reset point for each regexp LensPlaysGames
2023-02-08  7:29 ` Juri Linkov [this message]
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=86ttzw1wji.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=lensplaysgames@gmail.com \
    /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).