From: Armaan Bhojwani Date: Sun, 16 May 2021 23:32:14 +0000 (-0400) Subject: Add doas-edit function X-Git-Url: https://git.armaanb.net/?p=config.org.git;a=commitdiff_plain;h=e4eaef95cdf35a893cc1e9182d021e2fdc07a5e3 Add doas-edit function --- 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