From: ueno Date: Wed, 20 Dec 2006 06:28:39 +0000 (+0000) Subject: (epa-last-coding-system-specified): New variable. X-Git-Tag: epg-0_0_9~9 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=fda54ec183bfa61ffc8c7383d73c201177025d90;p=elisp%2Fepg.git (epa-last-coding-system-specified): New variable. (epa-decrypt-region): Try to decode with the epa-coding-system-used text property. (epa--select-safe-coding-system): New function. (epa-verify-region): Try to decode with the epa-coding-system-used text property. (epa-sign-region): Query user to select coding-system to encode; set the epa-coding-system-used text property on the result. (epa-encrypt-region): Ditto. --- diff --git a/ChangeLog b/ChangeLog index 75fc4f1..aa4e5b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,15 @@ (epa-sign-file): Save the output to *.p7s or *.p7m file if epa-protocol is CMS. (epa-encrypt-file): Ditto. + (epa-last-coding-system-specified): New variable. + (epa-decrypt-region): Try to decode with the + epa-coding-system-used text property. + (epa--select-safe-coding-system): New function. + (epa-verify-region): Try to decode with the epa-coding-system-used + text property. + (epa-sign-region): Query user to select coding-system to encode; + set the epa-coding-system-used text property on the result. + (epa-encrypt-region): Ditto. 2006-12-19 Daiki Ueno diff --git a/epa.el b/epa.el index a88f59b..f67ad6a 100644 --- a/epa.el +++ b/epa.el @@ -172,6 +172,7 @@ the separate window." (defvar epa-key nil) (defvar epa-list-keys-arguments nil) (defvar epa-info-buffer nil) +(defvar epa-last-coding-system-specified nil) (defvar epa-keys-mode-map (let ((keymap (make-sparse-keymap))) @@ -716,7 +717,10 @@ Don't use this command in Lisp programs!" (message "Decrypting...done") (delete-region start end) (goto-char start) - (insert (epa--decode-coding-string plain coding-system-for-read)) + (insert (epa--decode-coding-string plain + (or coding-system-for-read + (get-text-property + start 'epa-coding-system-used)))) (if (epg-context-result-for context 'verify) (epa-display-info (epg-verify-result-to-string (epg-context-result-for context 'verify))))))) @@ -749,6 +753,11 @@ Don't use this command in Lisp programs!" (let ((coding-system-for-read coding-system)) (epa-decrypt-region start end))))))) +(if (fboundp 'select-safe-coding-system) + (defalias 'epa--select-safe-coding-system 'select-safe-coding-system) + (defun epa--select-safe-coding-system (from to) + buffer-file-coding-system)) + ;;;###autoload (defun epa-verify-region (start end) "Verify the current region between START and END. @@ -761,7 +770,9 @@ Don't use this command in Lisp programs!" (epg-verify-string context (epa--encode-coding-string (buffer-substring start end) - coding-system-for-write)) + (or coding-system-for-write + (get-text-property start + 'epa-coding-system-used)))) (if (epg-context-result-for context 'verify) (epa-display-info (epg-verify-result-to-string (epg-context-result-for context 'verify)))))) @@ -797,31 +808,36 @@ Don't use this command in Lisp programs!" Don't use this command in Lisp programs!" (interactive - (list (region-beginning) (region-end) - (epa-select-keys (epg-make-context epa-protocol) - "Select keys for signing. + (progn + (setq epa-last-coding-system-specified + (or coding-system-for-write + (epa--select-safe-coding-system (region-beginning) + (region-end)))) + (list (region-beginning) (region-end) + (epa-select-keys (epg-make-context epa-protocol) + "Select keys for signing. If no one is selected, default secret key is used. " - nil t) - (catch 'done - (while t - (message "Signature type (n,c,d,?) ") - (let ((c (read-char))) - (cond ((eq c ?c) - (throw 'done 'clear)) - ((eq c ?d) - (throw 'done 'detached)) - ((eq c ??) - (with-output-to-temp-buffer "*Help*" - (save-excursion - (set-buffer standard-output) - (insert "\ + nil t) + (catch 'done + (while t + (message "Signature type (n,c,d,?) ") + (let ((c (read-char))) + (cond ((eq c ?c) + (throw 'done 'clear)) + ((eq c ?d) + (throw 'done 'detached)) + ((eq c ??) + (with-output-to-temp-buffer "*Help*" + (save-excursion + (set-buffer standard-output) + (insert "\ n - Create a normal signature c - Create a cleartext signature d - Create a detached signature ? - Show this help ")))) - (t - (throw 'done nil)))))))) + (t + (throw 'done nil))))))))) (save-excursion (let ((context (epg-make-context epa-protocol)) signature) @@ -838,11 +854,23 @@ d - Create a detached signature (setq signature (epg-sign-string context (epa--encode-coding-string (buffer-substring start end) - coding-system-for-write) + epa-last-coding-system-specified) mode)) (message "Signing...done") (delete-region start end) - (insert (epa--decode-coding-string signature coding-system-for-read))))) + (add-text-properties (point) + (progn + (insert (epa--decode-coding-string + signature + (or coding-system-for-read + epa-last-coding-system-specified))) + (point)) + (list 'epa-coding-system-used + epa-last-coding-system-specified + 'front-sticky nil + 'rear-nonsticky t + 'start-open t + 'end-open t))))) ;;;###autoload (defun epa-encrypt-region (start end recipients) @@ -850,10 +878,15 @@ d - Create a detached signature Don't use this command in Lisp programs!" (interactive - (list (region-beginning) (region-end) - (epa-select-keys (epg-make-context epa-protocol) - "Select recipients for encryption. -If no one is selected, symmetric encryption will be performed. "))) + (progn + (setq epa-last-coding-system-specified + (or coding-system-for-write + (epa--select-safe-coding-system (region-beginning) + (region-end)))) + (list (region-beginning) (region-end) + (epa-select-keys (epg-make-context epa-protocol) + "Select recipients for encryption. +If no one is selected, symmetric encryption will be performed. ")))) (save-excursion (let ((context (epg-make-context epa-protocol)) cipher) @@ -869,11 +902,20 @@ If no one is selected, symmetric encryption will be performed. "))) (setq cipher (epg-encrypt-string context (epa--encode-coding-string (buffer-substring start end) - coding-system-for-write) + epa-last-coding-system-specified) recipients)) (message "Encrypting...done") (delete-region start end) - (insert cipher)))) + (add-text-properties (point) + (progn + (insert cipher) + (point)) + (list 'epa-coding-system-used + epa-last-coding-system-specified + 'front-sticky nil + 'rear-nonsticky t + 'start-open t + 'end-open t))))) ;;;###autoload (defun epa-delete-keys (keys &optional allow-secret)