Skip to content

Commit

Permalink
Define a minor mode for crux-reopen-as-root (#28)
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 #20.
  • Loading branch information
Wilfred authored and bbatsov committed Apr 30, 2016
1 parent 225b5e3 commit a6e0a52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][].
Expand Down
9 changes: 8 additions & 1 deletion crux.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit a6e0a52

Please sign in to comment.