commit 4ba6ac8e579ac0d6522b990cbe2283bc8eb6d079
parent b725f476bafb33f8d3ce31d384899637db8893b3
Author: Tomas Hlavaty <tom@logand.com>
Date: Wed, 27 Jan 2021 23:39:07 +0100
handle remote files transparently
Diffstat:
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/emacs-unoffice.el b/emacs-unoffice.el
@@ -18,6 +18,10 @@
;;; (add-to-list 'auto-mode-alist '("\\.abw\\'" . unabw))
;;; (add-to-list 'auto-mode-alist '("\\.docx\\'" . undocx))
;;; (add-to-list 'auto-mode-alist '("\\.odt\\'" . unodt))
+;;;
+;;; Dependencies:
+;;;
+;;; - sha256sum from coreutils
(require 'arc-mode)
(require 'cl)
@@ -26,6 +30,36 @@
(require 'view)
(require 'xml)
+(defcustom unoffice-cache-directory nil
+ "Specify the directory where to store cache files."
+ :type 'string
+ :group 'unoffice)
+
+(defun unoffice-local-cache-directory ()
+ (let ((z (or unoffice-cache-directory temporary-file-directory)))
+ (if (file-remote-p z)
+ (error "unoffice-cache-directory is remote %s" z)
+ z)))
+
+(defun unoffice-local-cache-file (name extension)
+ (concat (unoffice-local-cache-directory) "/" name "." extension))
+
+(defun unoffice-file-hash (file)
+ (with-temp-buffer
+ (if (file-remote-p file)
+ (process-file "sha256sum" file t)
+ (call-process "sha256sum" file t))
+ (buffer-substring (point-min) (+ (point-min) 64))))
+
+(defun unoffice-cache-remote (file)
+ (if (file-remote-p file)
+ (let ((z (unoffice-local-cache-file (unoffice-file-hash file)
+ (file-name-extension file))))
+ (unless (file-readable-p z)
+ (copy-file file z))
+ z)
+ file))
+
(defun unabw ()
(interactive)
(with-silent-modifications
@@ -55,6 +89,7 @@
(t (mapc #'rec (cddr x))))))))
(rec
(let ((f buffer-file-name))
+ (setq f (unoffice-cache-remote f))
(with-temp-buffer
(when (zerop (archive-zip-extract f "content.xml"))
(car (xml-parse-region))))))))
@@ -147,6 +182,7 @@
(t (mapc #'rec (cddr x)))))))
(rec
(let ((f buffer-file-name))
+ (setq f (unoffice-cache-remote f))
(with-temp-buffer
(when (or (zerop (archive-zip-extract f "word/document.xml"))
(zerop (archive-zip-extract f "document.xml")))