From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KOP1OmiT814KfgAA0tVLHw (envelope-from ) for ; Wed, 24 Jun 2020 17:54:48 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id uJHtNmiT814gJAAAB5/wlQ (envelope-from ) for ; Wed, 24 Jun 2020 17:54:48 +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 74C8A9402A2 for ; Wed, 24 Jun 2020 17:54:48 +0000 (UTC) Received: from localhost ([::1]:58226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo9bj-00009O-Cc for larch@yhetil.org; Wed, 24 Jun 2020 13:54:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo9bL-000099-Ud for emacs-orgmode@gnu.org; Wed, 24 Jun 2020 13:54:24 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:43893) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo9bJ-0005LS-Q3 for emacs-orgmode@gnu.org; Wed, 24 Jun 2020 13:54:23 -0400 Received: by mail-wr1-x42e.google.com with SMTP id j4so674837wrp.10 for ; Wed, 24 Jun 2020 10:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=LqCWJplm8Vd5gcMJ2SCdmkmsxISvgtKqW6KdHJA3mX4=; b=PyK7ofxZztcJABP7wnpxIwS+PqgmWWKOsszRBspWxFISgZucVuqKKnhXZpxScRbWmw PH4KT12gihC7YUoYaIPD9mz/nJyt7DzTXazpmJM+WOXKzBs0/gWTG8Bp3tfpiBj/9EUL u8Lq9IH+hMz07QcsmRm49edwxtcMWDmFJTc+rdxtC/KLCb4dgWfjTlPDOZyR9F8Q1ndn 15TdeTxmsgapnvr93Oc6StLZ//ikEOETCeIo+HqC66PlPP0cLKPKVTcaN5FXVODF2qV0 wiDTxnA44HZQgOdZfw2pVCoAve/8MVaVLXlhUpN6UxxPO8dowdp7Ez4pdBc5i27wH9j2 PUgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=LqCWJplm8Vd5gcMJ2SCdmkmsxISvgtKqW6KdHJA3mX4=; b=kaV6i21yyOSuydvzpdSahZpzu/5u6TPfGbxqIJHdpRZM3XJjRWfHImtPmKU5ROJDpT /Z0Q0Nu3vnpsnmD6V+C6jDjX00R+Ci0oZeTHpbJq04ONGr4qDwIikqNmlDWRshDhojj9 Sq0YL69xgEA/slKBkvqNz4D0u76E9EC2Cj2TcUXFRYyX1vvdIhDT3kN8lgDk8nKvdwUT GrQKGmcqzeWgSIb6CsS7GpiHxxgyekiOs/iJ6GrUPLZluRfO9D+ZAONWOAQzdfeNHUmT uq3BwquC68dHM7vHoZtXxy5E6QiITiAoKN4o+lQp3ZLYcticKv37OxWjSHPKrU2Lolcy ETFQ== X-Gm-Message-State: AOAM532Ps9TrwwzHIQSXS/3D4t66OgNkzPWrlotPjsg+lar5QBrGh7mj KGSF4S9TqD47cwbZcC1LttWQ/Ot4B7s= X-Google-Smtp-Source: ABdhPJxiID5EiBS/FGZITKp8McM1P2TjdfkOrBJoyBfQBb+orSULNvWqODO3Ci54Bt5U1qSnvF6PbA== X-Received: by 2002:a05:6000:11cc:: with SMTP id i12mr18667368wrx.224.1593021259435; Wed, 24 Jun 2020 10:54:19 -0700 (PDT) Received: from my-little-tumbleweed (200.143.13.109.rev.sfr.net. [109.13.143.200]) by smtp.gmail.com with ESMTPSA id y7sm23027944wrt.11.2020.06.24.10.54.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 10:54:18 -0700 (PDT) From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= To: emacs-orgmode@gnu.org Subject: Re: Setting org-todo-keywords through directory-local variables References: <87mu62gvjk.fsf@gmail.com> <87eercsx1b.fsf@gmail.com> <87lflkdmxx.fsf@nicolasgoaziou.fr> <87eeraaju7.fsf@gmail.com> Date: Wed, 24 Jun 2020 19:54:16 +0200 In-Reply-To: <87eeraaju7.fsf@gmail.com> (=?utf-8?Q?=22K=C3=A9vin?= Le Gouguec"'s message of "Sat, 23 May 2020 14:58:56 +0200") Message-ID: <87a70stkmv.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=kevin.legouguec@gmail.com; helo=mail-wr1-x42e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=PyK7ofxZ; dmarc=fail reason="SPF not aligned (relaxed)" 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.19 X-TUID: I8PmsC2UVbV4 --=-=-= Content-Type: text/plain Hello, I would like to re-submit this idea, now that I am reasonably sure that my implementation will not impact users who do not use the feature. (I understand that Org 9.4 is on the way. I am not asking for this feature to be included right now; I would like to get some feedback first, then move on to documenting it.) * Motivation To recap: AFAIK it is not possible to define both org-todo-keywords and org-todo-keyword-faces per-directory. The former can be set with #+SETUPFILE, but the latter simply can't be set locally, unless I'm mistaken. I'd like to specify, for all Org files in a directory, which keywords to use and how they must look. Setting both org-todo-* variables in .dir-locals.el would be ideal IMO: the definitions for keywords and their faces would be right next to each other. This cannot work right now because (1) of a stray call to default-value (2) Org computes the TODO machinery (regexps and font-lock) when setting up the major mode, before directory-local variables are in effect. * Prior art AUCTeX[1] and markdown-mode[2] both solve this using hack-local-variables-hook. This seems to be the expected way for modes to (re)compute things that may be affected by file or directory-local variables. [1] http://git.savannah.gnu.org/cgit/auctex.git/tree/font-latex.el?h=release_12_2#n1331 [2] https://github.com/jrblevin/markdown-mode/blob/v2.4/markdown-mode.el#L9403 The idea is to register a function that will check whether the user overloaded variables we care about; if that's the case, then we recompute what we need to. * Patch The attached patch: - does not change org-mode's default setup logic, - adds a function to hack-local-variables-hook that will look for org-todo-* variables, and recompute org-set-regexps-and-options and org-set-font-lock-defaults if needed, - adds :safe predicates for these variables, - adds unit tests. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Allow-users-to-configure-TODO-keywords-from-dir-loca.patch >From 148c5fa45e1fb8d58ecc86bb266d0fa33b8994a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= Date: Wed, 27 May 2020 22:53:56 +0200 Subject: [PATCH] Allow users to configure TODO keywords from dir-locals.el This uses the same method as AUCTeX and markdown-mode to refresh fontification based on file-local and directory-local variables: http://git.savannah.gnu.org/cgit/auctex.git/tree/font-latex.el?h=release_12_2#n1331 https://github.com/jrblevin/markdown-mode/blob/v2.4/markdown-mode.el#L9403 * lisp/org-faces.el (org-todo-keyword-faces): Add safe-local-variable predicate. * lisp/org.el (org-todo-keywords): Add safe-local-variable predicate. (org-set-regexps-and-options): Use buffer-local value of org-todo-keywords. (org-mode): Register a function to reset regexps and font-lock once file-local variables have been applied. (org--process-local-variables): Recompute regexps and font-lock if the user set relevant variables. * testing/examples/dir-locals/.dir-locals.el: * testing/examples/dir-locals/todo.org: Support files for new tests. * testing/lisp/test-org.el (test-org/dir-local-todo-keyword-faces): (test-org/dir-local-todo-cycling): New tests. --- lisp/org-faces.el | 10 ++++++- lisp/org.el | 28 +++++++++++++++---- testing/examples/dir-locals/.dir-locals.el | 11 ++++++++ testing/examples/dir-locals/todo.org | 8 ++++++ testing/lisp/test-org.el | 32 ++++++++++++++++++++++ 5 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 testing/examples/dir-locals/.dir-locals.el create mode 100644 testing/examples/dir-locals/todo.org diff --git a/lisp/org-faces.el b/lisp/org-faces.el index d78b606ec..fc834f37d 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) + (let ((keyword (car pair)) + (face (cdr pair))) + (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 4d46b4173..c0183dbff 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) @@ -4908,7 +4913,18 @@ 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))) + + (add-hook 'hack-local-variables-hook #'org--process-local-variables nil t)) + +(defun org--process-local-variables () + "Refresh settings affected by file-local or directory-local variables." + (when + (let ((local-vars (mapcar #'car file-local-variables-alist))) + (or (memq 'org-todo-keywords local-vars) + (memq 'org-todo-keyword-faces local-vars))) + (org-set-regexps-and-options) + (org-set-font-lock-defaults))) ;; Update `customize-package-emacs-version-alist' (add-to-list 'customize-package-emacs-version-alist diff --git a/testing/examples/dir-locals/.dir-locals.el b/testing/examples/dir-locals/.dir-locals.el new file mode 100644 index 000000000..677eaca10 --- /dev/null +++ b/testing/examples/dir-locals/.dir-locals.el @@ -0,0 +1,11 @@ +((org-mode + . ((org-todo-keywords + . ((sequence "TODO" "|" "DONE") + (sequence "REPORT" "BUG" "KNOWNCAUSE" "|" "FIXED") + (sequence "|" "CANCELED"))) + (org-todo-keyword-faces + . (("REPORT" . org-todo) + ("BUG" . warning) + ("KNOWNCAUSE" . warning) + ("FIXED" . org-done) + ("CANCELED" . shadow)))))) diff --git a/testing/examples/dir-locals/todo.org b/testing/examples/dir-locals/todo.org new file mode 100644 index 000000000..cd06b5ebd --- /dev/null +++ b/testing/examples/dir-locals/todo.org @@ -0,0 +1,8 @@ +#+Title: headings with TODO keywords set in .dir-locals.el +* TODO heading +* DONE heading +* REPORT heading +* BUG heading +* KNOWNCAUSE heading +* FIXED heading +* CANCELED heading diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 375e1a718..2adcb2681 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -7158,6 +7158,38 @@ CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40" (org-todo "DONE") (buffer-string)))))) +(ert-deftest test-org/dir-local-todo-keyword-faces () + "Make sure TODO faces honor dir-local variables." + (org-test-in-example-file + (expand-file-name "dir-locals/todo.org" org-test-example-dir) + (font-lock-ensure (point-min) (point-max)) + (dolist (expected-face '(org-todo + org-done + org-todo + warning + warning + org-done + shadow)) + (should (equal (get-text-property (+ 2 (point)) 'face) + expected-face)) + (next-line)))) + +(ert-deftest test-org/dir-local-todo-cycling () + "Make sure TODO cycling honors dir-local variables." + (org-test-in-example-file + (expand-file-name "dir-locals/todo.org" org-test-example-dir) + (dolist (expected-heading '("* DONE heading" + "* heading" + "* BUG heading" + "* KNOWNCAUSE heading" + "* FIXED heading" + "* heading" + "* heading")) + (org-todo) + (should (string= (buffer-substring (point) (line-end-position)) + expected-heading)) + (next-line)) + (revert-buffer t t))) ;;; Timestamps API -- 2.27.0 --=-=-= Content-Type: text/plain Am I on the right track with this patch, or are there problems I haven't thought of? Thank you for your time. --=-=-=--