emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote eb1131af24 2/7: Refactor denote--format-front-ma


From: ELPA Syncer
Subject: [elpa] externals/denote eb1131af24 2/7: Refactor denote--format-front-matter-keywords
Date: Wed, 10 Aug 2022 00:57:41 -0400 (EDT)

branch: externals/denote
commit eb1131af2496c23cb99387c01fd4804dd81ebae5
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>

    Refactor denote--format-front-matter-keywords
    
    - Make type parameter mandatory
    - Delete denote--format-markdown-keywords and
    denote--format-org-keywords
---
 denote.el | 36 +++++++++---------------------------
 1 file changed, 9 insertions(+), 27 deletions(-)

diff --git a/denote.el b/denote.el
index 5f34344ae8..ee2aa68e5a 100644
--- a/denote.el
+++ b/denote.el
@@ -655,35 +655,17 @@ which include the starting dot or the return value of
       (setq file-name (concat file-name "__" kws)))
     (concat file-name ext)))
 
-(defun denote--format-markdown-keywords (keywords)
-  "Quote, downcase, and comma-separate elements in KEYWORDS."
-  (format "[%s]" (mapconcat (lambda (k)
-                              (format "%S" (downcase k)))
-                            keywords ", ")))
-
-(defun denote--format-org-keywords (keywords)
-  "Quote, downcase, and colon-separate elements in KEYWORDS."
-  (format ":%s:" (mapconcat (lambda (k)
-                              (downcase k))
-                            keywords ":")))
-
-(defun denote--format-front-matter-keywords (keywords &optional type)
-  "Prepare KEYWORDS for inclusion in the file's front matter.
-Parse the output of `denote--keywords-prompt', using `downcase'
-on the keywords and separating them by two spaces.  A single
-keyword is just downcased.
-
-With optional TYPE, format the keywords accordingly (this might
-be `toml' or, in the future, some other spec that needss special
-treatment)."
-  (let ((kw (denote--sluggify-keywords keywords)))
+(defun denote--format-front-matter-keywords (keywords type)
+  "Format KEYWORDS according to TYPE for the file's front matter.
+Keywords are downcased."
+  (let ((kw (mapcar #'downcase (denote--sluggify-keywords keywords))))
     (cond
      ((or (eq type 'markdown-toml) (eq type 'markdown-yaml) (eq type 'md))
-      (denote--format-markdown-keywords kw))
+      (format "[%s]" (mapconcat (lambda (k) (format "%S" k)) kw ", ")))
      ((eq type 'text)
-      (mapconcat #'downcase kw "  "))
-     (t
-      (denote--format-org-keywords kw)))))
+      (string-join kw "  "))
+     ((eq type 'org)
+      (format ":%s:" (string-join kw ":"))))))
 
 (defun denote--front-matter-keywords-to-list (file)
   "Return keywords from front matter of FILE as list of strings.
@@ -764,7 +746,7 @@ else that variable is used."
                      (denote--format-front-matter-keywords keywords 'text)
                      id denote-text-front-matter-delimiter))
       (_ (format denote-org-front-matter title date
-                 (denote--format-front-matter-keywords keywords) id)))))
+                 (denote--format-front-matter-keywords keywords 'org) id)))))
 
 (defun denote--path (title keywords &optional dir id)
   "Return path to new file with TITLE and KEYWORDS.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]