Skip to content

Commit

Permalink
Define a minor mode for crux-reopen-as-root
Browse files Browse the repository at this point in the history
Rather than changing the default find-file behavior, providing a minor
mode enables users to opt-in or toggle the behavior.

Fixes bbatsov#20.
  • Loading branch information
Wilfred committed Apr 30, 2016
1 parent ca62859 commit 5969cc8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crux.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 5969cc8

Please sign in to comment.