Make stylistic refinements to the helpers introduced in 8e6d83c

I was testing them and was too eager to commit before refining them.
Will need to write tests eventually, but I do not have time right now.
This commit is contained in:
Protesilaos 2026-05-01 18:48:34 +03:00
parent 8e6d83c652
commit 0ff9573362
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA

View file

@ -2784,23 +2784,27 @@ or `line', referring to what the function should retrieve."
(defun denote--get-front-matter-value-no-indentation (component line file-type) (defun denote--get-front-matter-value-no-indentation (component line file-type)
"Return the COMPONENT on LINE given the FILE-TYPE without any indentation." "Return the COMPONENT on LINE given the FILE-TYPE without any indentation."
(with-temp-buffer (when-let* ((key-regexp-fn (denote--get-component-key-regexp-function component))
(insert line) (regexp (funcall key-regexp-fn file-type)))
(goto-char (point-min)) (with-temp-buffer
(when (re-search-forward (funcall (denote--get-component-key-regexp-function component) file-type) nil t 1) (insert line)
(re-search-forward "\\s-*" (line-end-position) t) (goto-char (point-min))
(buffer-substring-no-properties (point) (line-end-position))))) (when (re-search-forward regexp nil t 1)
(re-search-forward "\\s-*" (line-end-position) t)
(buffer-substring-no-properties (point) (line-end-position))))))
(defun denote--rewrite-front-matter-line (component new-line file-type) (defun denote--rewrite-front-matter-line (component new-line file-type)
"Rewrite COMPONENT with NEW-LINE given the FILE-TYPE. "Rewrite COMPONENT with NEW-LINE given the FILE-TYPE.
Preserve the existing key and the spacing, if any, that follows it. Preserve the existing key and the spacing, if any, that follows it.
Return non-nil if successful." Return non-nil if successful."
(when (re-search-forward (funcall (denote--get-component-key-regexp-function component) file-type) nil t 1) (when-let* ((key-regexp-fn (denote--get-component-key-regexp-function component))
(let ((new-value (denote--get-front-matter-value-no-indentation component new-line file-type))) (regexp (funcall key-regexp-fn file-type))
(re-search-forward "\\s-*" (line-end-position) t) (_ (re-search-forward regexp nil t 1))
(delete-region (point) (line-end-position)) (new-value (denote--get-front-matter-value-no-indentation component new-line file-type)))
(insert new-value) (re-search-forward "\\s-*" (line-end-position) t)
t))) (delete-region (point) (line-end-position))
(insert new-value)
t))
;; These are private front matter retrieval functions, working with a content parameter ;; These are private front matter retrieval functions, working with a content parameter