unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Rahguzar via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 69785@debbugs.gnu.org
Subject: bug#69785: 29.2; Image mode can loop due to invalid images
Date: Fri, 22 Mar 2024 18:24:09 +0100	[thread overview]
Message-ID: <87wmpudvqy.fsf@zohomail.eu> (raw)
In-Reply-To: <86cyrn3n23.fsf@gnu.org>

Hi Eli,
   The patch fixes the problem.

Thanks,
Rahguzar

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Wed, 13 Mar 2024 22:13:55 +0100
>> From:  Rahguzar via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>>
>>
>> Dear Emacs developers,
>>
>> Starting with emacs -Q, evaluate
>>
>> (with-current-buffer (get-buffer-create "*image-mode-test*")
>>   (insert (propertize "abc" 'display (list 'image "Definitely not an image.")))
>>   (image-mode))
>>
>> twice.
>>
>> The second time results in an error and pop ups the debugger, with the
>> following text,
>>
>> Debugger entered--Lisp error: (excessive-lisp-nesting 1601)
>>   display-images-p()
>>   image-mode()
>>   major-mode-restore((image-mode image-mode-as-text))
>>   image-mode-to-text()
>>   image-mode-as-text()
>>   image-mode--display()
>>   image-mode()
>>   major-mode-restore((image-mode image-mode-as-text))
>>   image-mode-to-text()
>>   image-mode-as-text()
>>   image-mode--display()
>>   image-mode()
>>   major-mode-restore((image-mode image-mode-as-text))
>>   image-mode-to-text()
>>   image-mode-as-text()
>>   image-mode--display()
>>   image-mode()
>>   ...
>>
>> It is unclear to me why this doesn't happen the first time but I think
>> sequence causing it the second time is as follows:
>>
>> 1. 'image-mode' calls 'major-mode-suspend' when 'major' mode is
>> 'fundamental-mode'. So 'major-mode--suspended' is not set.
>>
>> 2. 'image-mode--display' catches error and call 'image-mode-as-text'
>> which calls 'image-mode-to-text'.
>>
>> 3. 'image-mode-as-text' calls 'major-mode-restore' with '(image-mode
>> image-mode-as-text) as mode to avoid.
>>
>> 4. Since major-mode--suspended was not set in step 1
>> 'major-mode-restore' falls back to 'normal-mode' which calls
>> 'image-mode' causing the loop.
>>
>> I think the simplest way of fixing this is to make sure that
>> 'image-mode' doesn't call 'major-mode-suspend' with 'fundamental-mode'
>> instead calling 'text-mode' or 'special-mode' before calling
>> 'major-mode-suspend' if it starts in 'fundamental-mode'.
>
> How about the patch below instead?
>
> diff --git a/lisp/image-mode.el b/lisp/image-mode.el
> index 355685e..fa64f1a 100644
> --- a/lisp/image-mode.el
> +++ b/lisp/image-mode.el
> @@ -654,8 +654,9 @@ image-mode
>    (unless (display-images-p)
>      (error "Display does not support images"))
>
> -  (major-mode-suspend)
> -  (setq major-mode 'image-mode)
> +  (unless (eq major-mode 'image-mode)
> +    (major-mode-suspend)
> +    (setq major-mode 'image-mode))
>    (setq image-transform-resize image-auto-resize)
>
>    ;; Bail out early if we have no image data.





  reply	other threads:[~2024-03-22 17:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 21:13 bug#69785: 29.2; Image mode can loop due to invalid images Rahguzar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-21 10:18 ` Eli Zaretskii
2024-03-22 17:24   ` Rahguzar via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-03-23  7:53     ` 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=87wmpudvqy.fsf@zohomail.eu \
    --to=bug-gnu-emacs@gnu.org \
    --cc=69785@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rahguzar@zohomail.eu \
    /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).