From 237cdfa27c344cdaaf59cd9cc3174f187f8d38dc Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 7 Oct 2021 16:01:38 -0500 Subject: Fix crux-open-file-as-root --- init.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'init.el') diff --git a/init.el b/init.el index a633387..7fee7a3 100644 --- a/init.el +++ b/init.el @@ -1253,6 +1253,23 @@ specific to most general, they are these: "C-M-\\" #'crux-cleanup-buffer-or-region "C-x 4 t" #'crux-transpose-windows) + (el-patch-feature crux) + (with-eval-after-load 'crux + (el-patch-defun crux-reopen-as-root () + "Find file as root if necessary. + +Meant to be used as `find-file-hook'. +See also `crux-reopen-as-root-mode'." + (unless (or + ;; This helps fix for `nov-mode', and possibly others. + (el-patch-add (null buffer-file-name)) + (tramp-tramp-file-p buffer-file-name) + (equal major-mode 'dired-mode) + (not (file-exists-p (file-name-directory buffer-file-name))) + (file-writable-p buffer-file-name) + (crux-file-owned-by-user-p buffer-file-name)) + (crux-find-alternate-file-as-root buffer-file-name)))) + (crux-reopen-as-root-mode +1)) ;; (setup (:straight-when -- cgit 1.4.1-21-gabe81