Refactor doom/sudo-find-file, add doom/sudo-this-file

This commit is contained in:
Henrik Lissner 2017-05-15 11:20:25 +02:00
parent be4be57a1a
commit a1384d17f6

View file

@ -1,12 +1,19 @@
;;; editor.el ;;; editor.el
;;;###autoload ;;;###autoload
(defun doom/sudo-find-file () (defun doom/sudo-find-file (file)
"Open a file as root." "Open a file as root."
(interactive
(list (read-file-name "Open as root: ")))
(find-file (if (file-writable-p file)
file
(concat "/sudo:root@localhost:" file))))
;;;###autoload
(defun doom/sudo-this-file ()
"Open the current file as root."
(interactive) (interactive)
(let ((file (read-file-name "Open as root: "))) (doom/sudo-find-file (file-truename buffer-file-name)))
(unless (file-writable-p file)
(find-file (concat "/sudo:root@localhost:" file)))))
(defun doom--goto-first-non-blank () (defun doom--goto-first-non-blank ()
(beginning-of-visual-line) (beginning-of-visual-line)