[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 8faf120dff 26/33: Broaden the scope of denote-re
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 8faf120dff 26/33: Broaden the scope of denote-rename-no-confirm to save buffers as well |
Date: |
Wed, 14 Feb 2024 06:57:49 -0500 (EST) |
branch: externals/denote
commit 8faf120dff5005e5688072d6ca4bc70fc22d6573
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Broaden the scope of denote-rename-no-confirm to save buffers as well
We effectively make this an "expert mode".
---
README.org | 14 ++++++++++----
denote.el | 56 +++++++++++++++++++++++++++++++++++---------------------
2 files changed, 45 insertions(+), 25 deletions(-)
diff --git a/README.org b/README.org
index f1b6e9c064..5efd0a50ae 100644
--- a/README.org
+++ b/README.org
@@ -1128,7 +1128,10 @@ line or switching between then with commands like
~switch-to-buffer~.
:END:
[ Revised as part of {{{development-version}}} to honour the value of
- the user option ~denote-prompts~ where that makes sense
([[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The ~denote-prompts~ option]]). ]
+ the user option ~denote-prompts~ where that makes sense
([[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The ~denote-prompts~ option]]).
+ This version also broadens the scope of the user option
+ ~denote-rename-no-confirm~, such that it automatically saves the
+ affcted buffers, post-rename. ]
#+findex: denote-rename-file
The ~denote-rename-file~ command renames a file and updates existing
@@ -4217,9 +4220,12 @@ might change them without further notice.
note after ~denote-rename-file~ (or related) The =FILE=, =TITLE=,
=KEYWORDS=, and =FILE-TYPE= arguments are given by the renaming
command and are used to construct new front matter values if
- appropriate. With optional =NO-CONFIRM=, do not prompt to confirm the
- rewriting of the front matter. Otherwise produce a ~y-or-n-p~ prompt
- to that effect.
+ appropriate. With optional =NO-CONFIRM=, do not prompt to confirm
+ the rewriting of the front matter. Otherwise produce a ~y-or-n-p~
+ prompt to that effect. With optional =NO-CONFIRM=, save the buffer
+ after performing the rewrite. Otherwise leave it unsaved for
+ furthter review by the user. [ The =NO-CONFIRM= saves the buffer as
+ part of {{{development-version}}}. ]
#+findex: denote-rewrite-keywords
+ Function ~denote-rewrite-keywords~ :: Rewrite =KEYWORDS= in =FILE=
diff --git a/denote.el b/denote.el
index f81b0644f7..143569a201 100644
--- a/denote.el
+++ b/denote.el
@@ -434,25 +434,27 @@ current note."
:type 'boolean)
(defcustom denote-rename-no-confirm nil
- "When non-nil, `denote-rename-file' does not prompt for confirmation.
+ "Make `denote-rename-file' not prompt for confirmation and save buffers
outright.
+
The default behaviour of the `denote-rename-file' command is to
ask for an affirmative answer as a final step before changing the
file name and, where relevant, inserting or updating the
-corresponding front matter.
+corresponding front matter. It also does not save the affected
+file's buffer to let the user inspect and confirm the
+changes (such as by invoking the command `diff-buffer-with-file').
-Remember that `denote-rename-file' does not save the underlying
-buffer it modifies. It leaves it unsaved so that the user can
-review what happened, such as by invoking the command
-`diff-buffer-with-file'.
+With this user option bound to a non-nil value, buffers are saved
+as well. The assumption is that the user who opts in to this
+feature is familiar with the `denote-rename-file' operation and
+knows it is reliable.
Specialised commands that build on top of `denote-rename-file'
may internally bind this user option to a non-nil value in order
to perform their operation (e.g. `denote-dired-rename-files' goes
through each marked Dired file, prompting for the information to
-use, but carries out the renaming without asking for
-confirmation (buffers remain unsaved))."
+use, but carries out the renaming without asking for confirmation)."
:group 'denote
- :package-version '(denote . "2.1.0")
+ :package-version '(denote . "3.0.0")
:type 'boolean)
(defcustom denote-excluded-directories-regexp nil
@@ -2502,16 +2504,19 @@ variable `denote-directory'."
(rename-file old-name new-name nil)))
(denote--rename-buffer old-name new-name)))
-(defun denote--add-front-matter (file title keywords id file-type)
+(defun denote--add-front-matter (file title keywords id file-type &optional
save-buffer)
"Prepend front matter to FILE if `denote-file-is-note-p'.
The TITLE, KEYWORDS ID, and FILE-TYPE are passed from the
renaming command and are used to construct a new front matter
-block if appropriate."
+block if appropriate.
+
+With optional SAVE-BUFFER, save the buffer corresponding to FILE."
(when-let ((date (denote--date (date-to-time id) file-type))
(new-front-matter (denote--format-front-matter title date
keywords id file-type)))
(with-current-buffer (find-file-noselect file)
(goto-char (point-min))
- (insert new-front-matter))))
+ (insert new-front-matter)
+ (when save-buffer (save-buffer)))))
(defun denote--regexp-in-file-p (regexp file)
"Return t if REGEXP matches in the FILE."
@@ -2561,7 +2566,11 @@ values if appropriate.
With optional NO-CONFIRM, do not prompt to confirm the rewriting
of the front matter. Otherwise produce a `y-or-n-p' prompt to
-that effect."
+that effect.
+
+With optional NO-CONFIRM, save the buffer after performing the
+rewrite. Otherwise leave it unsaved for furthter review by the
+user."
(when-let ((old-title-line (denote-retrieve-front-matter-title-line file
file-type))
(old-keywords-line (denote-retrieve-front-matter-keywords-line
file file-type))
(new-title-line (denote--get-title-line-from-front-matter title
file-type))
@@ -2586,7 +2595,8 @@ that effect."
(re-search-forward (denote--keywords-key-regexp file-type) nil t 1)
(goto-char (line-beginning-position))
(insert new-keywords-line)
- (delete-region (point) (line-end-position))))))))
+ (delete-region (point) (line-end-position))
+ (when no-confirm (save-buffer))))))))
(define-obsolete-function-alias
'denote--rewrite-front-matter
@@ -2698,15 +2708,19 @@ the user option `denote-rename-no-confirm' is set to a
non-nil
value.
If FILE has front matter for TITLE and KEYWORDS, ask to rewrite
-their values in order to reflect the new input (this step always
-requires confirmation and the underlying buffer is not saved, so
-consider invoking `diff-buffer-with-file' to double-check the
-effect). The rewrite of the TITLE and KEYWORDS in the front
-matter should not affect the rest of the front matter.
+their values in order to reflect the new input, unless
+`denote-rename-no-confirm' is non-nil. When the
+`denote-rename-no-confirm' is nil (the default), do not save the
+underlying buffer, thus giving the user the option to
+double-check the result, such as by invokling the command
+`diff-buffer-with-file'. The rewrite of the TITLE and KEYWORDS
+in the front matter should not affect the rest of the front
+matter.
If the file does not have front matter but is among the supported
file types (per `denote-file-type'), add front matter to the top
-of it and leave the buffer unsaved for further inspection.
+of it and leave the buffer unsaved for further inspection. Save
+the buffer if `denote-rename-no-confirm' is non-nil.
For the front matter of each file type, refer to the variables:
@@ -2762,7 +2776,7 @@ one-by-one, use `denote-dired-rename-files'."
(when (denote-file-is-writable-and-supported-p new-name)
(if (denote--edit-front-matter-p new-name file-type)
(denote-rewrite-front-matter new-name title keywords file-type
denote-rename-no-confirm)
- (denote--add-front-matter new-name title keywords id file-type))))
+ (denote--add-front-matter new-name title keywords id file-type
denote-rename-no-confirm))))
new-name))
;;;###autoload
- [elpa] externals/denote aa865fa0d9 06/33: Update denote-rename-file doc string to describe its current behaviour, (continued)
- [elpa] externals/denote aa865fa0d9 06/33: Update denote-rename-file doc string to describe its current behaviour, ELPA Syncer, 2024/02/14
- [elpa] externals/denote e9e9c8ef2b 07/33: Tweak the behaviour of denote-create-unique-file-identifier, ELPA Syncer, 2024/02/14
- [elpa] externals/denote b02bf9d7c2 09/33: Add TODO about possible tweak to denote-rename-file, ELPA Syncer, 2024/02/14
- [elpa] externals/denote 764125525e 12/33: Broaden the scope of denote-rename-no-confirm to save buffers as well, ELPA Syncer, 2024/02/14
- [elpa] externals/denote 357c363242 17/33: Clarify that absent denote-prompts mean nil for relevant denote-rename-file arguments, ELPA Syncer, 2024/02/14
- [elpa] externals/denote ce9e2dd1bf 13/33: Complete the documentation of denote-rename-file, noting all modalities of interaction, ELPA Syncer, 2024/02/14
- [elpa] externals/denote ab20f4b0af 15/33: Make denote-dired-rename-files honour the denote-prompts (same as denote-rename-file), ELPA Syncer, 2024/02/14
- [elpa] externals/denote 37508c99d4 16/33: Update the documentation of denote-dired-rename-marked-files, ELPA Syncer, 2024/02/14
- [elpa] externals/denote 4cce51a092 22/33: Change how denote-rename-file passes DATE to denote-create-unique-file-identifier (per e9e9c8e), ELPA Syncer, 2024/02/14
- [elpa] externals/denote c5f8ef1d8a 23/33: Add TODO about possible tweak to denote-rename-file, ELPA Syncer, 2024/02/14
- [elpa] externals/denote 8faf120dff 26/33: Broaden the scope of denote-rename-no-confirm to save buffers as well,
ELPA Syncer <=
- [elpa] externals/denote 77eafb2dfe 25/33: Start updating the manual for denote-rename-file (WORK-IN-PROGRESS), ELPA Syncer, 2024/02/14
- [elpa] externals/denote adf8c6fdc8 02/33: Update denote-create-* commands to respect `denote-prompts`, ELPA Syncer, 2024/02/14
- [elpa] externals/denote ad13d32348 31/33: Clarify that absent denote-prompts mean nil for relevant denote-rename-file arguments, ELPA Syncer, 2024/02/14
- [elpa] externals/denote 1cdb49e227 32/33: Merge branch 'rename-honours-denote-prompts' of github.com:protesilaos/denote into rename-honours-denote-prompts, ELPA Syncer, 2024/02/14
- [elpa] externals/denote ab04f5b774 04/33: Fix typo in variable name in documentation, ELPA Syncer, 2024/02/14
- [elpa] externals/denote 60cf6b6125 05/33: Acknowledge maxbrieiev for commit 7d18b7b, ELPA Syncer, 2024/02/14
- [elpa] externals/denote 16b48265e2 08/33: Change how denote-rename-file passes DATE to denote-create-unique-file-identifier (per e9e9c8e), ELPA Syncer, 2024/02/14
- [elpa] externals/denote 5d4c78361a 10/33: Fix typo in denote-rename-file doc string, ELPA Syncer, 2024/02/14
- [elpa] externals/denote 6e050e4268 11/33: Start updating the manual for denote-rename-file (WORK-IN-PROGRESS), ELPA Syncer, 2024/02/14
- [elpa] externals/denote 6179fb7541 14/33: Ensure double spacing in a sentence of denote-rename-file docstring, ELPA Syncer, 2024/02/14