branch: elpa/crux commit a6e0a523aabaab8df9b597ea39b3fc7baa563a2f Author: Wilfred Hughes <m...@wilfred.me.uk> Commit: Bozhidar Batsov <bozhidar.bat...@gmail.com>
Define a minor mode for crux-reopen-as-root (#28) Rather than changing the default find-file behavior, providing a minor mode enables users to opt-in or toggle the behavior. Fixes #20. --- README.md | 8 ++++++++ crux.el | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 71fc7c1..db4dcee 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,14 @@ current line, rather than the whole line, in the absence of a region: (crux-with-region-or-point-to-eol kill-ring-save) ``` +## Minor modes + +#### `(crux-reopen-as-root-mode)` #### + +Crux provides a `crux-reopen-as-root` command for reopening a file as +root. This global minor mode changes `find-file` so all root files are +automatically opened as root. + ## License Copyright © 2015 Bozhidar Batsov and [contributors][]. diff --git a/crux.el b/crux.el index ff88d40..1c3d857 100644 --- a/crux.el +++ b/crux.el @@ -327,7 +327,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."