I like to structure my org-mode projects using the :CATEGORY: property, however categories seem not to be recognised by org-agenda-filter-by-regexp (bound to =). When viewing a rather large list of TODO items, it would be helpful to be able to narrow the list to matching categories.
I know that I can use org-agenda-filter-by-category (<), but this command must be executed on the category entry.
Is there a way to regexp filter the Org Agenda including categories?
The function below performs what I'd like, however I can't get it to work from the org-agenda dispatcher as a custom agenda command.
(defun rnkn/org-category-match (str)
"Org Agenda match TODO headlines matching :CATEGORY: property STR."
(interactive "sCategory: ")
(org-tags-view t (concat "CATEGORY={" str "}")))
Type M-x org-agenda RET m and then enter the regex -- e.g., PropertyDrawerName={regex}
Previous Answer (before the original poster edited the question) -- the current version of org-element-property / org-element-headline-parser uses all UPPERCASE letters for the property drawer arguments:
(defun example-one ()
(interactive)
(require 'org-element)
(let* (
(org-todo-keywords '((sequence "Active(a)" "Next Action(n)" "Reference(r)" "Someday(s)" "Delegated(d)" "|" "None(N)") ))
(sample-todo (concat
"* TASKS\n\n"
"** Active [#A] smith # drawer-one (fishing) | drawer-two (tennis). :lawlist:\n"
" DEADLINE: <2013-12-21 Sat 17:00> SCHEDULED: <2013-12-21 Sat>\n"
" :PROPERTIES:\n"
" :DRAWER-ONE: fishing\n"
" :DRAWER-TWO: tennis\n"
" :END:\n\n"
"** Next Action [#B] doe # drawer-one (football) | drawer-two (bowling). :fred:\n"
" DEADLINE: <2013-12-22 Sun 08:30> SCHEDULED: <2013-12-22 Sun>\n"
" :PROPERTIES:\n"
" :DRAWER-ONE: football\n"
" :DRAWER-TWO: bowling\n"
" :END:\n\n"
"* EVENTS\n\n"
"** Reference [#C] john # drawer-one (fishing) | drawer-two (sky-diving). :george:\n"
" DEADLINE: <2013-12-23 Mon 10:15> SCHEDULED: <2013-12-23 Mon>\n"
" :PROPERTIES:\n"
" :DRAWER-ONE: fishing\n"
" :DRAWER-TWO: sky-diving\n"
" :END:\n\n"
"* UNDATED\n\n"
"** Someday [#D] jane # drawer-one (basket-ball) | drawer-two (bowling). :sam:\n"
" DEADLINE: <2013-12-24 Tues 12:00> SCHEDULED: <2013-12-24 Tues>\n"
" :PROPERTIES:\n"
" :DRAWER-ONE: basket-ball\n"
" :DRAWER-TWO: bowling\n"
" :END:")))
(if (get-buffer "foo.org")
(progn
(switch-to-buffer "foo.org")
(erase-buffer)
(delete-other-windows))
(switch-to-buffer (get-buffer-create "foo.org")))
(org-mode)
(insert sample-todo)
(goto-char (point-min))
(or (y-or-n-p (format "For this example work, you must save this buffer as a file. Proceed with example?"))
(error "Canceled."))
(write-file "~/Desktop/foo.org" t)
(let* (
(filename (buffer-file-name))
(org-agenda-files (list filename))
(org-agenda-only-exact-dates t)
(org-agenda-show-all-dates nil)
(org-deadline-warning-days 0)
(org-agenda-time-grid nil)
(org-agenda-span 'month)
(org-agenda-entry-types '(:deadline))
(month "12")
(year "2013")
(org-agenda-start-day (concat year "-" month "-" "01"))
(drawer-content (read-string "basket-ball | bowling | fishing | football | sky-diving | tennis: " nil))
(org-agenda-skip-function (lambda ()
(org-back-to-heading t)
(let* (
(element (org-element-at-point))
(drawer-one (org-element-property :DRAWER-ONE element))
(drawer-two (org-element-property :DRAWER-TWO element)))
(cond
((not (or
(equal drawer-one drawer-content)
(equal drawer-two drawer-content)))
(org-end-of-subtree t))
(t nil) )) )))
(org-agenda-list))))
(defun example-two ()
(interactive)
(let* (
(drawer (read-string "Select a property drawer (e.g., ToodledoFolder): "))
(drawer-content (read-string (concat "Select the content of the " drawer " property drawer (e.g., EVENTS): "))))
(org-tags-view nil (concat drawer "=\"" drawer-content "\"" ))))
I'm using the following function to filter by category (solves the problem of < ).
(defun stu/org-agenda-filter-by-category ()
"Filter lines in the agenda buffer that have a specific category."
(interactive)
(let ((cat (read-string "Select the category: ")))
;;(stu/show-agenda-and-todo)
(org-agenda-filter-apply
(setq org-agenda-category-filter
(list (concat "+" cat))) 'category)))
I use (stu/show-agenda-and-todo) to make sure it filters every possible task, not only the ones shown in the buffer.
Related
I get this error when I Deploy a Hello World contract with Kadena Chainweaver on VM (https://chainweaver-builds.s3.amazonaws.com/2.2/kadena-chainweaver-vm-2.2.0.1.ova):
Failure: Tx Failed: Keyset failure (keys-any)
This is the contract I'm trying to Deploy(It's the default hello world that exists when you create a chainweaver account):
;;
;; "Hello, world!" smart contract/module
;;
;; To try it out, click "Load into REPL" and type into the repl:
;; (free.hello-world.set-message "universe")
;; (free.hello-world.greet)
;;
;; Check lines 21 and 34 to play with Formal Verification
;;
(namespace "free")
;; Define the module.
(module hello-world MODULE_ADMIN
"A smart contract to greet the world."
; no-op module admin for example purposes.
; in a real contract this could enforce a keyset, or
; tally votes, etc.
(defcap MODULE_ADMIN () true)
(defschema message-schema
#doc "Message schema"
#model [(invariant (!= msg ""))]
msg:string)
(deftable
message:{message-schema})
(defun set-message
(
m:string
)
"Set the message that will be used next"
; uncomment the following to make the model happy!
;(enforce (!= m "") "set-message: must not be empty")
(write message "0" {"msg": m})
)
(defun greet ()
"Do the hello-world dance"
(with-default-read message "0" { "msg": "" } { "msg":= msg }
(format "Hello {}!" [msg])))
)
(create-table message)
(set-message "world")
(greet)
Failure: Tx Failed: Keyset failure (keys-any)
The problem is sovled when I changed the module name from hello-world to something else.
Change this:
;; Define the module.
(module hello-world MODULE_ADMIN
"A smart contract to greet the world."
to this:
;; Define the module.
(module hello-world-YOUR-UNIQUE-NAME MODULE_ADMIN
"A smart contract to greet the world."
I'm writing a function, inDayRange, which takes two days (a start day and an end day) and a list of event structures and produces a new list where each element in the new list is only the name of all events which occurred between the two days (including start day and end day) but in any month or year.
(struct event (name day month year xlocation ylocation) #:transparent)
(define e1 (event "new years" 1 "Jan" 2021 0 0))
(define e2 (event "valentines" 14 "Feb" 2021 2 2))
(define e3 (event "my birthday" 6 "Mar" 2021 20 20))
(define e4 (event "tyler's birthday" 10 "Sep" 2020 23 23))
(define l1 (list e1 e2 e3 e4))
(define (inDayRange start end events)
(filter (lambda (e) (>= end (event-day e) start)) events))
I have the function written to filter what events occurred between the two days, but it returns a list of event structures. How do I produce a list of just the names of the events?
When running a janet test suite with the jpm command there is no listing of test cases.
$ jpm test
running test/test.janet ...
Failed: (= "hello" "holla")
Expected: "hello"
Actual: "holla"
Test: this should faild
Tests: 1/3 passed
Duration: 0.000 seconds
What I am looking for is to have an output similar to the one that you see when you run go test -v or pytest -v.
This is possible if one uses testament:
With testament the tests are written as:
(import testament :prefix "" :exit true)
(deftest one-plus-one
(is (= 2 (+ 1 1)) "1 + 1 = 2"))
(deftest two-plus-two
(is (= 5 (+ 2 2)) "2 + 2 = 5"))
(deftest test-should-fail
(is (= "hello" "holla") "should fail"))
Each test case is defined as:
(deftest <testname> (is <assertion>) <note>)
Testament allows defining a function which will be called after each test:
(set-on-result-hook reporter)
(run-tests!)
In this case, reporter can be defined as:
(defn reporter
"pretty report"
[result]
(var symbol "\e[31m✕\e[0m")
(if (result :passed?) (set symbol "\e[32m✓\e[0m"))
(print symbol " " (result :note))
)
The result will be:
$ jpm test
running test/test.janet ...
✓ 1 + 1 = 2
✕ should fail
✕ 2 + 2 = 5
> Failed: two-plus-two
Assertion: 2 + 2 = 5
Expect: 5
Actual: 4
> Failed: test-should-fail
Assertion: should fail
Expect: "hello"
Actual: "holla"
-----------------------------------
3 tests run containing 3 assertions
1 tests passed, 2 tests failed
-----------------------------------
In a Linux terminal the x will be red, and ✓ will be green.
The complete test code:
$ cat test/testam.janet
(import testament :prefix "" :exit true)
(deftest one-plus-one
(is (= 2 (+ 1 1)) "1 + 1 = 2"))
(deftest two-plus-two
(is (= 5 (+ 2 2)) "2 + 2 = 5"))
(deftest test-should-fail
(is (= "hello" "holla") "should fail"))
(defn reporter
"pretty report"
[result]
(var symbol "\e[31m✕\e[0m")
(if (result :passed?) (set symbol "\e[32m✓\e[0m"))
(print symbol " " (result :note))
)
(set-on-result-hook reporter)
(run-tests!)
(I had a previous question here, and assumed I wouldn't have issues getting to core.async).
Given input data such as this:
(require '[clojure.core.async :as a])
(def input-data
[{:itm_na 1 :seq_no 1 :doc_img "this is a very long "}
{:itm_na 1 :seq_no 2 :doc_img "sentence from a mainframe "}
{:itm_na 1 :seq_no 3 :doc_img "system that was built before i was "}
{:itm_na 1 :seq_no 4 :doc_img "born."}
{:itm_na 2 :seq_no 1 :doc_img "this is a another very long "}
{:itm_na 2 :seq_no 2 :doc_img "sentence from the same mainframe "}
{:itm_na 3 :seq_no 1 :doc_img "Ok here we are again. "}
{:itm_na 3 :seq_no 2 :doc_img "The mainframe only had 40 char per field so"}
{:itm_na 3 :seq_no 3 :doc_img "they broke it into multiple rows "}
{:itm_na 3 :seq_no 4 :doc_img "which seems to be common"}
{:itm_na 3 :seq_no 5 :doc_img " for the time. "}
{:itm_na 3 :seq_no 6 :doc_img "thanks for your help."}])
partition-by (as expected) clumps my data into seq's (for later collapsing):
(count (partition-by :itm_na input-data ))
;;=> 3
However, when i try to do this with a core.async pipeline for some reason it
doesn't seem to do the same... How do i get the stateful transducer part of
partition-by actually preserve state when in an async pipeline?
(let
[source-chan (a/to-chan input-data)
target-chan (a/chan 100)
xf (comp (partition-by :itm_na))
]
(a/pipeline 1
target-chan
xf
source-chan)
(count (<!! (a/into [] target-chan))))
;;=>12
This should be 3?
Strangely, when I bind the xf to the channel like below I get my expected result. I'm not sure why a/pipeline behaves differently.
(let [xf (comp (partition-by :itm_na))
ch (a/chan 1 xf)]
(a/onto-chan ch input-data)
(count (<!! (a/into [] ch))))
=>3
From the doc... mentions that stateful bit:
(clojure.repl/doc partition-by)
-------------------------
clojure.core/partition-by
([f] [f coll])
Applies f to each value in coll, splitting it each time f returns a
new value. Returns a lazy seq of partitions. Returns a stateful
transducer when no collection is provided.
This particular case was briefly highlighted by Rich Hickey in his talk: you cannot use pipeline with stateful transducers, basically because of pipeline's parallel nature.
I have a function
(defn f-test [c-width] (format "%-(c-width)s" "boogey"))
This is what happens when I try to evaluate it
(f-test 10)
FormatFlagsConversionMismatchException Conversion = c, Flags = ( java.util.Formatter$FormatSpecifier.failMismatch (Formatter.java:4041)
But this is what I am trying to do
(format "%-10s" "boogey")
"boogey "
how can I substitute in c-width inside the format call?
Try this one:
(defn f-test
[c-width]
(format (str "%-" c-width "s") "boogey"))