Function: denote-change-file-type-and-front-matter

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

Signature

(denote-change-file-type-and-front-matter FILE NEW-FILE-TYPE)

Documentation

Change file type of FILE and add an appropriate front matter.

If in Dired, consider FILE to be the one at point, else the current file, else prompt with minibuffer completion for one.

Add a front matter in the format of the NEW-FILE-TYPE at the beginning of the file.

Retrieve the title of FILE from a line starting with a title field in its front matter, depending on the previous file type (e.g. #+title for Org). The same process applies for keywords.

As a final step, ask for confirmation, showing the difference between old and new file names.

Important note: No attempt is made to modify any other elements of the file. This needs to be done manually.

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-change-file-type-and-front-matter (file new-file-type)
  "Change file type of FILE and add an appropriate front matter.

If in Dired, consider FILE to be the one at point, else the
current file, else prompt with minibuffer completion for one.

Add a front matter in the format of the NEW-FILE-TYPE at the
beginning of the file.

Retrieve the title of FILE from a line starting with a title
field in its front matter, depending on the previous file
type (e.g.  #+title for Org).  The same process applies for
keywords.

As a final step, ask for confirmation, showing the difference
between old and new file names.

Important note: No attempt is made to modify any other elements
of the file.  This needs to be done manually.

Construct the file name in accordance with the user option
`denote-file-name-components-order'."
  (interactive
   (list
    (denote--rename-dired-file-or-current-file-or-prompt)
    (denote--valid-file-type (or (denote-file-type-prompt) denote-file-type))))
  (let* ((initial-state (if (find-buffer-visiting file) 'visited 'not-visited))
         (dir (file-name-directory file))
         (old-file-type (denote-filetype-heuristics file))
         (id (or (denote-retrieve-filename-identifier file) ""))
         (date (denote-retrieve-front-matter-date-value file old-file-type))
         (title (or (denote-retrieve-title-or-filename file old-file-type) ""))
         (keywords (denote-retrieve-front-matter-keywords-value file old-file-type))
         (signature (or (denote-retrieve-filename-signature file) ""))
         (new-extension (denote--file-extension new-file-type))
         (new-name (denote-format-file-name dir id keywords title new-extension signature))
         (max-mini-window-height denote-rename-max-mini-window-height))
    (when (denote-rename-file-prompt file new-name)
      (denote-rename-file-and-buffer file new-name)
      (denote-update-dired-buffers)
      (when (and (denote-file-is-writable-and-supported-p new-name)
                 (denote-add-front-matter-prompt new-name))
        (denote-prepend-front-matter new-name title keywords signature date id new-file-type)
        (denote--handle-save-and-kill-buffer 'rename new-name initial-state)))))