@code{tramp-archive-all-gvfs-methods} for a complete list of
@code{tramp-gvfs} supported method names.
-If @value{tramp} is loaded and @code{url-handler-mode} is enabled,
-archives could be visited via URLs, like
+If @code{url-handler-mode} is enabled, archives could be visited via
+URLs, like
@file{https://ftp.gnu.org/gnu/tramp/tramp-2.3.2.tar.gz/INSTALL}. This
allows complex file operations like
@lisp
@group
(progn
- (require 'tramp)
(url-handler-mode 1)
(ediff-directories
"https://ftp.gnu.org/gnu/tramp/tramp-2.3.1.tar.gz/tramp-2.3.1"
@lisp
@group
-(find-file
- "http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_8.28-1_amd64.deb/control.tar.gz/control")
+(progn
+ (url-handler-mode 1)
+ (find-file
+ "http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_8.28-1_amd64.deb/control.tar.gz/control"))
@end group
@end lisp
(defvar url-tramp-protocols)
;; <https://github.com/libarchive/libarchive/wiki/LibarchiveFormats>
-;;;###tramp-autoload
+;;;###autoload
(defconst tramp-archive-suffixes
;; "cab", "lzh" and "zip" are included with lower and upper letters,
;; because Microsoft Windows provides them often with capital
It must be supported by libarchive(3).")
;; <http://unix-memo.readthedocs.io/en/latest/vfs.html>
-;; read and write: tar, cpio, pax , gzip , zip, bzip2, xz, lzip, lzma, ar, mtree, iso9660, compress,
-;; read only: 7-Zip, mtree, xar, lha/lzh, rar, microsoft cab,
+;; read and write: tar, cpio, pax , gzip , zip, bzip2, xz, lzip, lzma, ar, mtree, iso9660, compress.
+;; read only: 7-Zip, mtree, xar, lha/lzh, rar, microsoft cab.
-;;;###tramp-autoload
+;;;###autoload
(defconst tramp-archive-compression-suffixes
'("bz2" "gz" "lrz" "lz" "lz4" "lzma" "lzo" "uu" "xz" "Z")
"List of suffixes which indicate a compressed file.
It must be supported by libarchive(3).")
-;;;###tramp-autoload
-(defconst tramp-archive-file-name-regexp
- (concat
+;; The definition of `tramp-archive-file-name-regexp' contains calls
+;; to `regexp-opt', which cannot be autoloaded while loading
+;; loaddefs.el. So we use a macro, which is evaluated only when needed.
+;;;###autoload
+(progn (defmacro tramp-archive-autoload-file-name-regexp ()
+ "Regular expression matching archive file names."
+ `(concat
"\\`" "\\(" ".+" "\\."
;; Default suffixes ...
(regexp-opt tramp-archive-suffixes)
;; ... with compression.
"\\(?:" "\\." (regexp-opt tramp-archive-compression-suffixes) "\\)*"
"\\)" ;; \1
- "\\(" "/" ".*" "\\)" "\\'") ;; \2
+ "\\(" "/" ".*" "\\)" "\\'"))) ;; \2
+
+;;;###tramp-autoload
+(defconst tramp-archive-file-name-regexp
+ (tramp-archive-autoload-file-name-regexp)
"Regular expression matching archive file names.")
;;;###tramp-autoload
(save-match-data (apply (cdr fn) args))
(tramp-archive-run-real-handler operation args))))))
+;;;###autoload
+(progn (defun tramp-register-archive-file-name-handler ()
+ "Add archive file name handler to `file-name-handler-alist'."
+ (add-to-list 'file-name-handler-alist
+ (cons (tramp-archive-autoload-file-name-regexp)
+ 'tramp-autoload-file-name-handler))
+ (put 'tramp-archive-file-name-handler 'safe-magic t)))
+
+;;;###autoload
+(add-hook 'after-init-hook 'tramp-register-archive-file-name-handler)
+
;; Mark `operations' the handler is responsible for.
(put 'tramp-archive-file-name-handler 'operations
(mapcar 'car tramp-archive-file-name-handler-alist))
(delete-directory tmp-file)
(should-not (file-exists-p tmp-file))))
-(ert-deftest tramp-archive-test40-archive-file-system-info ()
+(ert-deftest tramp-archive-test40-file-system-info ()
"Check that `file-system-info' returns proper values."
(skip-unless tramp-gvfs-enabled)
;; Since Emacs 27.1.
(zerop (nth 1 fsi))
(zerop (nth 2 fsi))))))
+(ert-deftest tramp-archive-test42-auto-load ()
+ "Check that `tramp-archive' autoloads properly."
+ (skip-unless tramp-gvfs-enabled)
+
+ (let ((default-directory (expand-file-name temporary-file-directory))
+ (code
+ (format
+ "(message \"Tramp loaded: %%s\" (and (file-exists-p %S) t))"
+ tramp-archive-test-archive)))
+ (should
+ (string-match
+ "Tramp loaded: t[\n\r]+"
+ (shell-command-to-string
+ (format
+ "%s -batch -Q -L %s --eval %s"
+ (shell-quote-argument
+ (expand-file-name invocation-name invocation-directory))
+ (mapconcat 'shell-quote-argument load-path " -L ")
+ (shell-quote-argument code)))))))
+
+(ert-deftest tramp-archive-test42-delay-load ()
+ "Check that `tramp-archive' is loaded lazily, only when needed."
+ (skip-unless tramp-gvfs-enabled)
+
+ ;; Tramp is neither loaded at Emacs startup, nor when completing a
+ ;; non archive file name like "/foo". Completing an archive file
+ ;; name like "/foo.tar/" autoloads Tramp, when `tramp-mode' is t.
+ (let ((default-directory (expand-file-name temporary-file-directory))
+ (code
+ (format
+ "(progn \
+ (message \"Tramp loaded: %%s\" (featurep 'tramp-archive)) \
+ (file-name-all-completions %S \"/\") \
+ (message \"Tramp loaded: %%s\" (featurep 'tramp-archive)) \
+ (file-name-all-completions %S \"/\") \
+ (message \"Tramp loaded: %%s\" (featurep 'tramp-archive)))"
+ tramp-archive-test-file-archive
+ tramp-archive-test-archive)))
+ ;; Tramp doesn't load when `tramp-mode' is nil.
+ (should
+ (string-match
+ "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: t[\n\r]+"
+ (shell-command-to-string
+ (format
+ "%s -batch -Q -L %s --eval %s"
+ (shell-quote-argument
+ (expand-file-name invocation-name invocation-directory))
+ (mapconcat 'shell-quote-argument load-path " -L ")
+ (shell-quote-argument code)))))))
+
(ert-deftest tramp-archive-test99-libarchive-tests ()
"Run tests of libarchive test files."
:tags '(:expensive-test)