Skip to content

Instantly share code, notes, and snippets.

@smonff
Created September 7, 2014 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smonff/09d41b2a0fe8d0200583 to your computer and use it in GitHub Desktop.
Save smonff/09d41b2a0fe8d0200583 to your computer and use it in GitHub Desktop.
Gain sudo privileges in Emacs without launch it as sudo
;; Makes possible to sudo-edit files
;; From Damien Cassou
;; https://github.com/renard/dired-toggle-sudo/issues/1
(defun sudo ()
(interactive)
(let ((fname (or buffer-file-name
dired-directory)))
(when fname
(if (string-match "^/sudo:root@localhost:" fname)
(setq fname (replace-regexp-in-string
"^/sudo:root@localhost:" ""
fname))
(setq fname (concat "/sudo:root@localhost:" fname)))
(find-alternate-file fname))))
@smonff
Copy link
Author

smonff commented Sep 7, 2014

To use from dired-mode, type M-x sudo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment