Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sexp diary entries support #31

Open
przemekd opened this issue Jun 28, 2022 · 7 comments · May be fixed by #35
Open

Sexp diary entries support #31

przemekd opened this issue Jun 28, 2022 · 7 comments · May be fixed by #35

Comments

@przemekd
Copy link

I am not really sure but from the first look, this grammar does not implement parsing sexp diary entries.

Would you consider adding support for that (or at least accepting PR with this addition)?

@milisims
Copy link
Owner

Can you give me an example of where they fall in an org file?

sexps are already supported in timestamps, and objects otherwise are intended to be implemented via queries.

@przemekd
Copy link
Author

przemekd commented Jun 28, 2022

sexps are already supported in timestamps

Yep, I saw that 👍🏻

Can you give me an example of where they fall in an org file?

They would be the top-level objects (?). Let me paste the example from https://orgmode.org/manual/Weekly_002fdaily-agenda.html

* Holidays
  :PROPERTIES:
  :CATEGORY: Holiday
  :END:
%%(org-calendar-holiday)   ; special function for holiday names

* Birthdays
  :PROPERTIES:
  :CATEGORY: Ann
  :END:
%%(org-anniversary 1956  5 14) Arthur Dent is %d years old
%%(org-anniversary 1869 10  2) Mahatma Gandhi would be %d years old

@milisims
Copy link
Owner

The text and formatting after the sexp isn't in the syntax description, as far as I can tell, I'm having some trouble finding information. Can they span multiple lines, after the ending parenthesis? I don't see anywhere that would answer that for me. How does that formatting cookie work? https://www.gnu.org/software/emacs/manual/html_node/emacs/Sexp-Diary-Entries.html mentions %s, but is there a list somewhere?

@przemekd
Copy link
Author

To be honest, I am not really sure where to look for that information. As an end-user, I just use %d. But just having a grammar that returns an entry in the form of (lisp-function) (entry-text) could be more than enough for a parser client.

@milisims
Copy link
Owner

In emacs orgmode, it looks like the sexp itself can be multiple lines, but the entry text afterwards can't be. That's somewhat straightforward to implement to start with, but there's some challenges still.

1: %%(f ")")    do we want to handle this?
2: %%func("a")  and this?
3: %%(a
     b) this evaluates correctly in emacs orgmode

While the diary seems to typically evaluate to some datetime thing which ties into the display/agenda, if we have this construct in the grammar I'm not interested in restricting it to lisp or datetime/numeric values, so I'd like it to be able to handle other expressions (like 2). I'm not really interested in trying to track and manage escaped and quoted parentheses though.

So there are a couple approaches here I can think of:

  1. Use a query in a paragraph. Customizable, but is a little tricky to implement, and would need to be done so per implemention.
  2. Parse %% followed by a single line of (expr), allowing an arbitrary parsing after it's been 'marked' by the %%. This fails #3 above, but would let the user figure out how to do 1 and 2 as complex or as simple as desired. I think I prefer approach 1 over this.
  3. Implement a node that tracks balanced parens, and make no attempt to handle escaped parens or parens in quotes. Easiest to deal with for users, but will fail to parse #1 above correctly.
  4. Implement a node that makes an attempt to handle escaped parens and parens in double quotes and escaping. I'm not really interested in this. Feels like I'm just asking for blowing up complexity, and why support any particular language construct over another? lua's [[string]]s come to mind.

So I think what I'm going to do is play with queries for approach 1, see if it's reasonable to implement with the current grammar without making it super complex. If not, I'll look into implementing approach 3

@kristijanhusak any thoughts?

@kristijanhusak
Copy link
Contributor

I would be satisfied with 2. Just to be able to identify them, and then i can parse them accordingly. If it will cause too much mess and performance issues, 1 is the only solution I guess.

@przemekd
Copy link
Author

@milisims Looks like the usage of placeholders like %d and %s is function-specific. This might be helpful for reference -> https://github.com/typester/emacs/blob/master/lisp/calendar/diary-lib.el#L1581

@milisims milisims linked a pull request Aug 16, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants