Function: denote-rename-file-using-front-matter

denote-rename-file-using-front-matter is an autoloaded, interactive and byte-compiled function defined in denote.el.

Signature

(denote-rename-file-using-front-matter FILE)

Documentation

Rename FILE using its front matter as input.

When called interactively, FILE is the variable buffer-file-name(var)/buffer-file-name(fun) 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 the user option denote-file-type(var)/denote-file-type(fun).

The values of denote-rename-confirmations, denote-save-buffers and denote-kill-buffers are respected.

Only the front matter lines that appear in the front matter template (as defined in denote-file-types) will be handled.

To change the identifier (date) of the note with this command, the identifier line (if present) of the front matter must be modified. Modifying the date line has no effect.

While this command generally does not modify the front matter, there are exceptions. The value of the date line will follow that of the identifier line. If they are both in the front matter template and the date line is missing, it will be added again. Similarly, if they are both in the front matter template and the date line is present and the identifier line has been removed, the date line will be removed as well. Also, if the keywords are out of order and denote-sort-keywords is non-nil, they will be sorted. There will be a prompt for this if denote-rename-confirmations contains rewrite-front-matter.

Construct the file name in accordance with the user option denote-file-name-components-order.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/denote-4.2.3/denote.el
;;;###autoload
(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 the user option `denote-file-type'.

The values of `denote-rename-confirmations',
`denote-save-buffers' and `denote-kill-buffers' are respected.

Only the front matter lines that appear in the front matter template (as
defined in `denote-file-types') will be handled.

To change the identifier (date) of the note with this command, the
identifier line (if present) of the front matter must be modified.
Modifying the date line has no effect.

While this command generally does not modify the front matter, there are
exceptions.  The value of the `date' line will follow that of the
`identifier' line.  If they are both in the front matter template and
the `date' line is missing, it will be added again.  Similarly, if they
are both in the front matter template and the `date' line is present and
the `identifier' line has been removed, the `date' line will be removed
as well.  Also, if the keywords are out of order and
`denote-sort-keywords' is non-nil, they will be sorted.  There will be a
prompt for this if `denote-rename-confirmations' contains
`rewrite-front-matter'.

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"))
  (let ((file-type (denote-filetype-heuristics file)))
    (unless (denote--file-has-front-matter-p file file-type)
      (user-error "The file does not appear to have a front matter"))
    (let* ((front-matter-template (denote--front-matter file-type))
           (components-in-template (denote--get-front-matter-components-order front-matter-template file-type))
           (title (if (memq 'title components-in-template)
                      (or (denote-retrieve-front-matter-title-value file file-type) "")
                    (or (denote-retrieve-filename-title file) "")))
           (keywords (if (memq 'keywords components-in-template)
                         (denote-retrieve-front-matter-keywords-value file file-type)
                       (denote-retrieve-filename-keywords-as-list file)))
           (signature (if (memq 'signature components-in-template)
                          (or (denote-retrieve-front-matter-signature-value file file-type) "")
                        (or (denote-retrieve-filename-signature file) "")))
           (identifier (if (memq 'identifier components-in-template)
                           (or (denote-retrieve-front-matter-identifier-value file file-type) "")
                         (or (denote-retrieve-filename-identifier file) "")))
           (date (when (memq 'date components-in-template)
                   (when-let* ((date-value (denote-retrieve-front-matter-date-value file file-type)))
                     (denote-valid-date-p date-value))))
           (denote-accept-nil-date t))
      (denote--rename-file file title keywords signature date identifier)
      (denote-update-dired-buffers))))