diff options
author | Leon Rische <leon.rische@me.com> | 2020-05-01 14:13:10 +0200 |
---|---|---|
committer | Leon Rische <leon.rische@me.com> | 2020-05-01 14:13:20 +0200 |
commit | a2aa55e2855e415ee52a46e36bdfa2060a01f744 (patch) | |
tree | 1c4052190a7b1b5b1f10c8b1c5ba2dc99a4091cf /awk | |
parent | ba0307070ccccdd195a96af9214b69340beecb1d (diff) |
Track tags in position indexer
Diffstat (limited to 'awk')
-rw-r--r-- | awk/index_cards.awk | 15 | ||||
-rw-r--r-- | awk/index_positions.awk | 50 | ||||
-rw-r--r-- | awk/utils.awk | 9 |
3 files changed, 69 insertions, 5 deletions
diff --git a/awk/index_cards.awk b/awk/index_cards.awk index 27c50b9..0785543 100644 --- a/awk/index_cards.awk +++ b/awk/index_cards.awk @@ -6,6 +6,8 @@ BEGIN { review_data_drawer = ":" or_default(review_data_drawer, "REVIEW_DATA") ":"; type_property = or_default(type_property, "FC_TYPE"); created_property = or_default(created_property, "FC_CREATED"); + + print "("; } ## Heading Parsing @@ -40,7 +42,18 @@ in_properties && /:END:/ { id = properties["ID"]; type = properties[type_property]; created = properties[created_property]; - print FILENAME "\t" id "\t" type "\t" suspended "\t" created; + print " (" \ + ":path \"" FILENAME "\"" \ + " :id \"" id "\"" \ + " :type " type \ + " :suspended " (suspended ? "t" : "nil") \ + " :created \"" created "\"" \ + ")" + in_properties = 0; in_card = 0; } + +END { + print ")"; +} diff --git a/awk/index_positions.awk b/awk/index_positions.awk index e409f52..c1c883c 100644 --- a/awk/index_positions.awk +++ b/awk/index_positions.awk @@ -7,14 +7,32 @@ BEGIN { review_data_drawer = ":" or_default(review_data_drawer, "REVIEW_DATA") ":"; type_property = or_default(type_property, "FC_TYPE"); created_property = or_default(created_property, "FC_CREATED"); + + print "("; +} + +BEGINFILE { + # Stack of parent headline tags, level 0 is used for filetags + parent_tags[0] = ""; +} + +## Filetags + +match($0, /#\+FILETAGS:[ \t]+(.*)/, a) { + parent_tags[0] = a[1]; } ## Heading Parsing -/^\*+[ \t]+.*$/ { +match($0, /^(\*)+[ \t]+.*$/, a) { + level = length(a[1]); + tags = "" + # tag re based on org-tag-re - match($0, /^\*+[ \t]+.*[ \t]+(:([a-zA-Z0-9_@#%]+:)+)$/, a) - tags = a[1] + if (match($0, /^\*+[ \t]+.*[ \t]+(:([a-zA-Z0-9_@#%]+:)+)$/, b) != 0) { + tags = b[1]; + } + parent_tags[level] = tags; id = "none"; @@ -24,6 +42,8 @@ BEGIN { } else { in_card = 0; } + + last_level = level; next } @@ -66,8 +86,30 @@ in_data && /^\|.*\|$/ { interval = trim($5); due = trim_surrounding($6); + inherited_tags = ""; + for (i = 0; i < level; i++) { + inherited_tags = combine_tags(inherited_tags, parent_tags[i]); + } + local_tags = parent_tags[level]; + if (!(filter_due == "1") || (due < now && suspended == "0")) { - print FILENAME "\t" id "\t" type "\t" suspended "\t" position "\t" ease "\t" box "\t" interval "\t" due "\t" inherited_tags "\t" local_tags; + print "(" \ + ":path \"" FILENAME "\"" \ + " :id \"" id "\"" \ + " :type " type \ + " :suspended " (suspended ? "t" : "nil") \ + " :position \"" position "\"" \ + " :ease " ease \ + " :box " box \ + " :interval " interval \ + " :due \"" due "\"" \ + " :inherited-tags \"" inherited_tags "\"" \ + " :local-tags \"" local_tags "\"" \ + ")" } } } + +END { + print ")"; +} diff --git a/awk/utils.awk b/awk/utils.awk index 01295a2..7384ea0 100644 --- a/awk/utils.awk +++ b/awk/utils.awk @@ -21,3 +21,12 @@ function time_days_ago(n) { function or_default(var, def) { return (var != "") ? var : def; } + +# Combine two tag strings +function combine_tags(tags1, tags2) { + if (tags1 == "") { + return tags2; + } else { + return substr(tags1, 0, length(tags1) - 1) tags2 + } +} |