From 5969cc8527fce4ae89038579bfdcb2dd8e6c44f5 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Mon, 4 Apr 2016 21:28:31 -0400 Subject: [PATCH] Define a minor mode for crux-reopen-as-root Rather than changing the default find-file behavior, providing a minor mode enables users to opt-in or toggle the behavior. Fixes #20. --- crux.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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."