fix(lib): doom/delete-this-file nil path handling

Fix the handling of a nil path within doom/delete-this-file.

If path is nil (e.g. called interactively when buffer is not visiting a
file), avoid calling abbreviate-file-name on nil, otherwise an error
will be signaled:

  (wrong-type-argument stringp nil)

Additionally, fix the subsequent path checks. These were treating two
distinct scenarios as a "Buffer is not visiting any file" user-error:

- nil path
- non-existent path
- Only the first should result in that error. The second should proceed
  to the next path check (which was previously unreachable), to signal
  the appropriate error, "File doesn't exist: %s".
This commit is contained in:
Ivan 2022-09-30 16:48:59 -04:00 committed by GitHub
parent 3a19152787
commit 850907ed9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -405,8 +405,8 @@ If FORCE-P, delete without confirmation."
(list (buffer-file-name (buffer-base-buffer)) (list (buffer-file-name (buffer-base-buffer))
current-prefix-arg)) current-prefix-arg))
(let* ((path (or path (buffer-file-name (buffer-base-buffer)))) (let* ((path (or path (buffer-file-name (buffer-base-buffer))))
(short-path (abbreviate-file-name path))) (short-path (and path (abbreviate-file-name path))))
(unless (and path (file-exists-p path)) (unless path
(user-error "Buffer is not visiting any file")) (user-error "Buffer is not visiting any file"))
(unless (file-exists-p path) (unless (file-exists-p path)
(error "File doesn't exist: %s" path)) (error "File doesn't exist: %s" path))