branch: externals/jarchive
commit 0733e1fcb31af0a38cb0b5a8c2807b29c55ee471
Author: dannyfreeman <[email protected]>
Commit: dannyfreeman <[email protected]>
Use find-buffer-visiting instead of local var check
find-buffer-visiting was causing an infinite loop of calls to
get-file-buffer when I tried it in previous attempts to implement this,
but this recursion is broken when jarchive--file-name-handler is
inhibited.
---
jarchive.el | 41 ++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/jarchive.el b/jarchive.el
index d0599e9b41..d387cc62a4 100644
--- a/jarchive.el
+++ b/jarchive.el
@@ -24,6 +24,14 @@ Delimited by `!' or `::'")
(defvar-local jarchive--managed-buffer nil
"This value is t when a buffer is managed by jarchive.")
+(defmacro jarchive--inhibit (op &rest body)
+ "Run BODY with `jarchive--file-name-handler' inhibited for OP."
+ `(let ((inhibit-file-name-handlers (cons (quote jarchive--file-name-handler)
+ (and (eq
inhibit-file-name-operation ,op)
+ inhibit-file-name-handlers)))
+ (inhibit-file-name-operation ,op))
+ ,@body))
+
(defun jarchive--file-name-handler (op &rest args)
"A `file-name-handler-alist' handler for opening files located in jars.
OP is a `(elisp)Magic File Names' operation and ARGS are any extra argument
@@ -34,25 +42,20 @@ provided when calling OP."
(match (string-match jarchive--hybrid-path-regex file))
(jar (substring file (match-beginning 1) (match-end 1)))
(file-in-jar (substring file (match-beginning 2))))
- (with-current-buffer (get-buffer-create file)
- (unless (or buffer-read-only jarchive--managed-buffer)
- (message "jarchive: writing buffer %s " args)
- (setq-local jarchive--managed-buffer t)
- (archive-zip-extract jar file-in-jar)
- (setq-local buffer-file-name file)
- (setq-local default-directory (file-name-directory jar))
- (setq-local buffer-offer-save nil)
- (setq buffer-read-only t)
- (set-auto-mode)
- (goto-char 0)
- (set-buffer-modified-p nil))
- (current-buffer))))
- (t (let ((inhibit-file-name-handlers (cons 'jarchive--file-name-handler
- (and (eq
inhibit-file-name-operation op)
-
inhibit-file-name-handlers)))
- (inhibit-file-name-operation op))
- (apply op args)))))
-
+ (or (jarchive--inhibit op (find-buffer-visiting file))
+ (with-current-buffer (create-file-buffer file)
+ (message "jarchive: writing buffer %s " args)
+ (setq-local jarchive--managed-buffer t)
+ (archive-zip-extract jar file-in-jar)
+ (setq-local buffer-file-name file)
+ (setq-local default-directory (file-name-directory jar))
+ (setq-local buffer-offer-save nil)
+ (setq buffer-read-only t)
+ (set-auto-mode)
+ (goto-char 0)
+ (set-buffer-modified-p nil)
+ (current-buffer)))))
+ (t (jarchive--inhibit op (apply op args)))))
(defun jarchive-setup ()
(interactive)