summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init/km-func.el13
1 files changed, 13 insertions, 0 deletions
diff --git a/init/km-func.el b/init/km-func.el
index f59d4ec..7e18b6e 100644
--- a/init/km-func.el
+++ b/init/km-func.el
@@ -44,3 +44,16 @@
(defun km/start-ess ()
(interactive)
(require 'ess-site))
+
+;; http://emacs-fu.blogspot.com/2013/03/editing-with-root-privileges-once-more.html
+(defun km/find-file-as-root ()
+ "`ido-find-file` that automatically edits the file with
+root-privileges (using tramp/sudo) if the file is not writable by
+user."
+ (interactive)
+ (let ((file (ido-read-file-name "Edit as root: ")))
+ (unless (file-writable-p file)
+ (setq file (concat "/sudo:root@localhost:" file)))
+ (find-file file)))
+
+(global-set-key (kbd "C-x F") 'km/find-file-as-root)