Function: tramp-revert-buffer-with-sudo
tramp-revert-buffer-with-sudo is an autoloaded, interactive and
byte-compiled function defined in tramp-cmds.el.gz.
Signature
(tramp-revert-buffer-with-sudo)
Documentation
Visit the current file again with superuser, or root, permissions.
By default this is done using the "sudo" Tramp method.
You can customize tramp-file-name-with-method to change this.
Interactively, with a prefix argument, prompt for a different method.
If the buffer visits a file, the file is replaced.
If the buffer runs dired, the buffer is reverted.
Probably introduced at or before Emacs version 30.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-cmds.el.gz
;; FIXME: We would like to rename this for Emacs 31.1 to a name that
;; does not encode the default method. It is intended as a generic
;; privilege-elevation command. Some ideas from bug#76974:
;; `tramp-revert-buffer-obtain-root',
;; `tramp-revert-buffer-as-superuser'.
;;;###autoload
(defun tramp-revert-buffer-with-sudo ()
"Visit the current file again with superuser, or root, permissions.
By default this is done using the \"sudo\" Tramp method.
You can customize `tramp-file-name-with-method' to change this.
Interactively, with a prefix argument, prompt for a different method.
If the buffer visits a file, the file is replaced.
If the buffer runs `dired', the buffer is reverted."
(interactive)
(with-tramp-file-name-with-method
(cond
((buffer-file-name)
(let ((pos (point)))
(find-alternate-file (tramp-file-name-with-sudo (buffer-file-name)))
(goto-char pos)))
((tramp-dired-buffer-p)
(dired-unadvertise (expand-file-name default-directory))
(setq default-directory (tramp-file-name-with-sudo default-directory)
list-buffers-directory
(tramp-file-name-with-sudo list-buffers-directory))
(if (consp dired-directory)
(setcar
dired-directory (tramp-file-name-with-sudo (car dired-directory)))
(setq dired-directory (tramp-file-name-with-sudo dired-directory)))
(dired-advertise)
(revert-buffer)))))