Bind 'SPC b u' to save current file as root

This commit is contained in:
Henrik Lissner 2019-12-24 14:25:08 -05:00
parent a28de332fc
commit f04af0b8a2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 13 additions and 0 deletions

View file

@ -341,3 +341,15 @@ file if it exists, without confirmation."
"Open the current file as root."
(interactive)
(find-alternate-file (doom--sudo-file buffer-file-name)))
;;;###autoload
(defun doom/sudo-save-buffer ()
"Save this file as root."
(interactive)
(let ((origin (current-buffer))
(buffer (doom--sudo-file buffer-file-name)))
(unwind-protect
(with-current-buffer buffer
(save-buffer))
(unless (eq origin buffer)
(kill-buffer buffer)))))