Skip to content

Commit

Permalink
Filter out files with no cards in AWK indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
l3kn committed Mar 16, 2024
1 parent 3a614b9 commit 0ee02d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
43 changes: 22 additions & 21 deletions org-fc-awk.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,28 @@ ITAGS and LTAGS are strings `\":tag1:tag2:\"'"
;; p(file|card) for the plist-based output of AWK
;; o(file|card) for eieio objects
(if (string-prefix-p "(" output)
(mapcar
(lambda (pfile)
(let* ((ofile
(org-fc-file
:path (plist-get pfile :path)
:title (plist-get pfile :title)))
(ocards
(mapcar
(lambda (pcard)
(org-fc-card-from-plist
(plist-put
pcard :tags
(org-fc-awk-combine-tags
(plist-get pcard :inherited-tags)
(plist-get pcard :local-tags)))
ofile))
(plist-get pfile :cards))))
(oset ofile cards
(if filter (cl-remove-if-not filter ocards) ocards))
ofile))
(read (concat "(" output ")")))
(let (files)
(dolist (pfile (read (concat "(" output ")")))
(let* ((ofile
(org-fc-file
:path (plist-get pfile :path)
:title (plist-get pfile :title)))
(ocards
(mapcar
(lambda (pcard)
(org-fc-card-from-plist
(plist-put
pcard :tags
(org-fc-awk-combine-tags
(plist-get pcard :inherited-tags)
(plist-get pcard :local-tags)))
ofile))
(plist-get pfile :cards)))
(fcards (if filter (cl-remove-if-not filter ocards) ocards)))
(when fcards
(oset ofile cards fcards)
(push ofile files))))
(reverse files))
(error "Org-fc shell error: %s" output))))

;;; Footer
Expand Down
17 changes: 9 additions & 8 deletions tests/org-fc-indexer-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

(ert-deftest org-fc-test-index-malformed ()
(let ((files
'("malformed/no_review_data.org"
"malformed/no_properties.org"
"malformed/normal_swapped_drawers.org"
"malformed/unclosed_drawer1.org"
"malformed/unclosed_drawer2.org")))
(mapcar
#'org-fc-test-fixture
'("malformed/no_review_data.org"
"malformed/no_properties.org"
"malformed/normal_swapped_drawers.org"
"malformed/unclosed_drawer1.org"
"malformed/unclosed_drawer2.org"))))
(dolist (file files)
(org-fc-test-check-structure
'((:cards ()))
(org-fc-awk-index (list (org-fc-test-fixture file)))))))
(org-fc-test-check-structure '()
(org-fc-awk-index (list file))))))

(ert-deftest org-fc-test-escaping ()
(org-fc-test-check-structure
Expand Down

0 comments on commit 0ee02d7

Please sign in to comment.