]> git.eshelyaron.com Git - emacs.git/commitdiff
Add inhibit-remote-files and without-remote-files
authorMichael Albinus <michael.albinus@gmx.de>
Sat, 22 Jul 2023 08:16:04 +0000 (10:16 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 22 Jul 2023 08:16:04 +0000 (10:16 +0200)
* doc/emacs/files.texi (Remote Files): Do not document tramp-mode
any longer.  Describe inhibit-remote-files instead.

* doc/lispref/files.texi (Magic File Names): Add without-remote-files.

* doc/misc/tramp.texi (Frequently Asked Questions): Do not
document tramp-mode any longer.  Describe inhibit-remote-files and
without-remote-files instead.

* etc/NEWS: Add inhibit-remote-files and without-remote-files.
Fix typos.

* lisp/net/tramp.el (inhibit-remote-files): New defun.
(without-remote-files): New defmacro.

* test/lisp/net/tramp-archive-tests.el
(tramp-archive-test49-without-remote-files):
* test/lisp/net/tramp-tests.el (tramp-test49-without-remote-files):
New tests.
(tramp-test50-unload): Rename.

doc/emacs/files.texi
doc/lispref/files.texi
doc/misc/tramp.texi
etc/NEWS
lisp/net/tramp.el
test/lisp/net/tramp-archive-tests.el
test/lisp/net/tramp-tests.el

index 9734223b95e74e5848d6d5118e54b5b9c8f8aa28..ac7751ceb53d1858e558478d923d737569abafd1 100644 (file)
@@ -2093,10 +2093,11 @@ Otherwise, Emacs uses @command{ssh}.
 @end enumerate
 
 @cindex disabling remote files
+@cindex inhibit-remote-files
 @noindent
-You can entirely turn off the remote file name feature by setting the
-variable @code{tramp-mode} to @code{nil}.  You can turn off the
-feature in individual cases by quoting the file name with @samp{/:}
+You can entirely turn off the remote file name feature by running
+@kbd{M-x inhibit-remote-files}.  You can turn off the feature in
+individual cases by quoting the file name with @samp{/:}
 (@pxref{Quoted File Names}).
 
 @cindex @code{ange-ftp}
index 31d4aaca50726a3f1675c89176accc7631377cdc..aaab4e455a007f6e836a4b763a743b0b25a38041 100644 (file)
@@ -3698,6 +3698,17 @@ between consecutive checks.  For example:
 @end example
 @end defopt
 
+@defmac without-remote-files body@dots{}
+The @code{without-remote-files} macro evaluates the @var{body} forms
+with deactivated file name handlers for remote files.  Those file
+names would be handled literally.
+
+The macro should be used only in forms where it is obvious, that
+remote files cannot appear or where it is intended not to handle
+remote file names.  It also reduces checks with
+@code{file-name-handler-alist}, resulting in more performant code.
+@end defmac
+
 @node Format Conversion
 @section File Format Conversion
 
index ff2a66ae7205c1eb01e4affeb73ae2f029a7d8af..1d8e00953282844eaee53270f2ff2435789a1cc9 100644 (file)
@@ -5851,16 +5851,6 @@ If you want to enable Ange FTP's syntax, add the following form:
 (tramp-change-syntax 'simplified)
 @end lisp
 
-@item
-@vindex tramp-mode
-To disable both @value{tramp} (and Ange FTP), set @code{tramp-mode} to
-@code{nil} in @file{.emacs}.  @strong{Note}, that we don't use
-@code{customize-set-variable}, in order to avoid loading @value{tramp}.
-
-@lisp
-(setq tramp-mode nil)
-@end lisp
-
 @item
 @vindex tramp-ignored-file-name-regexp
 To deactivate @value{tramp} for some look-alike remote file names, set
@@ -5877,6 +5867,29 @@ This is needed, if you mount for example a virtual file system on your
 local host's root directory as @file{/ssh:example.com:}.
 
 @item
+@findex inhibit-remote-files
+To disable both @value{tramp} (and Ange FTP), type @kbd{M-x
+inhibit-remote-files @key{RET}}.  You can also add this to your
+@file{.emacs}.
+
+@lisp
+(inhibit-remote-files)
+@end lisp
+
+@item
+@findex without-remote-files
+If you write code, which is intended to run only for local files, you
+can use the @code{without-remote-files} macro.
+
+@lisp
+(without-remote-files @dots{})
+@end lisp
+
+This improves performance, because many primitive file name operations
+don't check any longer for Tramp file name regexps then.
+
+@item
+@findex tramp-unload-tramp
 To unload @value{tramp}, type @kbd{M-x tramp-unload-tramp @key{RET}}.
 Unloading @value{tramp} resets Ange FTP plugins also.
 @end itemize
index d1af3b1b8667d09a30a03480a8a0db0b1bc0e202..c2c436fb4778d6e7e1eb60c3dc50fd7c85b9f600 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -93,11 +93,12 @@ The 'tool-bar-position' frame parameter can be set to 'bottom' on all
 window systems other than Nextstep.
 
 ** cl-print
+
 *** You can expand the "..." truncation everywhere.
-The code that allowed "..." to be expanded in the *Backtrace* should
-now work anywhere the data is generated by `cl-print`.
+The code that allowed "..." to be expanded in the "*Backtrace*" buffer
+should now work anywhere the data is generated by 'cl-print'.
 
-*** hash-tables' contents can be expanded via the ellipsis
+*** hash-tables' contents can be expanded via the ellipsis.
 
 ** Modeline elements can now be right-aligned.
 Anything following the symbol 'mode-line-format-right-align' in
@@ -264,6 +265,8 @@ docstring, or a comment, or (re)indents the surrounding defun if
 point is not in a comment or a string.  It is by default bound to
 'M-q' in 'prog-mode' and all its descendants.
 
+** Which Function Mode
+
 +++
 *** Which Function Mode can now display function names on the header line.
 The new user option 'which-func-display' allows choosing where the
@@ -300,6 +303,19 @@ sessions, respectively.
 It allows to kill only selected remote buffers, controlled by user
 option 'tramp-cleanup-some-buffers-hook'.
 
++++
+*** New command 'inhibit-remote-files'.
+This command disables the handling of file names with the special
+remote file name syntax.  It should be applied only when remote files
+won't be used in this Emacs instance.  It provides a slightly improved
+performance of file name handling in Emacs.
+
++++
+*** New macro 'without-remote-files'.
+This macro could wrap code which handles local files only.  Due to the
+temporary deactivation of remote files, it results in a slightly
+improved performance of file name handling in Emacs.
+
 ** EWW
 
 +++
@@ -602,7 +618,7 @@ behavior back for any other reason, you can do that using the
 'coding-system-put' function.  For example, the following restores the
 previous behavior of showing 'U' in the mode line for 'koi8-u':
 
-     (coding-system-put 'koi8-u :mnemonic ?U)
+    (coding-system-put 'koi8-u :mnemonic ?U)
 
 +++
 ** Infinities and NaNs no longer act as symbols on non-IEEE platforms.
@@ -611,6 +627,7 @@ tokens like 0.0e+NaN and 1.0e+INF are no longer read as symbols.
 Instead, the Lisp reader approximates an infinity with the nearest
 finite value, and a NaN with some other non-numeric object that
 provokes an error if used numerically.
+
 \f
 * Lisp Changes in Emacs 30.1
 
index 55e1ca932e4b8e499e17ea3cea944ae80bab642f..53a80c41680f3091439fba8b03bafd58bf9c1e6e 100644 (file)
@@ -2967,6 +2967,25 @@ whether HANDLER is to be called.  Add operations defined in
 (put #'tramp-unload-file-name-handlers 'tramp-autoload t)
 (add-hook 'tramp-unload-hook #'tramp-unload-file-name-handlers)
 
+;;;###autoload
+(progn (defun inhibit-remote-files ()
+  "Deactivate remote file names."
+  (interactive)
+  (when (fboundp 'tramp-cleanup-all-connections)
+    (funcall 'tramp-cleanup-all-connections))
+  (tramp-unload-file-name-handlers)
+  (setq tramp-mode nil)))
+
+;;;###autoload
+(progn (defmacro without-remote-files (&rest body)
+  "Deactivate remote file names temporarily.
+Run BODY."
+  (declare (indent 0) (debug ((form body) body)))
+  `(let ((file-name-handler-alist (copy-tree file-name-handler-alist))
+         tramp-mode)
+     (tramp-unload-file-name-handlers)
+     ,@body)))
+
 ;;; File name handler functions for completion mode:
 
 ;; This function takes action since Emacs 28.1, when
index 5485b12f74f961a0f6c9596db8e73668c60b6716..e34e830cb83274c950f39aa61b074e876d439396 100644 (file)
@@ -988,6 +988,20 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
             code tae tramp-archive-test-file-archive
             (concat tramp-archive-test-archive "foo"))))))))))
 
+(ert-deftest tramp-archive-test49-without-remote-files ()
+  "Check that Tramp can be suppressed."
+  (skip-unless tramp-archive-enabled)
+
+  (should (file-exists-p tramp-archive-test-archive))
+  (should-not (without-remote-files (file-exists-p tramp-archive-test-archive)))
+  (should (file-exists-p tramp-archive-test-archive))
+
+  (inhibit-remote-files)
+  (should-not (file-exists-p tramp-archive-test-archive))
+  (tramp-register-file-name-handlers)
+  (setq tramp-mode t)
+  (should (file-exists-p tramp-archive-test-archive)))
+
 (ert-deftest tramp-archive-test99-libarchive-tests ()
   "Run tests of libarchive test files."
   :tags '(:expensive-test :unstable)
index 16afc0f477a618140f18c29ee1310cf7673ca21e..9bc8ad8ce39486a1ecec5f14d00ee7fe04833a71 100644 (file)
@@ -8009,7 +8009,22 @@ process sentinels.  They shall not disturb each other."
        (mapconcat #'shell-quote-argument load-path " -L ")
        (shell-quote-argument code)))))))
 
-(ert-deftest tramp-test49-unload ()
+(ert-deftest tramp-test49-without-remote-files ()
+  "Check that Tramp can be suppressed."
+  (skip-unless (tramp--test-enabled))
+
+  (should (file-remote-p ert-remote-temporary-file-directory))
+  (should-not
+   (without-remote-files (file-remote-p ert-remote-temporary-file-directory)))
+  (should (file-remote-p ert-remote-temporary-file-directory))
+
+  (inhibit-remote-files)
+  (should-not (file-remote-p ert-remote-temporary-file-directory))
+  (tramp-register-file-name-handlers)
+  (setq tramp-mode t)
+  (should (file-remote-p ert-remote-temporary-file-directory)))
+
+(ert-deftest tramp-test50-unload ()
   "Check that Tramp and its subpackages unload completely.
 Since it unloads Tramp, it shall be the last test to run."
   :tags '(:expensive-test)