+(defun riece-epg-add-encrypted-button (start end)
+ (if (and (get 'riece-button 'riece-addon-enabled)
+ (get 'riece-epg 'riece-addon-enabled))
+ (riece-scan-property-region
+ 'riece-epg-encryption-target
+ start end
+ (lambda (start end)
+ (let ((inhibit-read-only t)
+ buffer-read-only)
+ (widget-convert-button
+ 'link start end
+ :help-echo "Click to decrypt"
+ :notify #'riece-epg-encrypted-button-notify
+ (get-text-property start 'riece-epg-encryption-target)))))))
+
+(defun riece-epg-encrypted-button-notify (widget &rest ignore)
+ (let* ((from (marker-position (widget-get widget :from)))
+ (to (marker-position (widget-get widget :to)))
+ (target (widget-get widget :value))
+ (cipher (buffer-substring from to))
+ (inhibit-read-only t)
+ buffer-read-only
+ plain)
+ (when (string-match "\\`\\[encrypted:\\(.*\\)]" cipher)
+ (setq plain (riece-epg-decrypt-string-for-identity
+ (epg-make-context) (match-string 1 cipher) target))
+ (widget-delete widget)
+ (delete-region from to)
+ (save-excursion
+ (goto-char from)
+ (insert "[decrypted:" plain "]")))))
+
+(defun riece-epg-requires ()
+ (if (memq 'riece-button riece-addons)
+ '(riece-button)))
+