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

Revert current buffer to visit with "sudo" permissions.

An alternative method could be chosen with tramp-file-name-with-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
;;;###tramp-autoload
(defun tramp-revert-buffer-with-sudo ()
  "Revert current buffer to visit with \"sudo\" permissions.
An alternative method could be chosen with `tramp-file-name-with-method'.
If the buffer visits a file, the file is replaced.
If the buffer runs `dired', the buffer is reverted."
  (interactive)
  (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))))