* Programmatically set TODO labels per file?
@ 2021-04-29 20:49 Arthur Miller
2021-04-29 21:09 ` tomas
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Arthur Miller @ 2021-04-29 20:49 UTC (permalink / raw)
To: emacs-orgmode
Hi all,
I have a simple question, but I wasn't able to find answer on the web,
so finally I'll try my luck here.
I know I can setq org-todo-keywords with a list '((sequence "TODO"
DONE")), as an example. But what variable is used for per-file keywords?
Once that are set with #+TODO: ... line?
I guess when org mode parses a file when starting up the mode, it has to
parse that line into some var, where do I find it?
Thanks in advance!
Best regards
/a
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-29 20:49 Programmatically set TODO labels per file? Arthur Miller
@ 2021-04-29 21:09 ` tomas
2021-04-29 21:58 ` Arthur Miller
2021-04-29 21:20 ` Russell Adams
2021-04-30 1:08 ` Nick Dokos
2 siblings, 1 reply; 10+ messages in thread
From: tomas @ 2021-04-29 21:09 UTC (permalink / raw)
To: Arthur Miller; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 668 bytes --]
On Thu, Apr 29, 2021 at 10:49:54PM +0200, Arthur Miller wrote:
>
> Hi all,
>
> I have a simple question, but I wasn't able to find answer on the web,
> so finally I'll try my luck here.
>
> I know I can setq org-todo-keywords with a list '((sequence "TODO"
> DONE")), as an example. But what variable is used for per-file keywords?
> Once that are set with #+TODO: ... line?
>
> I guess when org mode parses a file when starting up the mode, it has to
> parse that line into some var, where do I find it?
Use a file local variable?
That said (or rather, asked), I don't know whether there is a specific
Org way to achieve that.
Cheers
- t
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-29 20:49 Programmatically set TODO labels per file? Arthur Miller
2021-04-29 21:09 ` tomas
@ 2021-04-29 21:20 ` Russell Adams
2021-04-29 22:01 ` Arthur Miller
2021-04-30 1:08 ` Nick Dokos
2 siblings, 1 reply; 10+ messages in thread
From: Russell Adams @ 2021-04-29 21:20 UTC (permalink / raw)
To: emacs-orgmode
On Thu, Apr 29, 2021 at 10:49:54PM +0200, Arthur Miller wrote:
>
> Hi all,
>
> I have a simple question, but I wasn't able to find answer on the web,
> so finally I'll try my luck here.
>
> I know I can setq org-todo-keywords with a list '((sequence "TODO"
> DONE")), as an example. But what variable is used for per-file keywords?
> Once that are set with #+TODO: ... line?
>
> I guess when org mode parses a file when starting up the mode, it has to
> parse that line into some var, where do I find it?
>
> Thanks in advance!
>
> Best regards
> /a
>
https://orgmode.org/manual/Per_002dfile-keywords.html
------------------------------------------------------------------
Russell Adams RLAdams@AdamsInfoServ.com
PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/
Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-29 21:09 ` tomas
@ 2021-04-29 21:58 ` Arthur Miller
0 siblings, 0 replies; 10+ messages in thread
From: Arthur Miller @ 2021-04-29 21:58 UTC (permalink / raw)
To: tomas; +Cc: emacs-orgmode
<tomas@tuxteam.de> writes:
> On Thu, Apr 29, 2021 at 10:49:54PM +0200, Arthur Miller wrote:
>>
>> Hi all,
>>
>> I have a simple question, but I wasn't able to find answer on the web,
>> so finally I'll try my luck here.
>>
>> I know I can setq org-todo-keywords with a list '((sequence "TODO"
>> DONE")), as an example. But what variable is used for per-file keywords?
>> Once that are set with #+TODO: ... line?
>>
>> I guess when org mode parses a file when starting up the mode, it has to
>> parse that line into some var, where do I find it?
>
> Use a file local variable?
>
> That said (or rather, asked), I don't know whether there is a specific
> Org way to achieve that.
As I understand the manual, the org specific way is to use per file
variable, but instead of using Emacs _*_ for file variables, org uses #+
and they do their own parsing seems like. I might missunderstand, but
the syntax to use is:
#+TODO: keyword1 keyword2 ... keywordN
I was looking around in org.el a bit now, and I see there are three vars
associated with per-file todo keywords: org-todo-keywords-1
org-todo-kwd-alist and org-todo-key-alist which seem to be set in
org-set-regexps-and-options function. I'll see if I can refactore
something out from there for my purpose.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-29 21:20 ` Russell Adams
@ 2021-04-29 22:01 ` Arthur Miller
2021-04-29 22:37 ` Samuel Wales
0 siblings, 1 reply; 10+ messages in thread
From: Arthur Miller @ 2021-04-29 22:01 UTC (permalink / raw)
To: emacs-orgmode
Russell Adams <RLAdams@AdamsInfoServ.Com> writes:
> On Thu, Apr 29, 2021 at 10:49:54PM +0200, Arthur Miller wrote:
>>
>> Hi all,
>>
>> I have a simple question, but I wasn't able to find answer on the web,
>> so finally I'll try my luck here.
>>
>> I know I can setq org-todo-keywords with a list '((sequence "TODO"
>> DONE")), as an example. But what variable is used for per-file keywords?
>> Once that are set with #+TODO: ... line?
>>
>> I guess when org mode parses a file when starting up the mode, it has to
>> parse that line into some var, where do I find it?
>>
>> Thanks in advance!
>>
>> Best regards
>> /a
>>
>
> https://orgmode.org/manual/Per_002dfile-keywords.html
Thanks Rusell; but I have seen the manual as I wrote. I am aware I can
use
#+TODO:
syntax to set per file keywords. I wanted to do this from lisp, since I
can't use labels with multiple words with that syntax since spaces are
used as delimiters for keywords, but I can pass strings (with spaces)
with lisp.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-29 22:01 ` Arthur Miller
@ 2021-04-29 22:37 ` Samuel Wales
2021-04-29 22:48 ` Arthur Miller
0 siblings, 1 reply; 10+ messages in thread
From: Samuel Wales @ 2021-04-29 22:37 UTC (permalink / raw)
To: Arthur Miller; +Cc: emacs-orgmode
as you discovered, spaces can work for todo kw for at least some
purposes. [i have one, because i prefer space to snake_case and
kebab-case might not search well.] but you should check to see if it
is guaranteed to work. i vaguely recall spc is not allowable.
if it were guaranteed to work, then there would likely be a mechanism
to include it in the #+ syntax. :)
On 4/29/21, Arthur Miller <arthur.miller@live.com> wrote:
> Russell Adams <RLAdams@AdamsInfoServ.Com> writes:
>
>> On Thu, Apr 29, 2021 at 10:49:54PM +0200, Arthur Miller wrote:
>>>
>>> Hi all,
>>>
>>> I have a simple question, but I wasn't able to find answer on the web,
>>> so finally I'll try my luck here.
>>>
>>> I know I can setq org-todo-keywords with a list '((sequence "TODO"
>>> DONE")), as an example. But what variable is used for per-file keywords?
>>> Once that are set with #+TODO: ... line?
>>>
>>> I guess when org mode parses a file when starting up the mode, it has to
>>> parse that line into some var, where do I find it?
>>>
>>> Thanks in advance!
>>>
>>> Best regards
>>> /a
>>>
>>
>> https://orgmode.org/manual/Per_002dfile-keywords.html
>
> Thanks Rusell; but I have seen the manual as I wrote. I am aware I can
> use
>
> #+TODO:
>
> syntax to set per file keywords. I wanted to do this from lisp, since I
> can't use labels with multiple words with that syntax since spaces are
> used as delimiters for keywords, but I can pass strings (with spaces)
> with lisp.
>
>
>
--
The Kafka Pandemic
Please learn what misopathy is.
https://thekafkapandemic.blogspot.com/2013/10/why-some-diseases-are-wronged.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-29 22:37 ` Samuel Wales
@ 2021-04-29 22:48 ` Arthur Miller
0 siblings, 0 replies; 10+ messages in thread
From: Arthur Miller @ 2021-04-29 22:48 UTC (permalink / raw)
To: Samuel Wales; +Cc: emacs-orgmode
Samuel Wales <samologist@gmail.com> writes:
> as you discovered, spaces can work for todo kw for at least some
> purposes. [i have one, because i prefer space to snake_case and
> kebab-case might not search well.] but you should check to see if it
> is guaranteed to work. i vaguely recall spc is not allowable.
>
> if it were guaranteed to work, then there would likely be a mechanism
> to include it in the #+ syntax. :)
Indeed, I am aware that spaces are not so welcome in some places
:). However this works fine:
(setq org-todo-keywords '((sequence "first label" "second label")))
If it is guaranteed or not I have no idea, maybe some other APIs in org
are expecting labels to be single words, but for simple purpose it seems
to work. #+ could actually use just "" as grouping items or {}. For
example:
#+TODO: "item one" "item two" ... "item n"
or with {}
#+TODO: {item one} {item two} ... {item n}
When I tried, I got citation characters included in my label, which
wasn't really what I wanted either :).
>
>
> On 4/29/21, Arthur Miller <arthur.miller@live.com> wrote:
>> Russell Adams <RLAdams@AdamsInfoServ.Com> writes:
>>
>>> On Thu, Apr 29, 2021 at 10:49:54PM +0200, Arthur Miller wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I have a simple question, but I wasn't able to find answer on the web,
>>>> so finally I'll try my luck here.
>>>>
>>>> I know I can setq org-todo-keywords with a list '((sequence "TODO"
>>>> DONE")), as an example. But what variable is used for per-file keywords?
>>>> Once that are set with #+TODO: ... line?
>>>>
>>>> I guess when org mode parses a file when starting up the mode, it has to
>>>> parse that line into some var, where do I find it?
>>>>
>>>> Thanks in advance!
>>>>
>>>> Best regards
>>>> /a
>>>>
>>>
>>> https://orgmode.org/manual/Per_002dfile-keywords.html
>>
>> Thanks Rusell; but I have seen the manual as I wrote. I am aware I can
>> use
>>
>> #+TODO:
>>
>> syntax to set per file keywords. I wanted to do this from lisp, since I
>> can't use labels with multiple words with that syntax since spaces are
>> used as delimiters for keywords, but I can pass strings (with spaces)
>> with lisp.
>>
>>
>>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-29 20:49 Programmatically set TODO labels per file? Arthur Miller
2021-04-29 21:09 ` tomas
2021-04-29 21:20 ` Russell Adams
@ 2021-04-30 1:08 ` Nick Dokos
2021-04-30 10:13 ` Arthur Miller
2 siblings, 1 reply; 10+ messages in thread
From: Nick Dokos @ 2021-04-30 1:08 UTC (permalink / raw)
To: emacs-orgmode
Arthur Miller <arthur.miller@live.com> writes:
> I have a simple question, but I wasn't able to find answer on the web,
> so finally I'll try my luck here.
>
> I know I can setq org-todo-keywords with a list '((sequence "TODO"
> DONE")), as an example. But what variable is used for per-file keywords?
> Once that are set with #+TODO: ... line?
>
> I guess when org mode parses a file when starting up the mode, it has to
> parse that line into some var, where do I find it?
>
It is parsed into a buffer-local variable by the name of
`org-todo-keywords-1'. Do `C-h v org-todo-keywords' and `C-h v
org-todo-keywords-1' for all the details.
BTW, when the interwebs fail you (or even before that), use the source :-)
--
Nick
"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-30 1:08 ` Nick Dokos
@ 2021-04-30 10:13 ` Arthur Miller
2021-04-30 14:35 ` Arthur Miller
0 siblings, 1 reply; 10+ messages in thread
From: Arthur Miller @ 2021-04-30 10:13 UTC (permalink / raw)
To: Nick Dokos; +Cc: emacs-orgmode
Nick Dokos <ndokos@gmail.com> writes:
> Arthur Miller <arthur.miller@live.com> writes:
>
>> I have a simple question, but I wasn't able to find answer on the web,
>> so finally I'll try my luck here.
>>
>
>> I know I can setq org-todo-keywords with a list '((sequence "TODO"
>> DONE")), as an example. But what variable is used for per-file keywords?
>> Once that are set with #+TODO: ... line?
>>
>> I guess when org mode parses a file when starting up the mode, it has to
>> parse that line into some var, where do I find it?
>>
>
> It is parsed into a buffer-local variable by the name of
> `org-todo-keywords-1'. Do `C-h v org-todo-keywords' and `C-h v
> org-todo-keywords-1' for all the details.
>
> BTW, when the interwebs fail you (or even before that), use the source :-)
Yes indeed! I used the source Luke! :)
I found that one, unfortunately it is not enough to set that one to my
keywords. There are also two lists in play org-todo-kwd-alist and
org-todo-key-alist which are set in one mastodont method, but I think I
can refactor that out. I have to figure out how to build alist comming
from out org-collect-keywords which is input to that part of
code. Didn't had time last night, will see if I have time today.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Programmatically set TODO labels per file?
2021-04-30 10:13 ` Arthur Miller
@ 2021-04-30 14:35 ` Arthur Miller
0 siblings, 0 replies; 10+ messages in thread
From: Arthur Miller @ 2021-04-30 14:35 UTC (permalink / raw)
To: Nick Dokos; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1244 bytes --]
Arthur Miller <arthur.miller@live.com> writes:
If anyone is interested, this is how I understand the org TODO per file
parsing:
The file is parsed in org-collect-keywords-1 in org.el.
Each #+TODO: line is lumped into one single string, which is a problem
when strings with spaces a concerned. Multiple #+TODO: lines will end up
in final multiple strings added into an alist which has a first element
a "TODO" string. The right thing would be to parse multiple strings per
each #+TODO: line. Now the org-collect-keyword-1 is not a trivial one,
so it would take me quite some time to understand, so I'll pass.
The thing I did that worked for me is wrong super-hackish thing, just an
experiment, so to say.
I have simply refactored the code where the string obtained from
org-collect-keywords is parsed, which is the very last part of
org-set-regexps-and-options, where main action seems to take place. That
let's me do what I wanted. It will completely replace whatever was
specified with #+ syntax, and the fontification won't be done
either. Also if file is reverted than #+ will completely replace what
was set with lisp. So not a clean thing, probably nothing to be used by
anyone, but it does what I roughly need for my init file :-).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test.org --]
[-- Type: text/x-org, Size: 3888 bytes --]
#+TODO: one two
#+TODO: three
#+TODO: four
#+begin_src emacs-lisp
(defun org-todo-per-file-keywords (kwds)
"Sets per file TODO labels. Takes as argument a list of strings to be used as
labels."
(let (alist)
(push "TODO" alist)
(dolist (kwd kwds)
(push kwd alist))
(setq alist (list (nreverse alist)))
;; TODO keywords.
(setq-local org-todo-kwd-alist nil)
(setq-local org-todo-key-alist nil)
(setq-local org-todo-key-trigger nil)
(setq-local org-todo-keywords-1 nil)
(setq-local org-done-keywords nil)
(setq-local org-todo-heads nil)
(setq-local org-todo-sets nil)
(setq-local org-todo-log-states nil)
(let ((todo-sequences alist))
(dolist (sequence todo-sequences)
(let* ((sequence (or (run-hook-with-args-until-success
'org-todo-setup-filter-hook sequence)
sequence))
(sequence-type (car sequence))
(keywords (cdr sequence))
(sep (member "|" keywords))
names alist)
(dolist (k (remove "|" keywords))
(unless (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$"
k)
(error "Invalid TODO keyword %s" k))
(let ((name (match-string 1 k))
(key (match-string 2 k))
(log (org-extract-log-state-settings k)))
(push name names)
(push (cons name (and key (string-to-char key))) alist)
(when log (push log org-todo-log-states))))
(let* ((names (nreverse names))
(done (if sep (org-remove-keyword-keys (cdr sep))
(last names)))
(head (car names))
(tail (list sequence-type head (car done) (org-last done))))
(add-to-list 'org-todo-heads head 'append)
(push names org-todo-sets)
(setq org-done-keywords (append org-done-keywords done nil))
(setq org-todo-keywords-1 (append org-todo-keywords-1 names nil))
(setq org-todo-key-alist
(append org-todo-key-alist
(and alist
(append '((:startgroup))
(nreverse alist)
'((:endgroup))))))
(dolist (k names) (push (cons k tail) org-todo-kwd-alist))))))
(setq org-todo-sets (nreverse org-todo-sets)
org-todo-kwd-alist (nreverse org-todo-kwd-alist)
org-todo-key-trigger (delq nil (mapcar #'cdr org-todo-key-alist))
org-todo-key-alist (org-assign-fast-keys org-todo-key-alist))
;; Compute the regular expressions and other local variables.
;; Using `org-outline-regexp-bol' would complicate them much,
;; because of the fixed white space at the end of that string.
(unless org-done-keywords
(setq org-done-keywords
(and org-todo-keywords-1 (last org-todo-keywords-1))))
(setq org-not-done-keywords
(org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1))
org-todo-regexp (regexp-opt org-todo-keywords-1 t)
org-not-done-regexp (regexp-opt org-not-done-keywords t)
org-not-done-heading-regexp
(format org-heading-keyword-regexp-format org-not-done-regexp)
org-todo-line-regexp
(format org-heading-keyword-maybe-regexp-format org-todo-regexp)
org-complex-heading-regexp
(concat "^\\(\\*+\\)"
"\\(?: +" org-todo-regexp "\\)?"
"\\(?: +\\(\\[#.\\]\\)\\)?"
"\\(?: +\\(.*?\\)\\)??"
"\\(?:[ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?"
"[ \t]*$")
org-complex-heading-regexp-format
(concat "^\\(\\*+\\)"
"\\(?: +" org-todo-regexp "\\)?"
"\\(?: +\\(\\[#.\\]\\)\\)?"
"\\(?: +"
;; Stats cookies can be stuck to body.
"\\(?:\\[[0-9%%/]+\\] *\\)*"
"\\(%s\\)"
"\\(?: *\\[[0-9%%/]+\\]\\)*"
"\\)"
"\\(?:[ \t]+\\(:[[:alnum:]_@#%%:]+:\\)\\)?"
"[ \t]*$")
org-todo-line-tags-regexp
(concat "^\\(\\*+\\)"
"\\(?: +" org-todo-regexp "\\)?"
"\\(?: +\\(.*?\\)\\)??"
"\\(?:[ \t]+\\(:[[:alnum:]:_@#%]+:\\)\\)?"
"[ \t]*$"))
(org-compute-latex-and-related-regexp)))
(org-todo-per-file-keywords '("label 1" "label 2" "something" "last one"))
#+end_src
* Test
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-04-30 14:43 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-29 20:49 Programmatically set TODO labels per file? Arthur Miller
2021-04-29 21:09 ` tomas
2021-04-29 21:58 ` Arthur Miller
2021-04-29 21:20 ` Russell Adams
2021-04-29 22:01 ` Arthur Miller
2021-04-29 22:37 ` Samuel Wales
2021-04-29 22:48 ` Arthur Miller
2021-04-30 1:08 ` Nick Dokos
2021-04-30 10:13 ` Arthur Miller
2021-04-30 14:35 ` Arthur Miller
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).