unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47521: 28.0.50; [PATCH] [image-mode] reduce calling for image-toggle-display-text
@ 2021-03-31 12:17 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
  0 siblings, 1 reply; 3+ messages in thread
From: LinSun via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-03-31 12:17 UTC (permalink / raw)
  To: 47521

[-- Attachment #1: Type: text/html, Size: 2275 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#47521: 28.0.50; [PATCH] [image-mode] reduce calling for image-toggle-display-text
  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
  2021-04-05 16:12   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-03-31 14:47 UTC (permalink / raw)
  To: 47521, Glenn Morris, Eli Zaretskii, sunlin

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#47521: 28.0.50; [PATCH] [image-mode] reduce calling for image-toggle-display-text
  2021-03-31 14:47 ` Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-04-05 16:12   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2021-04-05 16:12 UTC (permalink / raw)
  To: Lin Sun; +Cc: Glenn Morris, 47521, sunlin

Lin Sun <lin.sun@zoom.us> writes:

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

Thanks; applied to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-05 16:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-04-05 16:12   ` Lars Ingebrigtsen

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