Based on the comments to my question, I was able to come up with a (partial?) solution:
- Create a list of variables with sensitive information.
- Create a function that makes them local to a buffer.
- Create another function that sets them to
nil
.
- Add a
find-file-hook
to conditionally call the first function.
- Add a
kill-buffer-hook
to conditionally call the second function.
The Emacs Lisp code:
(setq private-variable-list '(kill-ring minibuffer-history
regexp-search-ring search-ring))
(defun setup-private-buffer ()
"Enhance the privacy of the current buffer"
(interactive)
(dolist (variable private-variable-list)
(make-local-variable variable)))
(defun clear-private-buffer()
"Clean-up the current private buffer"
(interactive)
(dolist (variable private-variable-list)
(set variable nil)))
(add-hook 'find-file-hook
(lambda ()
(if epa-file-encrypt-to
(setup-private-buffer))))
(add-hook 'kill-buffer-hook
(lambda ()
(if epa-file-encrypt-to
(clear-private-buffer))))
This seems to work for all cases that I tried, although I expect that there may be a few corner cases e.g. when handling any buffer than the current one.
kill-buffer-hook
(you can give that a local value)?