protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme
https://protesilaos.com/emacs/denote
GNU General Public License v3.0
541 stars 55 forks source link

rename files errors with wrong-type-argument stringp nil #401

Closed alperenkose closed 3 months ago

alperenkose commented 3 months ago

Hi,

I'm trying to rename files using denote-rename-file-using-front-matter in order to import them from plain markdown files which have frontmatters in the compatible format with denote. I'm using the markdown-yaml format for frontmatter.

At first I thought there could be something wrong with how I generated frontmatters for my markdown files but I have the same issue when I try denote-rename-file-using-front-matter even on denote generated markdown files.

Consider the following frontmatter:

---
title:      "Note with multiple tags"
date:       2024-07-31T00:21:51+03:00
tags:       ["emacs", "personal"]
identifier: "20240731T002151"
---

tags seperated with "," in a list..

I remove one of the tags and run denote-rename-file-using-front-matter but I receive a (wrong-type-argument stringp nil) error.

---
title:      "Note with multiple tags"
date:       2024-07-31T00:21:51+03:00
tags:       ["emacs"]
identifier: "20240731T002151"
---

tags seperated with "," in a list..

Please see the backtrace for the error below. I also get a similar error when I run denote-rename-file as well.

Could you please help what might be wrong?

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  denote--file-regular-writable-p(nil)
  denote-file-is-writable-and-supported-p(nil)
  denote-rename-file-using-front-matter(nil nil)
  funcall-interactively(denote-rename-file-using-front-matter nil nil)
  command-execute(denote-rename-file-using-front-matter record)
  (progn (command-execute command 'record) (add-to-history 'extended-command-history command-name))
  (condition-case err (progn (command-execute command 'record) (add-to-history 'extended-command-history command-name)) ((debug error) (if helm-M-x-always-save-history (progn (add-to-history 'extended-command-history command-name))) (signal (car err) (cdr err))))
  (let ((prefix-arg (or helm-current-prefix-arg helm-M-x-prefix-argument)) (command-name (symbol-name command))) (condition-case err (progn (command-execute command 'record) (add-to-history 'extended-command-history command-name)) ((debug error) (if helm-M-x-always-save-history (progn (add-to-history 'extended-command-history command-name))) (signal (car err) (cdr err)))))
  (progn (setq this-command command real-this-command command) (let ((prefix-arg (or helm-current-prefix-arg helm-M-x-prefix-argument)) (command-name (symbol-name command))) (condition-case err (progn (command-execute command 'record) (add-to-history 'extended-command-history command-name)) ((debug error) (if helm-M-x-always-save-history (progn (add-to-history 'extended-command-history command-name))) (signal (car err) (cdr err))))))
  (if command (progn (setq this-command command real-this-command command) (let ((prefix-arg (or helm-current-prefix-arg helm-M-x-prefix-argument)) (command-name (symbol-name command))) (condition-case err (progn (command-execute command 'record) (add-to-history 'extended-command-history command-name)) ((debug error) (if helm-M-x-always-save-history (progn (add-to-history ... command-name))) (signal (car err) (cdr err)))))))
  helm-M-x-execute-command(denote-rename-file-using-front-matter)

Thanks!

protesilaos commented 3 months ago

From: Alp Eren Kose @.***> Date: Wed, 31 Jul 2024 04:13:39 -0700

[... 33 lines elided]

Please see the backtrace for the error below. I also get a similar error when I run denote-rename-file as well.

Thank you for taking the time to report this! Which version of Denote are you using? This will help me track things down.

-- Protesilaos Stavrou https://protesilaos.com

alperenkose commented 3 months ago

I'm currently on 3.0.8 from elpa but I also had the same issue on 2.x - upgraded to latest version but didn't help.

protesilaos commented 3 months ago

From: Alp Eren Kose @.***> Date: Wed, 31 Jul 2024 05:13:13 -0700

I'm currently on 3.0.8 from elpa but I also had the same issue on 2.x

  • upgraded to latest version but didn't help.

This is strange. I cannot reproduce the issue. Please send me the configuration you are using and I will try again.

-- Protesilaos Stavrou https://protesilaos.com

alperenkose commented 3 months ago

Following is my configuration, I'm using Spacemacs btw. One thing I noticed now is, it is working if I mark the file in dired and then run denote-dired-rename-marked-files-using-front-matter however denote-rename-file-using-front-matter is still not working when my cursor is on the file in dired.

  (require 'denote)
  (setq denote-file-type "markdown-yaml")
  (setq denote-prompts '(title keywords subdirectory))
  (setq denote-dired-directories
        (list denote-directory
              (expand-file-name "~/Documents/notes")))
  (add-hook 'dired-mode-hook #'denote-dired-mode-in-directories)
  (setq denote-dired-directories-include-subdirectories t)
  (denote-rename-buffer-mode 1)
protesilaos commented 3 months ago

From: Alp Eren Kose @.***> Date: Wed, 31 Jul 2024 07:37:01 -0700

Following is my configuration, I'm using Spacemacs btw.

Everything looks okay here.

One thing I noticed now is, it is working if I mark the file in dired and then run denote-dired-rename-marked-files-using-front-matter however denote-rename-file-using-front-matter is still not working when my cursor is on the file in dired.

Oh, I think I understand what is happening:

Does this make sense? I think we may be able to make the command 'denote-dired-rename-marked-files-using-front-matter' also work from Dired, to recognise the file at point.

-- Protesilaos Stavrou https://protesilaos.com

alperenkose commented 3 months ago

Ohhh I'm sorry for not reading the documentation carefully 😞 Since the denote-rename-file works in dired I thought all the other rename commands work as well.. 🙂 I'm really sorry for wasting your time, denote-rename-file-using-front-matter works from within the buffer. I wish I knew elisp and implement this to work in dired though :)

protesilaos commented 3 months ago

From: Alp Eren Kose @.***> Date: Wed, 31 Jul 2024 08:11:02 -0700

Ohhh I'm sorry for not reading the documentation carefully 😞 Since the denote-rename-file works in dired I thought all the other rename commands work as well.. 🙂 I'm really sorry for wasting your time, denote-rename-file-using-front-matter works from within the buffer.

That's fine, no worries!

I wish I knew elisp and implement this to work in dired though :)

I will review the code. Maybe it is easy to do. Will keep you posted.

-- Protesilaos Stavrou https://protesilaos.com

protesilaos commented 3 months ago

I just pushed the change. Thank you!

protesilaos commented 3 months ago

If you want to test this before the new version is out, evaluate the following:

(defun denote-rename-file-using-front-matter (file)
  "Rename FILE using its front matter as input.
When called interactively, FILE is the variable `buffer-file-name' or
the Dired file at point, 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'.

The values of `denote-rename-confirmations' and `denote-save-buffers'
are respected.  Though there is no prompt to confirm the rewrite of the
front matter, since this is already done by the user.

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.

Construct the file name in accordance with the user option
`denote-file-name-components-order'."
  (interactive (list (or (dired-get-filename nil t) buffer-file-name)))
  (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))
           (front-matter-title (denote-retrieve-front-matter-title-value file file-type))
           (id (denote-retrieve-filename-identifier file)))
      (let ((denote-rename-confirmations (delq 'rewrite-front-matter denote-rename-confirmations)))
        (pcase-let* ((denote-prompts '())
                     (front-matter-keywords (denote-retrieve-front-matter-keywords-value file file-type))
                     (`(_title _keywords ,signature ,date)
                      (denote--rename-get-file-info-from-prompts-or-existing file)))
          (denote--rename-file file front-matter-title front-matter-keywords signature date)
          (denote-update-dired-buffers)))
    (user-error "No identifier or front matter for title")))