From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#45256: Viewing images over network using TRAMP (errors and unexpected prompts) Date: Thu, 17 Dec 2020 23:59:55 +0200 Organization: LINKOV.NET Message-ID: <87mtycgkkk.fsf@mail.linkov.net> References: <461b6a4f-9709-c71b-0ec3-f70d08674c9e@fastmail.com> <87360615l3.fsf@gmx.de> <87zh2djyc2.fsf@mail.linkov.net> <87czz8zusu.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36625"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: Mikhail P , 45256@debbugs.gnu.org To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 17 23:13:13 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kq1WL-0009Q0-AD for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Dec 2020 23:13:13 +0100 Original-Received: from localhost ([::1]:40392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kq1WK-000050-BK for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Dec 2020 17:13:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kq1WB-0008V5-Me for bug-gnu-emacs@gnu.org; Thu, 17 Dec 2020 17:13:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kq1WA-0002aK-6X for bug-gnu-emacs@gnu.org; Thu, 17 Dec 2020 17:13:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kq1WA-0000MW-2p for bug-gnu-emacs@gnu.org; Thu, 17 Dec 2020 17:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 17 Dec 2020 22:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45256 X-GNU-PR-Package: emacs Original-Received: via spool by 45256-submit@debbugs.gnu.org id=B45256.16082431581337 (code B ref 45256); Thu, 17 Dec 2020 22:13:02 +0000 Original-Received: (at 45256) by debbugs.gnu.org; 17 Dec 2020 22:12:38 +0000 Original-Received: from localhost ([127.0.0.1]:37230 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kq1Vm-0000LU-7a for submit@debbugs.gnu.org; Thu, 17 Dec 2020 17:12:38 -0500 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:37619) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kq1Vi-0000Kq-Fb for 45256@debbugs.gnu.org; Thu, 17 Dec 2020 17:12:35 -0500 Original-Received: from mail.gandi.net (m91-129-99-98.cust.tele2.ee [91.129.99.98]) (Authenticated sender: juri@linkov.net) by relay11.mail.gandi.net (Postfix) with ESMTPSA id E9D59100003; Thu, 17 Dec 2020 22:12:26 +0000 (UTC) In-Reply-To: <87czz8zusu.fsf@gmx.de> (Michael Albinus's message of "Thu, 17 Dec 2020 09:44:01 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:196294 Archived-At: --=-=-= Content-Type: text/plain >> 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): --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=image-fit-to-window-lock.patch 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))))))))))) ;;; Animated images --=-=-=--