summaryrefslogtreecommitdiff
path: root/init/km-func.el
diff options
context:
space:
mode:
authorKyle Meyer <meyerkya@gmail.com>2013-04-22 22:24:48 -0400
committerKyle Meyer <meyerkya@gmail.com>2013-04-22 22:26:12 -0400
commit915ce5e2d0c1ce4e1c0316c23c00fd7f553ce72e (patch)
tree00890b7967804f64ea6503d79d115814c9318017 /init/km-func.el
parentfb84247aea99249e324dc8c417d17e3471ecb3f7 (diff)
downloademacs.d-915ce5e2d0c1ce4e1c0316c23c00fd7f553ce72e.tar.gz
find file as root
Diffstat (limited to 'init/km-func.el')
-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)