alphapapa / org-super-agenda

Supercharge your Org daily/weekly agenda by grouping items
GNU General Public License v3.0
1.38k stars 108 forks source link

How to use :property properly? #244

Closed dorneanu closed 3 months ago

dorneanu commented 1 year ago

Hi,

I'm struggling with the :property selector I'd like to use. For multiple ORG entries like:

**** TODO Testing
:PROPERTIES:
:CREATED: [2023-04-20 Thu 08:33]
:week:     16
:END:

I'd like to have a group/section in my agenda which shows all items where week=<week number>. This is what I have sofar:

...
                         (org-super-agenda-groups
                          '(
                            (:log t)
                            (:discard (:tag "inactive"))
                            (:discard (:tag "jira"))  
                            (:name "This Week"
                             :property ("week" . (format-time-string "%U"))
                            )
                            (:discard (:anything))))))
...

So for this week (format-time-string "%U") returns 16. Then in the "This week" group I'd like to match all entries that have week: 16 as a property. However I always get "Invalid org-super-agenda selector:" as an error.

Maybe it's my fault I don't know how to construct a cons cell properly. Thanks in advance!

alphapapa commented 1 year ago

Hi,

Please see the documentation of the property selector:

Group items with a property, optionally matching a value. Argument may be a property name string, or a list of property name string and either value string or predicate with which to test the value.

You're getting that error because it is indeed invalid.

If you want to insert the current week into the org-super-agenda-groups list, you'll need to use backquoting and unquoting, keeping in mind that the unquoting will only happen when you set the variable's value, not when the variable's value is accessed.

Backquoting, unquoting, and splicing is covered in a section of the Elisp manual. Simply, note the difference between what these forms evaluate to:

`(foo ,(format-time-string "%U"))
'(foo (format-time-string "%U"))
dorneanu commented 1 year ago

Thanks for your reply. In ielm I can see the difference between the both. When I then try to set:

  (:name "This Week"
    :property `("week" ,(format-time-string "%U"))
  )

then I get:

Wront type argument: sequencep, \`

Again: I want to match items with a property called week where the value is the current week number (aka format-time-string "%U")

DavidCodingLounge commented 3 months ago

Thanks for your reply. In ielm I can see the difference between the both. When I then try to set:

  (:name "This Week"
    :property `("week" ,(format-time-string "%U"))
  )

then I get:

Wront type argument: sequencep, \`

Again: I want to match items with a property called week where the value is the current week number (aka format-time-string "%U")

Just posting this to solve the problem and get the issue closed.

The problem is that you are nesting a backquote inside of an already quoted block. Simply change the block from a quote to a backquote and then use the expression that alphapapa provided.

(org-super-agenda-groups
    `(
    (:log t)
    (:discard (:tag "inactive"))
    (:discard (:tag "jira"))  
    (:name "This Week"
    :property ("week" ,(format-time-string "%U"))
    )
    (:discard (:anything))))

Note the change I made on the second line of my code snippet, the form is now using ` instead of ' which means that reader/splice operators such as , and ,@ will correctly work inside of it.