From: Michael Albinus Date: Tue, 4 Jul 2023 13:27:03 +0000 (+0200) Subject: Apply remote-file-name-access-timeout in desktop.el and recentf.el X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b34f9a44393a331c866268d93b16ad69567a3cd4;p=emacs.git Apply remote-file-name-access-timeout in desktop.el and recentf.el * doc/emacs/files.texi (File Conveniences): * doc/emacs/misc.texi (Saving Emacs Sessions): Mention remote-file-name-access-timeout. * doc/misc/tramp.texi (Frequently Asked Questions): Add note. * etc/NEWS: Explain use of 'remote-file-name-access-timeout' in desktop.el and recentf.el. * lisp/desktop.el (desktop-access-file): New defun. (desktop-restore-file-buffer): Use it. * lisp/recentf.el (recentf-access-file): New defun. (recentf-keep-default-predicate): Use it. * lisp/net/tramp.el (tramp-handle-access-file): Improve error handling. --- diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 74315a05bbd..43140f5da0f 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -2255,6 +2255,12 @@ to visit one of these files. @kbd{M-x recentf-save-list} saves the current @code{recentf-list} to a file, and @kbd{M-x recentf-edit-list} edits it. +@vindex remote-file-name-access-timeout + If you use remote files, you might also consider to customize +@code{remote-file-name-access-timeout} to a proper value (number of +seconds), after which time a check whether a remote file shall be used +in Recentf is stopped. This prevents Emacs to be blocked. + @c FIXME partial-completion-mode (complete.el) is obsolete. The @kbd{M-x ffap} command generalizes @code{find-file} with more powerful heuristic defaults (@pxref{FFAP}), often based on the text at diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 37da6b5956d..042829002db 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -2812,9 +2812,13 @@ frame parameters you don't want to be restored; they will then be set according to your customizations in the init file. @vindex desktop-files-not-to-save +@vindex remote-file-name-access-timeout Information about buffers visiting remote files is not saved by default. Customize the variable @code{desktop-files-not-to-save} to -change this. +change this. In this case, you might also consider to customize +@code{remote-file-name-access-timeout} to a proper value (number of +seconds), after which time a buffer restoration of a remote file is +stopped. This prevents Emacs to be blocked. @vindex desktop-restore-eager By default, all the buffers in the desktop are restored in one go. diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index a965dd89e71..890d4c0c07a 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -5181,6 +5181,11 @@ If the connection to the remote host isn't established yet, and if this requires an interactive password, the timeout check doesn't work properly. +@c Since Emacs 30. +@strong{Note}: In recent versions of Emacs, both packages apply +already this check. You just need to customize +@code{remote-file-name-access-timeout}. + @item Does @value{tramp} support @acronym{SSH} security keys? diff --git a/etc/NEWS b/etc/NEWS index ad9ce9114c8..be2327c5a8d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -454,6 +454,24 @@ which makes them visually distinct from subroutine prototypes. CPerl mode supports the new keywords for exception handling and the object oriented syntax which were added in Perl 5.36 and 5.38. +** Emacs Sessions (Desktop) + ++++ +*** Restoring buffers with remote files should not block. +When a buffer is restored which uses a remote file, the user option +'remote-file-name-access-timeout' could be set to a positive number. +This value will be used as timeout (in seconds) for checking, whether +the remote file is accessible. + +** Recentf + ++++ +*** Checking recent remote files should not block. +When a a remote file is checked in 'recentf-list', the user option +'remote-file-name-access-timeout' could be set to a positive number. +This value will be used as timeout (in seconds) for checking, whether +the remote file is accessible. + * New Modes and Packages in Emacs 30.1 diff --git a/lisp/desktop.el b/lisp/desktop.el index 6aacb85c12c..cb5cbbd1ef2 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el @@ -1499,6 +1499,11 @@ This function is called from `window-configuration-change-hook'." (desktop-clear) (desktop-read desktop-dirname)) +;; ---------------------------------------------------------------------------- +(defun desktop-access-file (filename) + "Check whether FILENAME is accessible." + (ignore-errors (not (access-file filename "Restoring desktop buffer")))) + (defvar desktop-buffer-major-mode) (defvar desktop-buffer-locals) (defvar auto-insert) ; from autoinsert.el @@ -1508,8 +1513,8 @@ This function is called from `window-configuration-change-hook'." _buffer-misc) "Restore a file buffer." (when buffer-filename - (if (or (file-exists-p buffer-filename) - (let ((msg (format "Desktop: File \"%s\" no longer exists." + (if (or (desktop-access-file buffer-filename) + (let ((msg (format "Desktop: File \"%s\" no longer accessible." buffer-filename))) (if desktop-missing-file-warning (y-or-n-p (concat msg " Re-create buffer? ")) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 39e70e99fa7..b8345dcff49 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3993,9 +3993,14 @@ Let-bind it when necessary.") (with-parsed-tramp-file-name filename v (with-tramp-timeout (timeout + (unless (when-let ((p (tramp-get-connection-process v))) + (and (process-live-p p) + (tramp-get-connection-property p "connected"))) + (tramp-cleanup-connection v 'keep-debug 'keep-password)) (tramp-error v 'file-error - (format "%s: Timeout %s second(s) accessing %s" string timeout filename))) + (format + "%s: Timeout %s second(s) accessing %s" string timeout filename))) (setq filename (file-truename filename)) (if (file-exists-p filename) (unless diff --git a/lisp/recentf.el b/lisp/recentf.el index 7816c005358..94ae871763b 100644 --- a/lisp/recentf.el +++ b/lisp/recentf.el @@ -112,11 +112,15 @@ must return non-nil to exclude it." :group 'recentf :type '(repeat (choice regexp function))) +(defun recentf-access-file (filename) + "Check whether FILENAME is accessible." + (ignore-errors (not (access-file filename "Checking recentf file")))) + (defun recentf-keep-default-predicate (file) "Return non-nil if FILE should be kept in the recent list. It handles the case of remote files as well." (cond - ((file-remote-p file nil t) (file-readable-p file)) + ((file-remote-p file nil t) (recentf-access-file file)) ((file-remote-p file)) ((file-readable-p file))))