aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-02-03 13:22:56 +0100
committerMichael Albinus2018-02-03 13:22:56 +0100
commit84c9dba4cee052b68b194c3a2e5c297a94d8c8af (patch)
treed9b8f9c74fdeeda789f31c1785ab6d5dacab67e0
parent0e0ad865d49dbcfcebaae9204c52e8632e1e2ddf (diff)
downloademacs-84c9dba4cee052b68b194c3a2e5c297a94d8c8af.tar.gz
emacs-84c9dba4cee052b68b194c3a2e5c297a94d8c8af.zip
Autoload tramp-archive
* doc/misc/tramp.texi (Archive file names): Do not require to load Tramp explicitly, this is autoloaded now also for file archives. * lisp/net/tramp-archive.el (tramp-archive-suffixes) (tramp-archive-compression-suffixes): Autoload them. (tramp-archive-autoload-file-name-regexp): New defmacro. (tramp-archive-file-name-regexp): Use it. (tramp-register-archive-file-name-handler): New defun. Call it in `after-init-hook'. * test/lisp/net/tramp-archive-tests.el (tramp-archive-test40-file-system-info): Rename from `tramp-archive-test40-archive-file-system-info. (tramp-archive-test42-auto-load) (tramp-archive-test42-delay-load): New tests.
-rw-r--r--doc/misc/tramp.texi11
-rw-r--r--lisp/net/tramp-archive.el35
-rw-r--r--test/lisp/net/tramp-archive-tests.el52
3 files changed, 84 insertions, 14 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index f5dfef261f7..235627cc0f9 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -3117,15 +3117,14 @@ similar @samp{/scp:user@@host:...}. See the constant
3117@code{tramp-archive-all-gvfs-methods} for a complete list of 3117@code{tramp-archive-all-gvfs-methods} for a complete list of
3118@code{tramp-gvfs} supported method names. 3118@code{tramp-gvfs} supported method names.
3119 3119
3120If @value{tramp} is loaded and @code{url-handler-mode} is enabled, 3120If @code{url-handler-mode} is enabled, archives could be visited via
3121archives could be visited via URLs, like 3121URLs, like
3122@file{https://ftp.gnu.org/gnu/tramp/tramp-2.3.2.tar.gz/INSTALL}. This 3122@file{https://ftp.gnu.org/gnu/tramp/tramp-2.3.2.tar.gz/INSTALL}. This
3123allows complex file operations like 3123allows complex file operations like
3124 3124
3125@lisp 3125@lisp
3126@group 3126@group
3127(progn 3127(progn
3128 (require 'tramp)
3129 (url-handler-mode 1) 3128 (url-handler-mode 1)
3130 (ediff-directories 3129 (ediff-directories
3131 "https://ftp.gnu.org/gnu/tramp/tramp-2.3.1.tar.gz/tramp-2.3.1" 3130 "https://ftp.gnu.org/gnu/tramp/tramp-2.3.1.tar.gz/tramp-2.3.1"
@@ -3137,8 +3136,10 @@ It is even possible to access file archives in file archives, as
3137 3136
3138@lisp 3137@lisp
3139@group 3138@group
3140(find-file 3139(progn
3141 "http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_8.28-1_amd64.deb/control.tar.gz/control") 3140 (url-handler-mode 1)
3141 (find-file
3142 "http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_8.28-1_amd64.deb/control.tar.gz/control"))
3142@end group 3143@end group
3143@end lisp 3144@end lisp
3144 3145
diff --git a/lisp/net/tramp-archive.el b/lisp/net/tramp-archive.el
index e012ac3a198..23191f11f3e 100644
--- a/lisp/net/tramp-archive.el
+++ b/lisp/net/tramp-archive.el
@@ -113,7 +113,7 @@
113(defvar url-tramp-protocols) 113(defvar url-tramp-protocols)
114 114
115;; <https://github.com/libarchive/libarchive/wiki/LibarchiveFormats> 115;; <https://github.com/libarchive/libarchive/wiki/LibarchiveFormats>
116;;;###tramp-autoload 116;;;###autoload
117(defconst tramp-archive-suffixes 117(defconst tramp-archive-suffixes
118 ;; "cab", "lzh" and "zip" are included with lower and upper letters, 118 ;; "cab", "lzh" and "zip" are included with lower and upper letters,
119 ;; because Microsoft Windows provides them often with capital 119 ;; because Microsoft Windows provides them often with capital
@@ -143,25 +143,33 @@
143It must be supported by libarchive(3).") 143It must be supported by libarchive(3).")
144 144
145;; <http://unix-memo.readthedocs.io/en/latest/vfs.html> 145;; <http://unix-memo.readthedocs.io/en/latest/vfs.html>
146;; read and write: tar, cpio, pax , gzip , zip, bzip2, xz, lzip, lzma, ar, mtree, iso9660, compress, 146;; read and write: tar, cpio, pax , gzip , zip, bzip2, xz, lzip, lzma, ar, mtree, iso9660, compress.
147;; read only: 7-Zip, mtree, xar, lha/lzh, rar, microsoft cab, 147;; read only: 7-Zip, mtree, xar, lha/lzh, rar, microsoft cab.
148 148
149;;;###tramp-autoload 149;;;###autoload
150(defconst tramp-archive-compression-suffixes 150(defconst tramp-archive-compression-suffixes
151 '("bz2" "gz" "lrz" "lz" "lz4" "lzma" "lzo" "uu" "xz" "Z") 151 '("bz2" "gz" "lrz" "lz" "lz4" "lzma" "lzo" "uu" "xz" "Z")
152 "List of suffixes which indicate a compressed file. 152 "List of suffixes which indicate a compressed file.
153It must be supported by libarchive(3).") 153It must be supported by libarchive(3).")
154 154
155;;;###tramp-autoload 155;; The definition of `tramp-archive-file-name-regexp' contains calls
156(defconst tramp-archive-file-name-regexp 156;; to `regexp-opt', which cannot be autoloaded while loading
157 (concat 157;; loaddefs.el. So we use a macro, which is evaluated only when needed.
158;;;###autoload
159(progn (defmacro tramp-archive-autoload-file-name-regexp ()
160 "Regular expression matching archive file names."
161 `(concat
158 "\\`" "\\(" ".+" "\\." 162 "\\`" "\\(" ".+" "\\."
159 ;; Default suffixes ... 163 ;; Default suffixes ...
160 (regexp-opt tramp-archive-suffixes) 164 (regexp-opt tramp-archive-suffixes)
161 ;; ... with compression. 165 ;; ... with compression.
162 "\\(?:" "\\." (regexp-opt tramp-archive-compression-suffixes) "\\)*" 166 "\\(?:" "\\." (regexp-opt tramp-archive-compression-suffixes) "\\)*"
163 "\\)" ;; \1 167 "\\)" ;; \1
164 "\\(" "/" ".*" "\\)" "\\'") ;; \2 168 "\\(" "/" ".*" "\\)" "\\'"))) ;; \2
169
170;;;###tramp-autoload
171(defconst tramp-archive-file-name-regexp
172 (tramp-archive-autoload-file-name-regexp)
165 "Regular expression matching archive file names.") 173 "Regular expression matching archive file names.")
166 174
167;;;###tramp-autoload 175;;;###tramp-autoload
@@ -297,6 +305,17 @@ pass to the OPERATION."
297 (save-match-data (apply (cdr fn) args)) 305 (save-match-data (apply (cdr fn) args))
298 (tramp-archive-run-real-handler operation args)))))) 306 (tramp-archive-run-real-handler operation args))))))
299 307
308;;;###autoload
309(progn (defun tramp-register-archive-file-name-handler ()
310 "Add archive file name handler to `file-name-handler-alist'."
311 (add-to-list 'file-name-handler-alist
312 (cons (tramp-archive-autoload-file-name-regexp)
313 'tramp-autoload-file-name-handler))
314 (put 'tramp-archive-file-name-handler 'safe-magic t)))
315
316;;;###autoload
317(add-hook 'after-init-hook 'tramp-register-archive-file-name-handler)
318
300;; Mark `operations' the handler is responsible for. 319;; Mark `operations' the handler is responsible for.
301(put 'tramp-archive-file-name-handler 'operations 320(put 'tramp-archive-file-name-handler 'operations
302 (mapcar 'car tramp-archive-file-name-handler-alist)) 321 (mapcar 'car tramp-archive-file-name-handler-alist))
diff --git a/test/lisp/net/tramp-archive-tests.el b/test/lisp/net/tramp-archive-tests.el
index 96c6a71097c..bebdf108c66 100644
--- a/test/lisp/net/tramp-archive-tests.el
+++ b/test/lisp/net/tramp-archive-tests.el
@@ -779,7 +779,7 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
779 (delete-directory tmp-file) 779 (delete-directory tmp-file)
780 (should-not (file-exists-p tmp-file)))) 780 (should-not (file-exists-p tmp-file))))
781 781
782(ert-deftest tramp-archive-test40-archive-file-system-info () 782(ert-deftest tramp-archive-test40-file-system-info ()
783 "Check that `file-system-info' returns proper values." 783 "Check that `file-system-info' returns proper values."
784 (skip-unless tramp-gvfs-enabled) 784 (skip-unless tramp-gvfs-enabled)
785 ;; Since Emacs 27.1. 785 ;; Since Emacs 27.1.
@@ -796,6 +796,56 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
796 (zerop (nth 1 fsi)) 796 (zerop (nth 1 fsi))
797 (zerop (nth 2 fsi)))))) 797 (zerop (nth 2 fsi))))))
798 798
799(ert-deftest tramp-archive-test42-auto-load ()
800 "Check that `tramp-archive' autoloads properly."
801 (skip-unless tramp-gvfs-enabled)
802
803 (let ((default-directory (expand-file-name temporary-file-directory))
804 (code
805 (format
806 "(message \"Tramp loaded: %%s\" (and (file-exists-p %S) t))"
807 tramp-archive-test-archive)))
808 (should
809 (string-match
810 "Tramp loaded: t[\n\r]+"
811 (shell-command-to-string
812 (format
813 "%s -batch -Q -L %s --eval %s"
814 (shell-quote-argument
815 (expand-file-name invocation-name invocation-directory))
816 (mapconcat 'shell-quote-argument load-path " -L ")
817 (shell-quote-argument code)))))))
818
819(ert-deftest tramp-archive-test42-delay-load ()
820 "Check that `tramp-archive' is loaded lazily, only when needed."
821 (skip-unless tramp-gvfs-enabled)
822
823 ;; Tramp is neither loaded at Emacs startup, nor when completing a
824 ;; non archive file name like "/foo". Completing an archive file
825 ;; name like "/foo.tar/" autoloads Tramp, when `tramp-mode' is t.
826 (let ((default-directory (expand-file-name temporary-file-directory))
827 (code
828 (format
829 "(progn \
830 (message \"Tramp loaded: %%s\" (featurep 'tramp-archive)) \
831 (file-name-all-completions %S \"/\") \
832 (message \"Tramp loaded: %%s\" (featurep 'tramp-archive)) \
833 (file-name-all-completions %S \"/\") \
834 (message \"Tramp loaded: %%s\" (featurep 'tramp-archive)))"
835 tramp-archive-test-file-archive
836 tramp-archive-test-archive)))
837 ;; Tramp doesn't load when `tramp-mode' is nil.
838 (should
839 (string-match
840 "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: t[\n\r]+"
841 (shell-command-to-string
842 (format
843 "%s -batch -Q -L %s --eval %s"
844 (shell-quote-argument
845 (expand-file-name invocation-name invocation-directory))
846 (mapconcat 'shell-quote-argument load-path " -L ")
847 (shell-quote-argument code)))))))
848
799(ert-deftest tramp-archive-test99-libarchive-tests () 849(ert-deftest tramp-archive-test99-libarchive-tests ()
800 "Run tests of libarchive test files." 850 "Run tests of libarchive test files."
801 :tags '(:expensive-test) 851 :tags '(:expensive-test)