From 915ce5e2d0c1ce4e1c0316c23c00fd7f553ce72e Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 22 Apr 2013 22:24:48 -0400 Subject: find file as root --- init/km-func.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'init') 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) -- cgit v1.2.3