diff --git a/crux.el b/crux.el index a0a9cb8..a9e02ef 100644 --- a/crux.el +++ b/crux.el @@ -313,7 +313,14 @@ buffer is not visiting a file." (crux-file-owned-by-user-p buffer-file-name)) (crux-find-alternate-file-as-root buffer-file-name))) -(add-hook 'find-file-hook #'crux-reopen-as-root) +;;;###autoload +(define-minor-mode crux-reopen-as-root-mode + "Automatically reopen files as root if we can't write to them +as the current user." + :global t + (if crux-reopen-as-root-mode + (add-hook 'find-file-hook #'crux-reopen-as-root) + (remove-hook 'find-file-hook #'crux-reopen-as-root))) (defun crux-insert-date () "Insert a timestamp according to locale's date and time format."