summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Rische <leon.rische@me.com>2020-07-08 14:20:22 +0200
committerLeon Rische <leon.rische@me.com>2020-07-08 14:20:22 +0200
commit9e6b8619362d7cb5f92d016a045b8473feb788ae (patch)
tree000b36b32a930466f6b1f894d4092b9f16a0af65
parent9fcee5223d5951264cfc2a5d8dbfb500fda76d0a (diff)
Include headline text in awk output
-rw-r--r--awk/index.awk13
-rw-r--r--tests/org-fc-indexer-test.el40
2 files changed, 49 insertions, 4 deletions
diff --git a/awk/index.awk b/awk/index.awk
index 4646ddc..c389176 100644
--- a/awk/index.awk
+++ b/awk/index.awk
@@ -52,14 +52,20 @@ match($0, /#\+FILETAGS:[ \t]+(.*)/, a) {
## Heading Parsing
-match($0, /^(\*+)[ \t]+.*$/, a) {
+match($0, /^(\*+)[ \t]+(.*)$/, a) {
level = length(a[1]);
+ title = a[2];
tags = "";
# tag re based on org-tag-re
+ # this only guarantees that there is at least one tab/space
+ # between the headline text and the tags.
# TODO: Do this in a single match
- if (match($0, /^\*+[ \t]+.*[ \t]+(:([a-zA-Z0-9_@#%]+:)+)$/, b) != 0) {
- tags = b[1];
+ if (match(title, /^(.*)[ \t]+(:([a-zA-Z0-9_@#%]+:)+)$/, b) != 0) {
+ title = b[1];
+ # remove trailing tabs/spaces
+ sub(/[ \t]*$/, "", title);
+ tags = b[2];
}
parent_tags[level] = tags;
@@ -114,6 +120,7 @@ $0 ~ review_data_drawer {
print " (" \
":id " escape_string(properties["ID"]) \
+ " :title " escape_string(title) \
" :type " properties[type_property] \
" :created " parse_time(properties[created_property]) \
" :suspended " (suspended ? "t" : "nil") \
diff --git a/tests/org-fc-indexer-test.el b/tests/org-fc-indexer-test.el
index 2200fa0..1d37529 100644
--- a/tests/org-fc-indexer-test.el
+++ b/tests/org-fc-indexer-test.el
@@ -2,7 +2,7 @@
(require 'org-fc-test-helper)
(require 'ert)
-(ert-deftest org-fc-test-malformed ()
+(ert-deftest org-fc-test-index-malformed ()
(should (null (org-fc-awk-index-paths
(list (org-fc-test-fixture "malformed/no_review_data.org")))))
(should (null (org-fc-awk-index-paths
@@ -13,3 +13,41 @@
(list (org-fc-test-fixture "malformed/unclosed_drawer1.org")))))
(should (null (org-fc-awk-index-paths
(list (org-fc-test-fixture "malformed/unclosed_drawer2.org"))))))
+
+(ert-deftest org-fc-test-index ()
+ (let ((index (org-fc-awk-index-paths
+ (list
+ (org-fc-test-fixture "index/test.org")))))
+ (should (eq (length index) 3))
+ (let ((card1 (car index))
+ (card2 (cadr index))
+ (card3 (caddr index)))
+ (should
+ (equal (plist-get card1 :id)
+ "edee8940-5c9a-4c70-b1c4-f45c194c0c97"))
+ (should
+ (equal (plist-get card1 :local-tags)
+ ":fc:tag1:"))
+ (should
+ (equal (plist-get card1 :title)
+ "Headline"))
+
+ (should
+ (equal (plist-get card2 :id)
+ "59b3b102-aebd-44ba-a1fd-6dc912c34fcf"))
+ (should
+ (equal (plist-get card2 :local-tags)
+ ":fc:tag2:"))
+ (should
+ (equal (plist-get card2 :title)
+ "Headline 2"))
+
+ (should
+ (equal (plist-get card3 :id)
+ "a7ed2686-73e6-4780-825d-78cf4b2e5374"))
+ (should
+ (equal (plist-get card3 :local-tags)
+ ":fc:tag3:"))
+ (should
+ (equal (plist-get card3 :title)
+ "Headline 3:not_a_tag:")))))