emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Setting org-todo-keywords through directory-local variables
@ 2020-05-20 21:12 Kévin Le Gouguec
  2020-05-21 23:12 ` Kévin Le Gouguec
  2020-05-22  8:42 ` Nicolas Goaziou
  0 siblings, 2 replies; 10+ messages in thread
From: Kévin Le Gouguec @ 2020-05-20 21:12 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I'd like to set org-todo-keywords and org-todo-keyword-faces through
directory-local variables, to get rid of duplicate #+SEQ_TODO lines in
my Org files[1].

Right now I see two obstacles for this to work:

(1) org-set-regexps-and-options, which sets up a bunch of TODO-related
    machinery, insists on using (default-value 'org-todo-keywords),

(2) this function is called in the major mode function, which IIUC means
    that directory-local values have not been applied yet.

The first obstacle looks like it can be easily removed[2]; the second
obstacle looks more substantial.  It is trivially side-stepped by
sticking (hack-local-variables) at the top of org-mode; to my untrained
eye, it looks like TRT would rather be for Org to add
org-set-regexps-and-options to hack-local-variables-hook.

This sounds like a risky change though: I imagine that a lot of what
happens in the major mode function depends on what
org-set-regexps-and-options sets up, and would therefore need to be
moved to this hook as well.  Figuring which parts should be moved seems
like a non-trivial task that might introduce some regressions…


Can anyone confirm that this would (in principle) be the way forward, or
tell me if I am missing something[3]?


Thank you for your time.


[1] For example:

#+begin_src elisp
((org-mode
  . ((org-todo-keywords
      . ((sequence "REPORT" "REPORTED" "WAITING" "FIXED")
         (sequence "CANCELED")))
     (org-todo-keyword-faces
      . (("REPORT" . org-todo)
         ("REPORTED" . warning)
         ("WAITING" . warning)
         ("FIXED" . org-done)
         ("CANCELED" . shadow))))))
#+end_src

I'd like that so much that I went through the trouble of writing
safe-local-variable predicates for these variables:

#+begin_src elisp
(put 'org-todo-keywords
     'safe-local-variable
     (lambda (x)
       (cl-every
        (lambda (seq)
          (and (memq (car seq) '(sequence type))
               (cl-every (lambda (i) (stringp i)) (cdr seq))))
        x)))

(put 'org-todo-keyword-faces
     'safe-local-variable
     (lambda (x)
       (cl-every
        (lambda (pair)
          (pcase pair
            (`(,keyword . ,face)
             (and (stringp keyword)
                  (or (facep face) (listp face))))))
        x)))
#end_src

[2] I tried to go through org.el's history, but I could not find a
rationale for using default-value.

[3] Alternatively, maybe the answer is as simple as "Org documents
should be self-sufficient; keywords should be explicitly set in
#+SEQ_TODO lines"; that wouldn't sound right though, since
org-todo-keywords is customizable.



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-10-31  3:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-20 21:12 Setting org-todo-keywords through directory-local variables Kévin Le Gouguec
2020-05-21 23:12 ` Kévin Le Gouguec
2020-05-22 15:11   ` Nicolas Goaziou
2020-05-23 12:58     ` Kévin Le Gouguec
2020-06-24 17:54       ` Kévin Le Gouguec
2020-09-05 15:39         ` Bastien
2022-10-30  3:10           ` Ihor Radchenko
2022-10-30 14:35             ` Kévin Le Gouguec
2022-10-31  3:00               ` Ihor Radchenko
2020-05-22  8:42 ` Nicolas Goaziou

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).