pragmat1c1 · 2022-05-27 13:16
Running `(looking-at org-todo-line-regexp)` to check if I am visiting a todo heading or just an outline heading without TODO keywords, I get always true, even if I am visiting a heading without TODO keyword.
Here's the line I'm checking:
**** Infos
Here's my regexp: `org-todo-line-regexp`:
"^\\(\\*+\\)\\(?: +\\(AGENDA\\|CANCELLED\\|D\\(?:EFERRED\\|ONE\\)\\|INFO\\|KEEP\\|MULTI\\|PROJECT\\|REVIEW\\|S\\(?:KIPPED\\|OMEDAY\\)\\|T\\(?:ERMIN\\|ODO\\)\\|WAITING\\)\\)?\\(?: +\\(.*?\\)\\)?[ ]*$"
With the cursor at the beginning of the said line (**** Infos), here's what I get:
`M-: (looking-at org-todo-line-regexp)` => t
Is there another way for checking if I am visiting a todo heading (active or done).
## Edit
The question mark at the end of the regexp `...WAITING\\)\\)?` says: One or no repetition of the previous group (the group being the TODO keywords).
So the regexp says: A todo line starts with stars and has one or no todo keyword.
But what I need is a line that definitely has a todo keyword. So I need to modify the regexp, which is defined in `org.el`.
organic-bookworm · 2022-05-27 14:15
The docstring of `org-todo-line-regexp` variable says:
>Matches a headline and puts TODO state into group 2 if present.
That's the `\\(AGENDA...WAITING\\)` part in your regexp. See [capturing group](https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Backslash.html#index-_0028-in-regexp).
Thus `(match-string 2)` after `looking-at` should return a specific TODO keyword or `nil`.
>Is there another way for checking if I am visiting a todo heading (active or done).
See [Using the Property API](https://orgmode.org/manual/Using-the-Property-API.html#index-org_002dentry_002dget). You could use `org-entry-get`.
(org-entry-get (point) "TODO")
You could also use `org-get-todo-state`, but that's not a public API.
pragmat1c1 · 2022-05-27 14:40
>(org-entry-get (point) "TODO")
This does what I need. Thank you.
github-alphapapa · 2022-05-28 02:00
This problem has already been solved. See `org-ql`.
pragmat1c1 · 2022-05-28 07:05
Good to see you here :) - Well, actually I did not want to „find“ TODO items, just check if the current line contains a TODO item.
github-alphapapa · 2022-05-28 12:43
Ah, I see. :)