Skip to content

Instantly share code, notes, and snippets.

@smonff smonff/.emacs
Created Sep 7, 2014

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.