From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 4JpAHOQKx15NZwAA0tVLHw (envelope-from ) for ; Thu, 21 May 2020 23:12:36 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id iPgvGOQKx17+CAAA1q6Kng (envelope-from ) for ; Thu, 21 May 2020 23:12:36 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7884A9400C3 for ; Thu, 21 May 2020 23:12:35 +0000 (UTC) Received: from localhost ([::1]:47650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbuMa-0006mH-Rj for larch@yhetil.org; Thu, 21 May 2020 19:12:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbuMB-0006m7-M7 for emacs-orgmode@gnu.org; Thu, 21 May 2020 19:12:07 -0400 Received: from ciao.gmane.io ([159.69.161.202]:55470) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbuMB-00038A-02 for emacs-orgmode@gnu.org; Thu, 21 May 2020 19:12:07 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1jbuM9-000GZ0-FX for emacs-orgmode@gnu.org; Fri, 22 May 2020 01:12:05 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= Subject: Re: Setting org-todo-keywords through directory-local variables Date: Fri, 22 May 2020 01:12:00 +0200 Message-ID: <87eercsx1b.fsf@gmail.com> References: <87mu62gvjk.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cancel-Lock: sha1:NK5mJay+vWeFqrgwIP6lOGo/Cdk= Received-SPF: pass client-ip=159.69.161.202; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/21 17:24:15 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: 3 X-Spam_score: 0.3 X-Spam_bar: / X-Spam_report: (0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NML_ADSP_CUSTOM_MED=0.9, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -0.41 X-TUID: dGoj/31f0h8c --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Kévin Le Gouguec writes: > Can anyone confirm that this would (in principle) be the way forward, or > tell me if I am missing something[3]? I went ahead and cooked up a proof-of-concept patch, which (1) adds safe-local-variable properties to org-todo-keywords and org-todo-keyword-faces, (2) stops applying default-value to org-todo-keywords, (3) delays regexps/font-lock setups until after file- and dir-local variables have been set. While this patch contains a few things that make me weary[1], it solves my use-case, and passes the current test suite with Emacs 26.3 and 28. Does this look sound overall? Does anyone have any idea what kind of breakage might be slipping through the test suite? Thank you for your time. [1] - It's hard to feel confident that moving org-regexps-and-options and org-set-font-lock-defaults like this will not introduce regressions. - Also, these safe-local-variable validation functions could probably use some unit tests. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=dir-local-todo-keywords.patch diff --git a/lisp/org-faces.el b/lisp/org-faces.el index d78b606ec..544563276 100644 --- a/lisp/org-faces.el +++ b/lisp/org-faces.el @@ -291,7 +291,15 @@ determines if it is a foreground or a background color." (string :tag "Keyword") (choice :tag "Face " (string :tag "Color") - (sexp :tag "Face"))))) + (sexp :tag "Face")))) + :safe (lambda (x) + (cl-every + (lambda (pair) + (pcase pair + (`(,keyword . ,face) + (and (stringp keyword) + (or (facep face) (listp face)))))) + x))) (defface org-priority '((t :inherit font-lock-keyword-face)) "Face used for priority cookies." diff --git a/lisp/org.el b/lisp/org.el index e577dc661..7f4672058 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -1945,7 +1945,13 @@ taken from the (otherwise obsolete) variable `org-todo-interpretation'." org-todo-interpretation-widgets)) widget)) (repeat - (string :tag "Keyword")))))) + (string :tag "Keyword"))))) + :safe (lambda (x) + (cl-every + (lambda (seq) + (and (memq (car seq) '(sequence type)) + (cl-every (lambda (i) (stringp i)) (cdr seq)))) + x))) (defvar-local org-todo-keywords-1 nil "All TODO and DONE keywords active in a buffer.") @@ -4358,10 +4364,9 @@ related expressions." (cons 'sequence (split-string value))) (append (cdr (assoc "TODO" alist)) (cdr (assoc "SEQ_TODO" alist))))) - (let ((d (default-value 'org-todo-keywords))) - (if (not (stringp (car d))) d - ;; XXX: Backward compatibility code. - (list (cons org-todo-interpretation d))))))) + (if (not (stringp (car org-todo-keywords))) org-todo-keywords + ;; XXX: Backward compatibility code. + (list (cons org-todo-interpretation org-todo-keywords)))))) (dolist (sequence todo-sequences) (let* ((sequence (or (run-hook-with-args-until-success 'org-todo-setup-filter-hook sequence) @@ -4801,8 +4806,6 @@ The following commands are available: (vconcat (mapcar (lambda (c) (make-glyph-code c 'org-ellipsis)) org-ellipsis))) (setq buffer-display-table org-display-table)) - (org-set-regexps-and-options) - (org-set-font-lock-defaults) (when (and org-tag-faces (not org-tags-special-faces-re)) ;; tag faces set outside customize.... force initialization. (org-set-tag-faces 'org-tag-faces org-tag-faces)) @@ -4909,7 +4912,16 @@ The following commands are available: ;; Try to set `org-hide' face correctly. (let ((foreground (org-find-invisible-foreground))) (when foreground - (set-face-foreground 'org-hide foreground)))) + (set-face-foreground 'org-hide foreground))) + + ;; For file-visiting buffers, delay some setup until after + ;; file-local and directory-local variables have been set. + (if (buffer-file-name) + (progn + (add-hook 'hack-local-variables-hook 'org-set-regexps-and-options 1 t) + (add-hook 'hack-local-variables-hook 'org-set-font-lock-defaults 1 t)) + (org-set-regexps-and-options) + (org-set-font-lock-defaults))) ;; Update `customize-package-emacs-version-alist' (add-to-list 'customize-package-emacs-version-alist --=-=-=--