unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lin Sun via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 47521@debbugs.gnu.org, Glenn Morris <rgm@gnu.org>,
	Eli Zaretskii <eliz@gnu.org>, sunlin <sunlin7@yahoo.com>
Subject: bug#47521: 28.0.50; [PATCH] [image-mode] reduce calling for image-toggle-display-text
Date: Wed, 31 Mar 2021 22:47:33 +0800	[thread overview]
Message-ID: <CAKu6+JFv1-E=WWJg-3qyPDRQCXctHnwi6KNDxusRX-j92V_n9g@mail.gmail.com> (raw)
In-Reply-To: <40B0A46C-9AFD-49AF-BCDE-0B5E2CF8ED6B@hxcore.ol>

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

(Resend in text mail format.)
Hi,

When opening a png file and toggle display from image to text by C-c
C-c, the `image-toggle-display-text` will be called twice in function
`image-toggle-display-text`.
The first call is from the major mode change hook, in the following
line will cause `change-major-mode-hook` be run and it’s
`image-toggle-display-text` for image-mode.
image-mode.el:730         (major-mode-restore '(image-mode image-mode-as-text))

The second call is from the direct call at
image-mode.el:736         (image-toggle-display-text)

Try debug-on-entry on `image-toggle-display-text`, then switch image
to text in image-mode by press C-c C-c to observe the issue.

And the patch tries to reduce calling for `image-toggle-display-text`.

Best Regards
Lin Sun

[-- Attachment #2: 0001-image-mode-reduce-calling-for-image-toggle-display-t.patch --]
[-- Type: application/octet-stream, Size: 996 bytes --]

From a2af38fb056418386b709b8653f0d3677b482af9 Mon Sep 17 00:00:00 2001
From: Lin Sun <lin.sun@zoom.us>
Date: Wed, 31 Mar 2021 20:02:18 +0800
Subject: [PATCH] [image-mode] reduce calling for image-toggle-display-text

*lisp/image-mode.el: do not call the image-toggle-display-text twice
when toggle image display.
---
 lisp/image-mode.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 2de16cb..f4ff35f 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -732,8 +732,9 @@ image-mode-to-text
     (setq image-type previous-image-type)
     ;; Enable image minor mode with `C-c C-c'.
     (image-minor-mode 1)
-    ;; Show the image file as text.
-    (image-toggle-display-text)))
+    (unless (image-get-display-property)
+      ;; Show the image file as text.
+      (image-toggle-display-text))))
 
 (defun image-mode-as-hex ()
   "Set a non-image mode as major mode in combination with image minor mode.
-- 
2.7.0


  reply	other threads:[~2021-03-31 14:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 12:17 bug#47521: 28.0.50; [PATCH] [image-mode] reduce calling for image-toggle-display-text LinSun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-31 14:47 ` Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-04-05 16:12   ` Lars Ingebrigtsen

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='CAKu6+JFv1-E=WWJg-3qyPDRQCXctHnwi6KNDxusRX-j92V_n9g@mail.gmail.com' \
    --to=bug-gnu-emacs@gnu.org \
    --cc=47521@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=lin.sun@zoom.us \
    --cc=rgm@gnu.org \
    --cc=sunlin7@yahoo.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).