unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: Mikhail P <mikpom@fastmail.com>, 45256@debbugs.gnu.org
Subject: bug#45256: Viewing images over network using TRAMP (errors and unexpected prompts)
Date: Thu, 17 Dec 2020 23:59:55 +0200	[thread overview]
Message-ID: <87mtycgkkk.fsf@mail.linkov.net> (raw)
In-Reply-To: <87czz8zusu.fsf@gmx.de> (Michael Albinus's message of "Thu, 17 Dec 2020 09:44:01 +0100")

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

>> The simplest solution is just to increase the number of seconds
>> in the user option 'image-auto-resize-on-window-resize'
>> proportionally to network latency.
>
> That's a global variable, right? So you would also delay resizing of
> images located locally.

Right, but disabling image-auto-resize-on-window-resize to nil in init file
will help as a temporary measure until this problem is properly fixed
for slow connections.

>> Locking could be implemented as well.  How would be better to do this?
>> Maybe by using a buffer-local variable?
>
> Yes. Something like
>
> (defvar image-fit-to-window-lock nil
>   "Lock for `image-fit-to-window' timer."
>
> (defun image-fit-to-window (window)
>   "..."
>   (unless image-fit-to-window-lock
>     (unwind-protect
> 	(progn
> 	  (setq-local image-fit-to-window-lock t)
> 	  ...)
>       (setq image-fit-to-window-lock nil))))
>
>
> There's also another thread. When image-fit-to-window is called from
> Emacs the first time, there could also be a running Tramp operation,
> which would be disturbed. See the recent discussion about "Tramp and
> timers" in the emacs-devel ML. Tramp would detect this situation, and
> fire the (new) error remote-file-error. This must also be handled, like
>
> (defun image-fit-to-window (window)
>   "..."
>   (ignore-error 'remote-file-error
>     ...))

Additionally to these changes, I also added canceling the previous timer
before starting a new timer to avoid several simultaneously started timers.
This improved responsiveness in non-remote case.  In remote case it helps
a little too, but still needs the lock for extremely slow connections.
Here is a complete patch (BTW, I'm not sure if the check for file-remote-p
can be removed now):


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: image-fit-to-window-lock.patch --]
[-- Type: text/x-diff, Size: 2478 bytes --]

diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 032ebf3873..a5b610745c 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -795,7 +795,7 @@ image-toggle-display-image
   (let* ((filename (buffer-file-name))
 	 (data-p (not (and filename
 			   (file-readable-p filename)
-			   (not (file-remote-p filename))
+			   (not (file-remote-p filename)) ; TODO: remove?
 			   (not (buffer-modified-p))
 			   (not (and (boundp 'archive-superior-buffer)
 				     archive-superior-buffer))
@@ -942,6 +942,9 @@ image-after-revert-hook
           (get-buffer-window-list (current-buffer) 'nomini 'visible))
     (image-toggle-display-image)))
 
+(defvar image-auto-resize-timer nil
+  "Timer for `image-auto-resize-on-window-resize' option.")
+
 (defun image--window-state-change (window)
   ;; Wait for a bit of idle-time before actually performing the change,
   ;; so as to batch together sequences of closely consecutive size changes.
@@ -950,8 +953,15 @@ image--window-state-change
   ;; consecutive calls happen without any redisplay between them,
   ;; the costly operation of image resizing should happen only once.
   (when (numberp image-auto-resize-on-window-resize)
-    (run-with-idle-timer image-auto-resize-on-window-resize nil
-                         #'image-fit-to-window window)))
+    (when image-auto-resize-timer
+      (cancel-timer image-auto-resize-timer)
+      (setq image-auto-resize-timer nil))
+    (setq image-auto-resize-timer
+          (run-with-idle-timer image-auto-resize-on-window-resize nil
+                               #'image-fit-to-window window))))
+
+(defvar image-fit-to-window-lock nil
+  "Lock for `image-fit-to-window' timer function.")
 
 (defun image-fit-to-window (window)
   "Adjust size of image to display it exactly in WINDOW boundaries."
@@ -968,7 +978,13 @@ image-fit-to-window
               (when (and image-width image-height
                          (or (not (= image-width  window-width))
                              (not (= image-height window-height))))
-                (image-toggle-display-image)))))))))
+                (unless image-fit-to-window-lock
+                  (unwind-protect
+                      (progn
+                        (setq-local image-fit-to-window-lock t)
+                        (ignore-error 'remote-file-error
+                          (image-toggle-display-image)))
+                    (setq image-fit-to-window-lock nil)))))))))))
 
 \f
 ;;; Animated images

  reply	other threads:[~2020-12-17 21:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 12:17 bug#45256: Viewing images over network using TRAMP (errors and unexpected prompts) Mikhail P
2020-12-16  9:08 ` Michael Albinus
2020-12-16 20:52   ` Juri Linkov
2020-12-17  8:44     ` Michael Albinus
2020-12-17 21:59       ` Juri Linkov [this message]
2020-12-18  8:05         ` Michael Albinus
2020-12-18  8:29           ` Juri Linkov
2020-12-18  9:58             ` Michael Albinus
2020-12-19 20:19               ` Juri Linkov
2020-12-22 14:49                 ` Mikhail Pomaznoy

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=87mtycgkkk.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=45256@debbugs.gnu.org \
    --cc=michael.albinus@gmx.de \
    --cc=mikpom@fastmail.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).