mirror of
https://github.com/protesilaos/denote.git
synced 2026-09-15 09:46:24 -04:00
Add SAVE-BUFFER arg to denote-rename-file-using-front-matter and conform with denote-rename-no-confirm
This commit is contained in:
parent
69408a5ef8
commit
58568d3be5
21
README.org
21
README.org
|
|
@ -1287,6 +1287,12 @@ use, but carries out the renaming without asking for confirmation
|
|||
:CUSTOM_ID: h:3ab08ff4-81fa-4d24-99cb-79f97c13a373
|
||||
:END:
|
||||
|
||||
[ Revised as part of {{{development-version}}} to (i) accept an
|
||||
optional double prefix argument to automatically save the buffer and
|
||||
(ii) to not ask for confirmation while renaming and to automatically
|
||||
save the buffer if the user option ~denote-rename-no-confirm~ is
|
||||
non-nil ([[#h:a2ae9090-c49e-4b32-bcf5-eb8944241fd7][The ~denote-rename-no-confirm~ option]]). ]
|
||||
|
||||
#+findex: denote-rename-file-using-front-matter
|
||||
In the previous section, we covered the more general mechanism of the
|
||||
command ~denote-rename-file~ ([[#h:7cc9e000-806a-48da-945c-711bbc7426b0][Rename a single file]]). There is also a
|
||||
|
|
@ -1329,8 +1335,19 @@ The renaming is subject to a "yes or no" prompt that shows the old and
|
|||
new names, just so the user is certain about the change.
|
||||
|
||||
If called interactively with a prefix argument (=C-u= by default) or
|
||||
from Lisp with a non-nil =AUTO-CONFIRM= argument, this "yes or no"
|
||||
prompt is skipped.
|
||||
from Lisp with a non-nil =NO-CONFIRM= argument, this "yes or no"
|
||||
prompt is skipped and the renaming is done outright.
|
||||
|
||||
[ The following are part of {{{development-version}}}. ]
|
||||
|
||||
If called interactively with a double prefix argument (=C-u C-u= by
|
||||
default) or from Lisp with a non-nil =SAVE-BUFFER= argument, the
|
||||
buffer is saved after the front matter is updated and the file is
|
||||
renamed.
|
||||
|
||||
If the user option ~denote-rename-no-confirm~ is non-nil, it is
|
||||
interpreted the same way as a combination of =NO-CONFIRM= and
|
||||
=SAVE-BUFFER= ([[#h:a2ae9090-c49e-4b32-bcf5-eb8944241fd7][The ~denote-rename-no-confirm~ option]]).
|
||||
|
||||
The identifier of the file, if any, is never modified even if it is
|
||||
edited in the front matter: Denote considers the file name to be the
|
||||
|
|
|
|||
37
denote.el
37
denote.el
|
|
@ -2887,14 +2887,14 @@ Run the `denote-after-rename-file-hook' after renaming is done.
|
|||
(user-error "No marked files; aborting")))
|
||||
|
||||
;;;###autoload
|
||||
(defun denote-rename-file-using-front-matter (file &optional auto-confirm)
|
||||
(defun denote-rename-file-using-front-matter (file &optional no-confirm save-buffer)
|
||||
"Rename FILE using its front matter as input.
|
||||
When called interactively, FILE is the return value of the
|
||||
function `buffer-file-name' which is subsequently inspected for
|
||||
the requisite front matter. It is thus implied that the FILE has
|
||||
a file type that is supported by Denote, per `denote-file-type'.
|
||||
|
||||
Unless AUTO-CONFIRM is non-nil (such as with a prefix argument),
|
||||
Unless NO-CONFIRM is non-nil (such as with a prefix argument),
|
||||
ask for confirmation, showing the difference between the old and
|
||||
the new file names.
|
||||
|
||||
|
|
@ -2903,11 +2903,29 @@ edited in the front matter. Denote considers the file name to be
|
|||
the source of truth in this case to avoid potential breakage with
|
||||
typos and the like.
|
||||
|
||||
If AUTO-CONFIRM is non-nil, then proceed with the renaming
|
||||
operation without prompting for confirmation. This is what the
|
||||
command `denote-dired-rename-marked-files-using-front-matter'
|
||||
does internally."
|
||||
(interactive (list (buffer-file-name) current-prefix-arg))
|
||||
If NO-CONFIRM is non-nil (such as with a prefix argument) do not
|
||||
prompt for confirmation while renaming the file. Do it outright.
|
||||
|
||||
If optional SAVE-BUFFER is non-nil (such as with a double prefix
|
||||
argument), save the corresponding buffer.
|
||||
|
||||
If the user option `denote-rename-no-confirm' is non-nil,
|
||||
interpret it the same way as a combination of NO-CONFIRM and
|
||||
SAVE-BUFFER.
|
||||
|
||||
The identifier of the file, if any, is never modified even if it
|
||||
is edited in the front matter: Denote considers the file name to
|
||||
be the source of truth in this case, to avoid potential breakage
|
||||
with typos and the like."
|
||||
(interactive
|
||||
(let (no-confirm save-buffer)
|
||||
(cond
|
||||
((and current-prefix-arg (> (prefix-numeric-value current-prefix-arg) 4))
|
||||
(setq no-confirm t
|
||||
save-buffer t))
|
||||
(current-prefix-arg
|
||||
(setq no-confirm t)))
|
||||
(list buffer-file-name no-confirm save-buffer)))
|
||||
(unless (denote-file-is-writable-and-supported-p file)
|
||||
(user-error "The file is not writable or does not have a supported file extension"))
|
||||
(if-let ((file-type (denote-filetype-heuristics file))
|
||||
|
|
@ -2918,10 +2936,13 @@ does internally."
|
|||
(extension (denote-get-file-extension file))
|
||||
(dir (file-name-directory file))
|
||||
(new-name (denote-format-file-name dir id keywords title extension signature)))
|
||||
(when (or auto-confirm
|
||||
(when (or denote-rename-no-confirm
|
||||
no-confirm
|
||||
(denote-rename-file-prompt file new-name))
|
||||
(denote-rename-file-and-buffer file new-name)
|
||||
(denote-update-dired-buffers)
|
||||
(when (or denote-rename-no-confirm save-buffer)
|
||||
(save-buffer))
|
||||
(run-hooks 'denote-after-rename-file-hook)))
|
||||
(user-error "No identifier or front matter for title")))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue