diff --git a/core/prelude-core.el b/core/prelude-core.el index 03fa039..350ba65 100644 --- a/core/prelude-core.el +++ b/core/prelude-core.el @@ -250,9 +250,21 @@ there's a region, all lines that region covers will be duplicated." (byte-recompile-directory prelude-dir 0)) (defun prelude-sudo-edit (&optional arg) - (interactive "p") + "Edit currently visited file as root. + +With a prefix ARG prompt for a file to visit. +Will also prompt for a file to visit if current +buffer is not visiting a file." + (interactive "P") (if (or arg (not buffer-file-name)) - (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: "))) + (find-file (concat "/sudo:root@localhost:" + (ido-read-file-name "Find file(as root): "))) + (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)))) + +(defadvice ido-find-file (after find-file-sudo activate) + "Find file as root if necessary." + (unless (and buffer-file-name + (file-writable-p buffer-file-name)) (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)))) (defun prelude-switch-or-start (function buffer)