From f953141200c1f8f40f5b1f1893bd04c84e82f4b8 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Thu, 16 Apr 2026 18:02:40 +0200 Subject: [PATCH] Add fscotto/sudo-edit function to edit files as root via TRAMP --- .../desktop/.emacs.d/lisp/misc/custom-functions.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el b/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el index 0b434be..b8cc697 100644 --- a/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el +++ b/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el @@ -225,3 +225,13 @@ Resume the latest saved session when available, otherwise create a new one." (unless (and sym (string-prefix-p "Test" sym)) (user-error "No Go test at point")) sym)) + +(defun fscotto/sudo-edit (&optional arg) + "Reopen current file as root via TRAMP. +If ARG is provided (C-u), prompts for file path." + (interactive "P") + (if arg + (find-file (concat "/sudo:root@localhost:" (read-file-name "File: "))) + (if buffer-file-name + (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)) + (user-error "This buffer is not associated with a file"))))