summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Rische <leon.rische@me.com>2022-11-30 12:45:24 +0100
committerLeon Rische <leon.rische@me.com>2022-11-30 12:45:24 +0100
commit44876305b38e11ac253817549a4271f926721c1e (patch)
tree62bf718d0cb1b65b04db56643d3cccdaeed82058
parent973a16a9561f1ed2fd7e4c5c614b5e5d15715b12 (diff)
Change indexing functions to group cards by files
-rw-r--r--org-fc-awk.el49
-rw-r--r--org-fc-cache.el45
-rw-r--r--org-fc-core.el15
3 files changed, 38 insertions, 71 deletions
diff --git a/org-fc-awk.el b/org-fc-awk.el
index 951c1a6..321b28d 100644
--- a/org-fc-awk.el
+++ b/org-fc-awk.el
@@ -87,27 +87,7 @@ ITAGS and LTAGS are strings `\":tag1:tag2:\"'"
(org-remove-uninherited-tags (split-string itags ":" t))
(split-string ltags ":" t))))
-(defun org-fc-awk-flatten-index (index)
- "Remove the file-level of INDEX."
- (mapcan
- (lambda (file)
- (mapcar
- (lambda (card)
- (plist-put card :path (plist-get file :path))
- (plist-put card :filetitle (plist-get file :title)))
- (plist-get file :cards)))
- index))
-
(defun org-fc-awk-index (paths &optional filter)
- "Find cards in PATHS matching an optional FILTER predicate.
-FILTER can be either nil or a function taking a single card as
- its input."
- (let ((index (org-fc-awk-index-paths paths)))
- (if filter
- (cl-remove-if-not filter index)
- index)))
-
-(defun org-fc-awk-index-paths (paths)
"Generate a list of all cards and positions in PATHS."
(let ((output (shell-command-to-string
(org-fc-awk--pipe
@@ -117,19 +97,22 @@ FILTER can be either nil or a function taking a single card as
"awk/index.awk"
:variables (org-fc-awk--indexer-variables)))))))
(if (string-prefix-p "(" output)
- (org-fc-awk-flatten-index
- (mapcar
- (lambda (file)
- (plist-put file :cards
- (mapcar
- (lambda (card)
- (plist-put
- card :tags
- (org-fc-awk-combine-tags
- (plist-get card :inherited-tags)
- (plist-get card :local-tags))))
- (plist-get file :cards))))
- (read output)))
+ (mapcar
+ (lambda (file)
+ (let ((cards
+ (mapcar
+ (lambda (card)
+ (plist-put
+ card :tags
+ (org-fc-awk-combine-tags
+ (plist-get card :inherited-tags)
+ (plist-get card :local-tags))))
+ (plist-get file :cards))))
+ (plist-put file :cards
+ (if filter
+ (cl-remove-if-not filter cards)
+ cards))))
+ (read output))
(error "Org-fc shell error: %s" output))))
(defun org-fc-awk-stats-reviews ()
diff --git a/org-fc-cache.el b/org-fc-cache.el
index 9168bd6..d830d1c 100644
--- a/org-fc-cache.el
+++ b/org-fc-cache.el
@@ -55,7 +55,7 @@
(gethash file hashes)))
(hash-table-keys hashes))))
;; Update changed files
- (dolist (new (org-fc-awk-index-files changed))
+ (dolist (new (org-fc-awk-index-paths changed))
(let* ((path (plist-get new :path))
(hash (gethash path hashes)))
(puthash
@@ -83,45 +83,16 @@ as its input."
(when (cl-some (lambda (p) (string-prefix-p p path)) paths)
;; Use push instead of `nconc' because `nconc' would break
;; the entries of the hash table.
- (if filter
- (dolist (card (cl-remove-if-not filter (plist-get file :cards)))
- (push (plist-put
- (plist-put card :path path)
- :filetitle
- (plist-get file :title)) res))
- (dolist (card (plist-get file :cards))
- (push
- (plist-put
- (plist-put card :path path)
- :filetitle
- (plist-get file :title)) res)))))
+ (push
+ (list :path path
+ :cards
+ (if filter
+ (cl-remove-if-not filter (plist-get file :cards))
+ (plist-get file :cards)))
+ res)))
org-fc-cache)
res))
-;; TODO: Check for awk errors
-;; TODO: This should go into the awk file
-(defun org-fc-awk-index-files (files)
- "Generate a list of all cards and positions in FILES.
-Unlike `org-fc-awk-index-paths', files are included directly in
-the AWK command and directories are not supported."
- (mapcar
- (lambda (file)
- (plist-put file :cards
- (mapcar
- (lambda (card)
- (plist-put
- card :tags
- (org-fc-awk-combine-tags
- (plist-get card :inherited-tags)
- (plist-get card :local-tags))))
- (plist-get file :cards))))
- (read
- (shell-command-to-string
- (org-fc-awk--command
- "awk/index.awk"
- :variables (org-fc-awk--indexer-variables)
- :input (mapconcat #'identity files " "))))))
-
;;; Cache Mode
(defun org-fc-cache--enable ()
diff --git a/org-fc-core.el b/org-fc-core.el
index db4ff86..5ff8be1 100644
--- a/org-fc-core.el
+++ b/org-fc-core.el
@@ -581,7 +581,20 @@ use `(and (type double) (tag \"math\"))'."
(if filter (setq filter (org-fc--compile-filter filter)))
- (funcall org-fc-index-function paths filter)))
+ (org-fc-index-flatten-file
+ (funcall org-fc-index-function paths filter))))
+
+(defun org-fc-index-flatten-file (index)
+ "Flatten INDEX into a list of cards.
+Relevant data from the file is included in each card element."
+ (mapcan
+ (lambda (file)
+ (mapcar
+ (lambda (card)
+ (plist-put card :path (plist-get file :path))
+ (plist-put card :filetitle (plist-get file :title)))
+ (plist-get file :cards)))
+ index))
(defun org-fc-index-flatten-card (card)
"Flatten CARD into a list of positions.