[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 299b8970ee 095/355: Add support for notes in Mar
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 299b8970ee 095/355: Add support for notes in Markdown and Plain Text |
Date: |
Sun, 26 Jun 2022 23:58:03 -0400 (EDT) |
branch: externals/denote
commit 299b8970ee02f2bace0e0cef0346fb2ffab0021f
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add support for notes in Markdown and Plain Text
The new user option 'denote-file-type' lets the user pick between the
aforementioned two or Org (which remains the default).
---
README.org | 18 ++++++++++----
denote.el | 82 +++++++++++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 76 insertions(+), 24 deletions(-)
diff --git a/README.org b/README.org
index ee6c2eb000..661e31dd46 100644
--- a/README.org
+++ b/README.org
@@ -83,7 +83,7 @@ the creation of such files.
Every note produced by Denote follows this pattern:
-: DATE--TITLE--KEYWORDS.org
+: DATE--TITLE--KEYWORDS.EXTENSION
The =DATE= field represents the date in year-month-day format followed
by the capital letter =T= (for "time") and the current time in
@@ -104,14 +104,20 @@ one-word-long must be written with an underscore. So when
=emacs_library= appears in a file name, it is interpreted as a single
keyword, whereas =emacs+library= are two distinct keywords.
+#+vindex: denote-file-type
+The =EXTENSION= is the file type. By default, it is =.org= (~org-mode~)
+though the user option ~denote-file-type~ provides support for Markdown
+(=.md= which runs ~markdown-mode~) and plain text (=.txt.= via
+~text-mode~). Consult its doc string for the minutia.
+
Examples:
: 20220107T124941--plentiful-and-predictable-liquidity--economics.org
-: 20220214T104945--git-patch-formatting--emacs+git.org
-: 20220420T113805--this-is-a-test--three_word_keyword.org
+: 20220214T104945--git-patch-formatting--emacs+git.md
+: 20220420T113805--this-is-a-test--three_word_keyword.txt
-While files end in the =.org= extension, the Denote code base does not
-actually depend on org.el and/or its accoutrements.
+While files end in the =.org= extension by default, the Denote code base
+does not actually depend on org.el and/or its accoutrements.
#+vindex: denote-directory
Notes are stored as a flat list in the ~denote-directory~ (i.e. no
@@ -413,6 +419,8 @@ Everything is in place to set up the package.
'("emacs" "philosophy" "politics" "economics"))
(setq denote-infer-keywords t)
(setq denote-sort-keywords t)
+(setq denote-file-type nil) ; default is Org mode, else set `markdown' or
`text'
+
(setq denote-front-matter-date-format 'org-timestamp)
(require 'denote-link)
diff --git a/denote.el b/denote.el
index 0bc0ae3cbc..454398fb64 100644
--- a/denote.el
+++ b/denote.el
@@ -85,6 +85,23 @@ If nil, show the keywords in their given order."
:group 'denote
:type 'boolean)
+(defcustom denote-file-type nil
+ "The file type extension for new notes.
+
+By default (a nil value), the file type is that of Org mode.
+
+When the value is the symbol `markdown', the file type is that of
+Markdown mode.
+
+When the value is `text', the file type is that of Text mode.
+
+Any other non-nil value is the same as the default."
+ :type '(choice
+ (const :tag "Org mode (default)" nil)
+ (const :tag "Markdown" markdown)
+ (const :tag "Plain text" text))
+ :group 'denote)
+
(defcustom denote-front-matter-date-format nil
"Date format in the front matter (file header) of new notes.
@@ -253,13 +270,6 @@ output is sorted with `string-lessp'."
(mapconcat #'downcase keywords "+")
keywords))
-(defun denote--keywords-capitalize (keywords)
- "`capitalize' KEYWORDS output of `denote--keywords-prompt'."
- (if (and (> (length keywords) 1)
- (not (stringp keywords)))
- (mapconcat #'capitalize keywords ", ")
- (capitalize keywords)))
-
(defun denote--keywords-add-to-history (keywords)
"Append KEYWORDS to `denote--keyword-history'."
(if-let ((listed (listp keywords))
@@ -275,30 +285,63 @@ output is sorted with `string-lessp'."
;;;; New note
-(defun denote--format-file (path id keywords slug &optional extension)
+(defun denote--file-extension ()
+ "Return file type extension based on `denote-file-type'."
+ (pcase denote-file-type
+ ('markdown ".md")
+ ('text ".txt")
+ (_ ".org")))
+
+(defun denote--format-file (path id keywords slug extension)
"Format file name.
PATH, ID, KEYWORDS, SLUG are expected to be supplied by `denote'
or equivalent: they will all be converted into a single string.
-
-Optional EXTENSION is the file type extension. Use .org if none
-is specified."
+EXTENSION is the file type extension, either a string which
+include the starting dot or the return value of
+`denote--file-extension'."
(let ((kws (if denote-infer-keywords
(denote--keywords-combine keywords)
keywords))
- (ext (or extension ".org")))
+ (ext (or extension (denote--file-extension))))
(format "%s%s--%s--%s%s" path id slug kws ext)))
+(defun denote--file-meta-keywords (keywords)
+ "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."
+ (if (and (> (length keywords) 1)
+ (not (stringp keywords)))
+ (mapconcat #'downcase keywords " ")
+ (downcase keywords)))
+
(defun denote--file-meta-header (title date keywords id)
"Front matter for new notes.
TITLE, DATE, KEYWORDS, FILENAME, ID are all strings which are
provided by `denote-new-note'."
- (let ((kw (denote--keywords-capitalize keywords)))
- (concat "#+title: " title "\n"
- "#+date: " date "\n"
- "#+filetags: " kw "\n"
- "#+identifier: " id "\n"
- "\n")))
+ (let ((kw (denote--file-meta-keywords keywords)))
+ (pcase denote-file-type
+ ('markdown (concat "---" "\n"
+ "title: " title "\n"
+ "date: " date "\n"
+ "tags: " kw "\n"
+ "identifier: " id "\n"
+ "---" "\n"
+ "\n"))
+
+ ('text (concat "title: " title "\n"
+ "date: " date "\n"
+ "tags: " kw "\n"
+ "identifier: " id "\n"
+ (make-string 27 ?-) "\n"
+ "\n"))
+
+ (_ (concat "#+title: " title "\n"
+ "#+date: " date "\n"
+ "#+filetags: " kw "\n"
+ "#+identifier: " id "\n"
+ "\n")))))
(defun denote--path (title keywords)
"Return path to new file with TITLE and KEYWORDS.
@@ -308,7 +351,8 @@ Format current time, else use optional ID."
(file-name-as-directory denote-directory)
(format-time-string denote--id)
keywords
- (denote--sluggify title))))
+ (denote--sluggify title)
+ (denote--file-extension))))
(defun denote--date ()
"Expand the date for a new note's front matter."
- [elpa] externals/denote 3e2b560548 099/355: Elaborate on the Overview of Denote, (continued)
- [elpa] externals/denote 3e2b560548 099/355: Elaborate on the Overview of Denote, ELPA Syncer, 2022/06/27
- [elpa] externals/denote cfe6e98e7b 090/355: Stop recording the file path in the front matter, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 2bc5df6011 103/355: denote-file-type: 'markdown-yaml', not 'markdown', ELPA Syncer, 2022/06/27
- [elpa] externals/denote d83c166c0d 125/355: Fix regexp for keywords, ELPA Syncer, 2022/06/27
- [elpa] externals/denote ebdacb3fea 073/355: Update doc string of denote-directory function, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 91f4780779 083/355: Merge pull request #3 from kaushalmodi/add-gitignore, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 17ad20f356 097/355: Document section on front matter, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 929157d424 089/355: Stop using link abbreviation, ELPA Syncer, 2022/06/27
- [elpa] externals/denote a809e9ea1d 087/355: Clarify active development; things might break, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 3f9bfcb74e 101/355: Name the FSF as the copyright holder, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 299b8970ee 095/355: Add support for notes in Markdown and Plain Text,
ELPA Syncer <=
- [elpa] externals/denote 112a12e6e5 130/355: Remove duplicate word from face names, ELPA Syncer, 2022/06/27
- [elpa] externals/denote bca23b3e3d 115/355: Clarify how front matter variables are used, ELPA Syncer, 2022/06/27
- [elpa] externals/denote f91d2472c3 128/355: Make the field delimiter face a bit more subtle, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 8a35382067 126/355: Rename internal variable for clarity, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 308322afab 108/355: Fix markdown-toml identifier value, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 11be1d6b40 123/355: Change "tml" to "toml" in denote-toml-front-matter, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 6000313eec 118/355: Enforce sluggification of keywords; document it, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 82eeb381dc 110/355: Make all front matter abstractions consistent, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 73dc07ac00 113/355: Make front matter variables "public", ELPA Syncer, 2022/06/27
- [elpa] externals/denote 21e415e2e7 111/355: Remove obsolete symbol of command, ELPA Syncer, 2022/06/27