~protesilaos/denote

Fix: Handle signature in denote-dired-rename-marked-files-with-keywords v1 APPLIED

Vedang Manerikar: 2
 Fix: Handle signature in denote-dired-rename-marked-files-with-keywords
 Fix: Ensure signature is sluggified correctly when renaming

 2 files changed, 3 insertions(+), 3 deletions(-)
I installed this patch as well. Thank you, Vedang!
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~protesilaos/denote/patches/46790/mbox | git am -3
Learn more about email & git

[PATCH 1/2] Fix: Handle signature in denote-dired-rename-marked-files-with-keywords Export this patch

I hit this bug when I called `M-x
denote-dired-rename-marked-files-with-keywords` on the file at point
in a dired buffer. The stack-trace is as follows:

```
Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
  replace-regexp-in-string("[][{}!@#$%^&*()=+'\"?,.|;:~`‘’“”/]*-" "" nil)
  denote--slug-no-punct(nil "-")
  denote-sluggify-signature(nil)
  denote-dired-rename-marked-files-with-keywords()
  ```

`denote-sluggify-signature` gets a `nil` input which it cannot handle.
This happens because the signature is extracted using
`denote-retrieve-filename-signature`, which can return a `nil` value.

The fix is to only call `denote-sluggify-signature` when we have a
signature to handle.
---
 denote.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/denote.el b/denote.el
index 23e074d..9d8e006 100644
--- a/denote.el
+++ b/denote.el
@@ -2530,7 +2530,7 @@ Specifically, do the following:
                 (file-type (denote-filetype-heuristics file))
                 (title (denote--retrieve-title-or-filename file file-type))
                 (extension (denote-get-file-extension file))
                 (new-name (denote-format-file-name dir id keywords (denote-sluggify title 'title) extension (denote-sluggify-signature signature))))
                 (new-name (denote-format-file-name dir id keywords (denote-sluggify title 'title) extension (when signature (denote-sluggify-signature signature)))))
            (denote-rename-file-and-buffer file new-name)
            (when (denote-file-is-writable-and-supported-p new-name)
              (if (denote--edit-front-matter-p new-name file-type)
-- 
2.42.0
Thank you, Vedang! I installed your patch.

[PATCH 2/2] Fix: Ensure signature is sluggified correctly when renaming Export this patch

Based on the bug found in the previous commit, I looked at all the
call-sites for `denote-sluggify-signature` and
`denote-retrieve-filename-signature` and found two other places:

1. `denote-rename-file`: Add check to ensure signature exists when
   trying to sluggify it.

2. `denote-rename-file-using-front-matter`: Sluggify the signature
   before creating the new file-name.
---
 denote.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/denote.el b/denote.el
index 9d8e006..c6137f6 100644
--- a/denote.el
+++ b/denote.el
@@ -2429,7 +2429,7 @@ place."
         (title (or title (denote--retrieve-title-or-filename file file-type)))
         (keywords (or keywords (denote-retrieve-keywords-value file file-type)))
         (signature (or signature (denote-retrieve-filename-signature file)))
         (new-name (denote-format-file-name dir id keywords (denote-sluggify title 'title) extension (denote-sluggify-signature signature)))
         (new-name (denote-format-file-name dir id keywords (denote-sluggify title 'title) extension (when signature (denote-sluggify-signature signature))))
         (max-mini-window-height denote-rename-max-mini-window-height))
    (when (or denote-rename-no-confirm (denote-rename-file-prompt file new-name))
      (denote-rename-file-and-buffer file new-name)
@@ -2573,7 +2573,7 @@ does internally."
             (signature (denote-retrieve-filename-signature file))
             (extension (denote-get-file-extension file))
             (dir (file-name-directory file))
             (new-name (denote-format-file-name dir id keywords sluggified-title extension signature)))
             (new-name (denote-format-file-name dir id keywords sluggified-title extension (when signature (denote-sluggify-signature signature)))))
        (when (or auto-confirm
                  (denote-rename-file-prompt file new-name))
          (denote-rename-file-and-buffer file new-name)
-- 
2.42.0
I installed this patch as well. Thank you, Vedang!