help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

isolating history with buffer-local variables


From: Nick Helm
Subject: isolating history with buffer-local variables
Date: Wed, 13 May 2015 02:10:25 +0000

Hello, I'm trying to teach myself some elisp, but I'm having a problem with 
some code that works with buffer-local variables. It seems to work as intended 
for some variables, but not others.

My objective is to create a minor mode that makes Emacs less likely to leak 
private data. 

The approach I've taken is to locally turn off backups and auto-saves, and 
create buffer-local variables to isolate command histories and rings that may 
accumulate private information. My intent is for editing to work normally in 
the private buffer, with local histories and the local kill-ring etc all 
available, but without exposing them globally to other buffers and packages 
like savehist, which should continue uninterrupted. When the minor mode is 
turned off, the local variables are killed, reinstating the global bindings.

Here's the code:

(define-minor-mode private-mode
   "This mode prevents Emacs from creating backups, auto-saves and
   certain history records for the current buffer. It is useful
   when editing private data, such as password files, key-chains and
   secure notes."
   :init-value nil
   :lighter " Private"
   :keymap nil
   (if (symbol-value private-mode) (progn
      (setq private-variables '( ;; data to isolate
         minibuffer-history         ;; <-- not working
         command-history            ;; ok
         extended-command-history   ;; <-- not working
         string-rectangle-history   ;; <-- not working
         query-replace-history      ;; ok
         search-ring                ;; ok
         regexp-search-ring         ;; ok
         kill-ring                  ;; ok
         backup-inhibited           ;; ok
         auto-save-timeout))        ;; ok 
      (dolist (variable private-variables) (make-local-variable variable)) ;; 
make local vars
      (setq backup-inhibited t) ;; locally disable backups
      (setq auto-save-timeout 0)) ;; locally idle auto-saves
      ;; TODO: Add idle timer to purge changes to local vars
    (dolist (variable private-variables) (kill-local-variable variable)))) ;; 
pop local vars

All the local auto-save/backup vars, local ring vars, and local 
query-replace-history and command-history vars work as intended. But 
minibuffer-history, extended-command-history and string-rectangle-history do 
not. The buffer-local vars for these are made as expected, but they are ignored 
and histories continue to accumulate in the global variables.

Any idea why? Anyone have suggestions for a different approach or a way around 
the problem? 

(There is a somewhat relevant discussion here: 
http://lists.gnu.org/archive/html/help-gnu-emacs/2011-10/msg00292.html)

Nick





reply via email to

[Prev in Thread] Current Thread [Next in Thread]