summary refs log tree commit diff stats
path: root/tag-emacs
diff options
context:
space:
mode:
authorAlan Pearce2015-04-03 16:19:47 +0100
committerAlan Pearce2015-04-03 16:19:47 +0100
commit4f018fb03b873f649eafeed16186fd791b55a1a8 (patch)
tree188983f4ed9ada8d6e2a80313bc9a486535d059b /tag-emacs
parentf50ed955d8beca2f86a0ab09cc0661db96fd2002 (diff)
downloaddotfiles-4f018fb03b873f649eafeed16186fd791b55a1a8.tar.lz
dotfiles-4f018fb03b873f649eafeed16186fd791b55a1a8.tar.zst
dotfiles-4f018fb03b873f649eafeed16186fd791b55a1a8.zip
Emacs: Open files via sudo if needed
Diffstat (limited to 'tag-emacs')
-rw-r--r--tag-emacs/emacs.d/init.el5
1 files changed, 5 insertions, 0 deletions
diff --git a/tag-emacs/emacs.d/init.el b/tag-emacs/emacs.d/init.el
index b7a16ae..c1b2c41 100644
--- a/tag-emacs/emacs.d/init.el
+++ b/tag-emacs/emacs.d/init.el
@@ -607,6 +607,11 @@
                   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)))