I had this sent to me this morning and thought it would be useful to discuss in the forum:
Hi beorg team, I’m trying to create a new, saved search query with Scheme, and am having trouble getting the syntax right. The query I’d like to create would return all tasks with: A state of TODO AND (a scheduled date of <= today OR a show-on date <= today) Would it be possible for you to provide help with this? Thanks!
With more complex Scheme expressions it is best to add them to your init.org file - this is read on startup so is ready to go when you start beorg.
To solve this problem there are two parts needed - firstly a function to determine if a given date is today or earlier. Here is what I've added to my init.org for this:
* Date helper function
#+BEGIN_SRC scheme
(define (today-or-earlier? date)
(if date
(let ((date-str-now (date->string (current-date) "~Y~m~d"))
(date-str-date (date->string date "~Y~m~d")))
(string<=? date-str-date date-str-now))
#f))
#+END_SRC
Now that we've got a function which will tell you whether a date is today or earlier we can go ahead and define a function to check the state of the item and if its scheduled or active/show on date is today or before today:
* Filters
Show all tasks which have a scheduled or show on date of today or earlier AND have a state of TODO
#+BEGIN_SRC scheme
(define (filter-todo-now item)
(and (string=? (item-state item) "TODO")
(or (today-or-earlier? (item-scheduled item))
(today-or-earlier? (item-active-date item)))))
#+END_SRC
When writing Scheme you are probably best doing so on a desktop computer. If you are using iCloud sync you should see the init.org updated pretty much immediately in beorg. To reload init.org without killing and restarting beorg go into the REPL and type:
(load 'init)
You can now use the filter by either typing in (filter-todo-item) into the search bar, setting up a saved search or adding a new filter using Scheme (see the documentation in the REPL on how to do this).
If you've created any cool filters using Scheme feel free to share in the comments or as a new forum post!
Matthew Kennard
I had this sent to me this morning and thought it would be useful to discuss in the forum:
Hi beorg team, I’m trying to create a new, saved search query with Scheme, and am having trouble getting the syntax right. The query I’d like to create would return all tasks with: A state of TODO AND (a scheduled date of <= today OR a show-on date <= today) Would it be possible for you to provide help with this? Thanks!
With more complex Scheme expressions it is best to add them to your init.org file - this is read on startup so is ready to go when you start beorg.
To solve this problem there are two parts needed - firstly a function to determine if a given date is today or earlier. Here is what I've added to my init.org for this:
Now that we've got a function which will tell you whether a date is today or earlier we can go ahead and define a function to check the state of the item and if its scheduled or active/show on date is today or before today:
When writing Scheme you are probably best doing so on a desktop computer. If you are using iCloud sync you should see the init.org updated pretty much immediately in beorg. To reload init.org without killing and restarting beorg go into the REPL and type:
You can now use the filter by either typing in (filter-todo-item) into the search bar, setting up a saved search or adding a new filter using Scheme (see the documentation in the REPL on how to do this).
If you've created any cool filters using Scheme feel free to share in the comments or as a new forum post!