- (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
- "Select recipents for encryption.
-If no one is selected, symmetric encryption will be performed. ")))
- nil (expand-file-name (buffer-file-name)))
+ (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)
+ (context (epg-make-context)))
+ (epg-context-set-passphrase-callback
+ context
+ (cons #'epa-file-passphrase-callback-function
+ (current-buffer)))
+ (write-region
+ (epg-encrypt-string
+ context
+ (encode-coding-string (buffer-string) coding-system)
+ (mapcar (lambda (key)
+ (epg-sub-key-id (car (epg-key-sub-key-list key))))
+ (unless epa-passphrase
+ (epa-select-keys
+ "Select recipents for encryption.
+If no one is selected, symmetric encryption will be performed. "))))
+ nil (expand-file-name (buffer-file-name))))
+ (set-visited-file-modtime)