From 654172da2b37401dda134cec35d6272dffae55f7 Mon Sep 17 00:00:00 2001 From: ueno Date: Mon, 17 Apr 2006 04:57:22 +0000 Subject: [PATCH] * epa-file.el (epa-write-file): Try to write region to "/" to get last-coding-system-used to be set. --- ChangeLog | 6 ++++++ epa-file.el | 38 ++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index b385a4b..4f658ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ 2006-04-17 Daiki Ueno + * epa-file.el (epa-write-file): Try to write region to "/" to get + last-coding-system-used to be set. + +2006-04-17 Daiki Ueno + * epa-file.el: New implementation of epf.el. + * epf.el: Abolished. 2006-04-17 Daiki Ueno diff --git a/epa-file.el b/epa-file.el index 093c66e..3d3b757 100644 --- a/epa-file.el +++ b/epa-file.el @@ -38,36 +38,42 @@ (defun epa-find-file () (when (string-match epa-file-name-regexp (buffer-file-name)) - (if (= (buffer-size) 0) - (progn - (set-auto-mode) - (hack-local-variables) - (auto-save-mode nil)) - (goto-char (point-min)) + (when (file-exists-p (expand-file-name (buffer-file-name))) (if (fboundp 'set-buffer-multibyte) (set-buffer-multibyte t)) + (goto-char (point-min)) (insert (epg-decrypt-file (epg-make-context) (expand-file-name (buffer-file-name)) nil)) (delete-region (point) (point-max)) (decode-coding-region (point-min) (point-max) 'undecided) - (set-buffer-modified-p nil)) + (set-buffer-modified-p nil) + (set-auto-mode) + (hack-local-variables) + (auto-save-mode nil)) (make-local-variable 'epa-file) (setq epa-file (buffer-file-name)))) +(defvar last-coding-system-used) (defun epa-write-file () (when epa-file - (write-region - (epg-encrypt-string - (epg-make-context) - (buffer-string) - (mapcar (lambda (key) - (epg-sub-key-id - (car (epg-key-sub-key-list key)))) - (epa-select-keys + (let* ((coding-system (if (boundp 'last-coding-system-used) + (condition-case nil + (write-region (point-min) (point-max) "/") + (error last-coding-system-used)) + buffer-file-coding-system)) + (coding-system-for-write 'binary)) + (write-region + (epg-encrypt-string + (epg-make-context) + (encode-coding-string (buffer-string) coding-system) + (mapcar (lambda (key) + (epg-sub-key-id + (car (epg-key-sub-key-list key)))) + (epa-select-keys "Select recipents for encryption. If no one is selected, symmetric encryption will be performed. "))) - nil (expand-file-name (buffer-file-name))) + nil (expand-file-name (buffer-file-name)))) (set-buffer-modified-p nil) t)) -- 1.7.10.4