X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=epg-file.el;h=d3f5da1a952fcd3b686db3fd19a6d1781344a80f;hb=37d3d49548803d24469b5c5e6a792aa94ad5aa22;hp=08d1bcbb03250a8de467ad235c92139323a4833d;hpb=816c20ee258f5c9e63572c1b15d5ff0afec14310;p=elisp%2Fepg.git diff --git a/epg-file.el b/epg-file.el index 08d1bcb..d3f5da1 100644 --- a/epg-file.el +++ b/epg-file.el @@ -10,14 +10,14 @@ with GnuPG." (let ((epg-file-operation (get operation 'epg-file))) (if epg-file-operation (apply epg-file-operation args) - (epg-file-invoke-default-handler operation args)))) + (epg-file-run-real-handler operation args)))) -(defun epg-file-invoke-default-handler (operation args) +(defun epg-file-run-real-handler (operation args) (let ((inhibit-file-name-handlers - (cons 'epg-file-handler - (and (eq inhibit-file-name-operation operation) - inhibit-file-name-handlers))) - (inhibit-file-name-operation operation)) + (cons 'epg-file-handler + (and (eq inhibit-file-name-operation operation) + inhibit-file-name-handlers))) + (inhibit-file-name-operation operation)) (apply operation args))) (defun epg-file-write-region (start end filename &optional append visit @@ -27,9 +27,8 @@ with GnuPG." (expand-file-name filename))) ;; XXX: Obtain the value returned by choose_write_coding_system (coding-system (condition-case nil - (epg-file-invoke-default-handler - #'write-region - (list start end "/")) + (epg-file-run-real-handler + 'write-region (list start end "/")) (file-error last-coding-system-used))) ;; start and end are normally buffer positions ;; specifying the part of the buffer to write. @@ -67,8 +66,8 @@ with GnuPG." (when (setq cipher (epg-encrypt-string context (buffer-string) nil)) (if (memq system-type '(ms-dos windows-nt)) (setq buffer-file-type t)) - (epg-file-invoke-default-handler - #'write-region + (epg-file-run-real-handler + 'write-region (list cipher nil filename nil 'not-visit lockname mustbenew))))) ;; Optional fifth argument visit, if t or a string, means ;; set the last-save-file-modtime of buffer to this file's modtime @@ -90,24 +89,23 @@ with GnuPG." (defun epg-file-insert-file-contents (filename &optional visit beg end replace) (barf-if-buffer-read-only) - - ;; If visit is non-nil, beg and end must be nil. - (if (and visit (or beg end)) - (error "Attempt to visit less than an entire file")) - - (let ((expanded-filename (expand-file-name filename)) + (setq filename (expand-file-name filename)) + (let ((filename (expand-file-name filename)) (length 0)) - (if (file-exists-p expanded-filename) - (let* ((local-copy (epg-file-invoke-default-handler - 'file-local-copy - (list expanded-filename))) - (local-file (or local-copy expanded-filename)) - (coding-system-for-read 'binary) - (context (epg-make-context)) - string) + (if (file-exists-p filename) + (let ((local-file + (let ((inhibit-file-name-operation + (when (eq inhibit-file-name-operation + 'insert-file-contents) + 'file-local-copy))) + (file-local-copy filename))) + (coding-system-for-read 'binary) + (context (epg-make-context)) + string) (unwind-protect (progn - (setq string (epg-decrypt-file context local-file) + (setq string (epg-decrypt-file context (or local-file + filename)) length (length string)) (if replace (goto-char (point-min))) @@ -118,22 +116,22 @@ with GnuPG." (insert (decode-coding-string string 'undecided))) (if replace (delete-region (point) (point-max)))))) - (when (and local-copy (file-exists-p local-copy)) - (delete-file local-copy))))) + (when (and local-file (file-exists-p local-file)) + (delete-file local-file))))) ;; If second argument visit is non-nil, the buffer's visited filename ;; and last save file modtime are set, and it is marked unmodified. (when visit (unlock-buffer) - (setq buffer-file-name expanded-filename) + (setq buffer-file-name filename) (set-visited-file-modtime)) ;; If visiting and the file does not exist, visiting is completed ;; before the error is signaled. - (if (and visit (not (file-exists-p expanded-filename))) + (if (and visit (not (file-exists-p filename))) (signal 'file-error (list "Opening input file" filename))) ;; Returns list of absolute file name and number of characters inserted. - (list expanded-filename length))) + (list filename length))) (put 'write-region 'epg-file 'epg-file-write-region) (put 'insert-file-contents 'epg-file 'epg-file-insert-file-contents)