fix(lib): sudo-{this,save}-file: file path for indirect clones
If the buffer is an indirect clone, it may not have a buffer-file-name. Also changes the command to throw an error if the current file has no file path *and* is not a dired buffer.
This commit is contained in:
parent
ea4792ccd2
commit
392fe88ed0
1 changed files with 4 additions and 3 deletions
|
@ -495,16 +495,17 @@ If FORCE-P, overwrite the destination file if it exists, without confirmation."
|
|||
(interactive)
|
||||
(find-file
|
||||
(doom--sudo-file-path
|
||||
(or buffer-file-name
|
||||
(or (buffer-file-name (buffer-base-buffer))
|
||||
(when (or (derived-mode-p 'dired-mode)
|
||||
(derived-mode-p 'wdired-mode))
|
||||
default-directory)))))
|
||||
default-directory)
|
||||
(user-error "Cannot determine the file path of the current buffer")))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/sudo-save-buffer ()
|
||||
"Save this file as root."
|
||||
(interactive)
|
||||
(let ((file (doom--sudo-file-path buffer-file-name)))
|
||||
(let ((file (doom--sudo-file-path (buffer-file-name (buffer-base-buffer)))))
|
||||
(if-let (buffer (find-file-noselect file))
|
||||
(let ((origin (current-buffer)))
|
||||
(copy-to-buffer buffer (point-min) (point-max))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue