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 guHIBjAeyV5IXgAA0tVLHw (envelope-from ) for ; Sat, 23 May 2020 12:59:28 +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 oEgpAjAeyV69DQAA1q6Kng (envelope-from ) for ; Sat, 23 May 2020 12:59:28 +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 7F9699401AD for ; Sat, 23 May 2020 12:59:27 +0000 (UTC) Received: from localhost ([::1]:39166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcTkM-0005Mq-HH for larch@yhetil.org; Sat, 23 May 2020 08:59:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcTjx-0005Ks-Ry for emacs-orgmode@gnu.org; Sat, 23 May 2020 08:59:01 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:38919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcTjw-0001iq-US for emacs-orgmode@gnu.org; Sat, 23 May 2020 08:59:01 -0400 Received: by mail-wm1-x32b.google.com with SMTP id w64so12603053wmg.4 for ; Sat, 23 May 2020 05:59:00 -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=reZwlBHJmi/f1H3IIrloGd2wTpsh77H4r03gNqvJomo=; b=VTp5aHijUw+nssk3/hx1SMVASV2grUsZPtHnMxGPOWU8X8C0iWTkfWfNgIzvnreKuL CR3WQIdxWAG/o9k1IcVNn3vpJ9H/7bet9sgvUwyNT77o5yJO35iXQp2zx3OHR0pW0BMv GnTkPH0obGFaSTaxu7fDJfCL8Jh49yAj8GTNB12m8NlDhKHizCk/E556YzGbeJMkmOI/ 2BNn5JB7l9v+Vs4rJKR4NhTzgCdIuLEJ0X0gSSjsG33d72+xuYAhvUear+0thOP8kiFk 9ggzxjCgkbeA1079P+IYo8V/Xyl0OpFq8jKWRzHhXbUzoEgny4mdmqLE8+y968y1tk6s 3bZw== 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=reZwlBHJmi/f1H3IIrloGd2wTpsh77H4r03gNqvJomo=; b=URC9KbcmCrLCMB/JNOSdmb41LEt7KcfX2XLUAO3pTw9Sj4KDoVPapOPr/sratMZ98F gNjauE5JxIUwvZsVZGqBFNkLekhAGfdc6/HrO3zvEGohRxFMUmDXZBOv9iN3jOc2TYeL 6VFI7HRNN+dhJ/tsLMExIg9Ori3Dm4NqPT3wurVQp3BB/dB7IBb420o8V7/e8HJ0T8Bd rTL7n8wBG08eVKdrNYctcXElPz7MTQrkNqK7DhruvQLbCGmYZZovRh93SlfVzn6MQUQ8 ZvHrtM6xVWSu0r2ZSt6LX/wlpye2dQy17fxfGZxa+0HgNVnehUSpCBhkK5MhGQBsOPGM uq7A== X-Gm-Message-State: AOAM532nXB89v6JnPx0SduHcLPHnMDMjF2s5Mqj1CXhctV/zcllvq4t/ 5XK02A5QY3rxfX2h7Udhvv+RXgdhky4= X-Google-Smtp-Source: ABdhPJwgO3kL/5VezLuaLwFUpp/fFVfx9x9Cnf1/XjMNR8q1kwM9sLfd30TEha5K11fdaXa7PYRmWQ== X-Received: by 2002:a05:600c:2c51:: with SMTP id r17mr5394790wmg.147.1590238738522; Sat, 23 May 2020 05:58:58 -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 v7sm4411888wre.93.2020.05.23.05.58.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 May 2020 05:58:57 -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> Date: Sat, 23 May 2020 14:58:56 +0200 In-Reply-To: <87lflkdmxx.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Fri, 22 May 2020 17:11:22 +0200") Message-ID: <87eeraaju7.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::32b; envelope-from=kevin.legouguec@gmail.com; helo=mail-wm1-x32b.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_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=pass header.d=gmail.com header.s=20161025 header.b=VTp5aHij; dmarc=pass (policy=none) header.from=gmail.com; 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: -1.71 X-TUID: ON7GyzC/Ssqh --=-=-= Content-Type: text/plain Nicolas Goaziou writes: > This looks hackish. Any bit in particular? AFAICT hack-local-variables-hook is the expected way to perform plumbing that might be affected by file/directory-local variables. It is used by e.g. shell-script-mode, cc-mode, markdown-mode and AUCTeX, to name a few. The docstring says: > Major modes can use this to examine user-specified local variables > in order to initialize other data structure based on them. I think the buffer-file-name bit looks dodgy; I mainly did that to get the unit tests to pass on this POC. > Also, Org needs the STARTUP part early on, so you > cannot really delay it. > > I /think/ the rest can be delayed, but I admit I'm not too sure either. Right. Now that I've looked at other major modes (especially AUCTeX[1]), it seems a more conventional approach would be to - keep the calls to org-set-regexps-and-options and org-set-font-lock-defaults where they are now, - in hack-local-variables-hook, *if* file-local-variables-alist contains Org variables that affect those functions, and call them again to refresh regexps and fontification. IIUC this would pretty much guarantee that things can only break for weirdos like me who try to use directory-local variables. > I think the expected way to do this is to add a SETUPFILE. Thanks for the pointer! Unless I'm misreading (info "(org) In-buffer Settings"), I could move my SEQ_TODO settings there, but that wouldn't work for org-todo-keyword-faces, right? In light of your comments, and based on what I've seen in AUCTeX, I'm attaching what I believe to be a less intrusive patch. WDYT? Thank you for taking the time to review this. I'm not opposed to using SETUPFILE (if I can handle org-todo-keyword-faces there); I'm just wondering if this could be one more opportunity to have Org play nice with other Emacs facilities (directory-local variables). [1] https://git.savannah.gnu.org/cgit/auctex.git/tree/font-latex.el?h=release_12_2#n1435 --=-=-= 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..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 e577dc661..da38beb45 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) @@ -4909,7 +4914,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 --=-=-=--