From e4eaef95cdf35a893cc1e9182d021e2fdc07a5e3 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sun, 16 May 2021 19:32:14 -0400 Subject: [PATCH] Add doas-edit function --- config.org | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/config.org b/config.org index 6a21b86..3d80196 100644 --- a/config.org +++ b/config.org @@ -608,6 +608,24 @@ Abbreviate things! #+begin_src emacs-lisp (setq ispell-silently-savep t) #+end_src +** Open file as root +#+begin_src emacs-lisp + (defun doas-edit (&optional arg) + "Edit currently visited file as root. + + With a prefix ARG prompt for a file to visit. + Will also prompt for a file to visit if current + buffer is not visiting a file. + + Modified from Emacs Redux." + (interactive "P") + (if (or arg (not buffer-file-name)) + (find-file (concat "/doas:root@localhost:" + (ido-read-file-name "Find file(as root): "))) + (find-alternate-file (concat "/doas:root@localhost:" buffer-file-name)))) + + (global-set-key (kbd "C-x C-r") #'doas-edit) +#+end_src * Keybindings ** Switch windows #+begin_src emacs-lisp -- 2.39.2