-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
Now properties can have multiple lines in the metadata section. The new const ekg-property-multivalue-type controls how multivalued properties act. This fixes #110.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,9 +180,18 @@ backups in your database after it has been created, run | |
(defvar ekg-metadata-parsers '(("Tags" . ekg--metadata-update-tag) | ||
("Resource" . ekg--metadata-update-resource) | ||
("Title" . ekg--metadata-update-title)) | ||
"Metadata fields to functions for updating data based on buffer test. | ||
Each function updates the buffer's `ekg-note' with the results of the field. | ||
The function takes one argument, the field metadata property value.") | ||
"Metadata fields to functions for updating data based on buffer text. | ||
Each function updates the buffer's `ekg-note' with the results of | ||
the field. The function takes one argument, a list of the field | ||
metadata property values for multivalue types, or a single one | ||
for single value types. If `ekg-property-multivalue-type' has an | ||
entry, it is a multivalue type.") | ||
|
||
(defconst ekg-property-multivalue-type '(("Tags" . comma) | ||
("Title" . line)) | ||
"Defines per typehow multiple values are separated. | ||
The values are symbols, COMMA means a comma-separated value. LINE | ||
means each value gets its own property line.") | ||
|
||
(defvar ekg-metadata-labels '((:titled/title . "Title")) | ||
"Alist of properties that can be on the note and their labels. | ||
|
@@ -892,13 +901,18 @@ The ID represents meaningful resource to the user, other than auto-generated id. | |
(mapconcat (lambda (tag) (format "%s" tag)) | ||
(ekg-note-tags note) ", "))) | ||
(map-apply (lambda (k v) | ||
(when-let (label (cdr (assoc k ekg-metadata-labels))) | ||
(insert (ekg--metadata-string | ||
label | ||
(if (listp v) | ||
(mapconcat (lambda (v) (format "%s" v)) | ||
v ", ") | ||
(format "%s" v)))))) | ||
(when-let ((label (assoc-default k ekg-metadata-labels))) | ||
(if (listp v) | ||
(pcase (assoc-default label ekg-property-multivalue-type) | ||
('line (cl-loop for val in v do | ||
(insert (ekg--metadata-string label val)))) | ||
('comma (insert (ekg--metadata-string | ||
label | ||
(if (listp v) | ||
|
||
(mapconcat (lambda (v) (format "%s" v)) | ||
v ", ") | ||
(format "%s" v))))))))) | ||
(ekg-note-properties note)) | ||
(buffer-string)))) | ||
|
||
|
@@ -1177,8 +1191,13 @@ attempt the completion." | |
(save-excursion (skip-chars-forward "^:\s\t\n") (point)) | ||
(completion-table-dynamic | ||
(lambda (_) | ||
;; Complete all fields, except single-value fields (which have no | ||
;; entry in ekg-property-multivalue-type) with an existing field | ||
;; already in existence. | ||
(seq-difference (mapcar #'car ekg-metadata-parsers) | ||
(mapcar #'car (ekg--metadata-fields nil))))))) | ||
(seq-difference | ||
(mapcar #'car (ekg--metadata-fields nil)) | ||
(mapcar #'car ekg-property-multivalue-type))))))) | ||
|
||
(defun ekg--tags-cap-exit (completion finished) | ||
"Cleanup after completion at point happened in a tag. | ||
|
@@ -1243,13 +1262,12 @@ The metadata fields are comma separated." | |
|
||
(defun ekg--metadata-update-tag (val) | ||
"Update the tag field from the metadata VAL." | ||
(setf (ekg-note-tags ekg-note) (ekg--split-metadata-string val))) | ||
(setf (ekg-note-tags ekg-note) val)) | ||
|
||
(defun ekg--metadata-update-title (val) | ||
"Update the title field from the metadata VAL." | ||
(setf (ekg-note-properties ekg-note) | ||
(plist-put (ekg-note-properties ekg-note) :titled/title | ||
(ekg--split-metadata-string val)))) | ||
(plist-put (ekg-note-properties ekg-note) :titled/title val))) | ||
|
||
(defun ekg--metadata-update-resource (val) | ||
"Update the resource to the metadata VAL." | ||
|
@@ -1272,11 +1290,21 @@ If EXPECT-VALID is true, warn when we encounter an unparseable field." | |
|
||
(defun ekg--update-from-metadata () | ||
"Update the `ekg-note' object from the metadata." | ||
(cl-loop for field in (ekg--metadata-fields t) | ||
(cl-loop with values = (make-hash-table :test 'equal) | ||
for (field . value) in (ekg--metadata-fields t) | ||
do | ||
(if-let (func (assoc (car field) ekg-metadata-parsers)) | ||
(funcall (cdr func) (cdr field)) | ||
(warn "EKG: No function found for field %s" (car field))))) | ||
(pcase (assoc-default field ekg-property-multivalue-type) | ||
('line (push value (gethash field values))) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
qingshuizheng
Contributor
|
||
('comma (push (ekg--split-metadata-string value) (gethash field values))) | ||
(_ (setf (gethash field values) value))) | ||
finally return | ||
(maphash (lambda (key val) | ||
(if-let (func (assoc key ekg-metadata-parsers)) | ||
(funcall (cdr func) (if (listp val) | ||
(nreverse (flatten-list val)) | ||
val)) | ||
(warn "EKG: No function found for field %s" key))) | ||
values))) | ||
|
||
(defun ekg-capture-finalize () | ||
"Save the current note." | ||
|
Empty string should be excluded when being parsed? So change this line to:
Before:
After: