Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect and use existing front matter when adding front matter #493

Open
juh2 opened this issue Dec 10, 2024 · 8 comments
Open

respect and use existing front matter when adding front matter #493

juh2 opened this issue Dec 10, 2024 · 8 comments

Comments

@juh2
Copy link

juh2 commented Dec 10, 2024

I am currently working on a silo where front matter is not complete, but the files have eg. titles. denote-add-front-matter does not evaluate the old title to make it the default. So I have to manually reuse the old title after adding front matter. Do I miss something? And is there a way to have this in denote-dired as kind of bulk add frontmatter?

@protesilaos
Copy link
Owner

Do you mean that you do not want to be prompted for the title? Or that you want it to read the title from the front matter instead of from the file name?

@juh2
Copy link
Author

juh2 commented Dec 10, 2024

I guess it would be a solution, if I wasn't asked and the title was leaved unchanged. But I think it gives me more optons if the first proposal for a title would be the title from the front matter.

protesilaos added a commit that referenced this issue Dec 11, 2024
Thanks to juh for asking about this in issue 493:
<#493>.
@protesilaos
Copy link
Owner

I just made the change to denote-add-front-matter. Please give it a try.

About having the same via Dired, let me take a look and work on it accordingly.

@juh2
Copy link
Author

juh2 commented Dec 11, 2024

If I updated correctly with straight (was using the release before) it inserts the filename part, not the title.

@protesilaos
Copy link
Owner

Maybe straight did something unexpected. Please evaluate the following and then try again:

(defun denote-add-front-matter (file title keywords signature)
  "Insert front matter at the top of FILE.

When called interactively, FILE is the return value of the
function `buffer-file-name'.  FILE is checked to determine
whether it is a note for Denote's purposes.

TITLE is a string.  Interactively, it is the user input at the
minibuffer prompt.

KEYWORDS is a list of strings.  Interactively, it is the user
input at the minibuffer prompt.  This one supports completion for
multiple entries, each separated by the `crm-separator' (normally
a comma).

SIGNATURE is a string.  Interactively, it is the user input at the
minibuffer prompt.

The purpose of this command is to help the user generate new
front matter for an existing note (perhaps because the user
deleted the previous one and could not undo the change).

This command does not rename the file (e.g. to update the
keywords).  To rename a file by reading its front matter as
input, use `denote-rename-file-using-front-matter'.

Note that this command is useful only for existing Denote notes.
If the user needs to convert a generic text file to a Denote
note, they can use one of the command which first rename the file
to make it comply with our file-naming scheme and then add the
relevant front matter.

[ NOTE: Please check with your minibuffer user interface how to
  provide an empty input.  The Emacs default setup accepts the
  empty minibuffer contents as they are, though popular packages
  like `vertico' use the first available completion candidate
  instead.  For `vertico', the user must either move one up to
  select the prompt and then type RET there with empty contents,
  or use the command `vertico-exit-input' with empty contents.
  That Vertico command is bound to M-RET as of this writing on
  2024-02-29 09:24 +0200. ]"
  (interactive
   (let* ((file buffer-file-name)
          (type (denote-filetype-heuristics file))
          (default-title (or (denote-retrieve-title-or-filename file type) ""))
          (default-keywords (string-join (denote-retrieve-filename-keywords-as-list file) ","))
          (default-signature (or (denote-retrieve-filename-signature file) "")))
     (list
      file
      (denote-title-prompt default-title "Add TITLE (empty to ignore)")
      (denote-keywords-sort (denote-keywords-prompt "Add KEYWORDS (empty to ignore)" default-keywords))
      (denote-signature-prompt default-signature "Add SIGNATURE (empty to ignore)"))))
  (when-let* ((denote-file-is-writable-and-supported-p file)
              (id (or (denote-retrieve-filename-identifier file) ""))
              (date (if (string-empty-p id) nil (date-to-time id)))
              (file-type (denote-filetype-heuristics file)))
    (denote--add-front-matter file title keywords signature date id file-type)))

@protesilaos
Copy link
Owner

By the way, I am rewriting this command to make it more useful and efficient overall.

@juh2
Copy link
Author

juh2 commented Dec 13, 2024

With the code above it works as expected. BTW: denote-rename-file-keywords makes what I want. Missing meta data like identifier, date and keywords is added without touching the title.

@protesilaos
Copy link
Owner

protesilaos commented Dec 14, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants