all repos — nixfiles @ 4f018fb03b873f649eafeed16186fd791b55a1a8

System and user configuration, managed by nix and home-manager

Emacs: Open files via sudo if needed
Alan Pearce alan@alanpearce.co.uk
Fri, 03 Apr 2015 16:19:47 +0100
commit

4f018fb03b873f649eafeed16186fd791b55a1a8

parent

f50ed955d8beca2f86a0ab09cc0661db96fd2002

1 files changed, 5 insertions(+), 0 deletions(-)

jump to
M tag-emacs/emacs.d/init.eltag-emacs/emacs.d/init.el
@@ -607,6 +607,11 @@ (setq ido-auto-merge-delay-time 99999                   ido-enable-flex-matching t)
 
             (ido-init-completion-maps)
+            (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::" buffer-file-name))))
             (defun ido-manual-merge ()
               (interactive)
               (ido-initiate-auto-merge (current-buffer)))