From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id wDw8K4UXjGAUVgAAgWs5BA (envelope-from ) for ; Fri, 30 Apr 2021 16:43:17 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id mHnHJoUXjGCAegAAbx9fmQ (envelope-from ) for ; Fri, 30 Apr 2021 14:43:17 +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 0420A26F5B for ; Fri, 30 Apr 2021 16:43:17 +0200 (CEST) Received: from localhost ([::1]:60922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcUMO-0001Dd-46 for larch@yhetil.org; Fri, 30 Apr 2021 10:43:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcUFR-0004PF-Os for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 10:36:05 -0400 Received: from mail-oln040092075068.outbound.protection.outlook.com ([40.92.75.68]:18750 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcUFN-0000jo-V7 for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 10:36:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lx5TP5bnLmPfDGVHtvqCNXYHelwixlC547nskZ/5Wzdf4gcT4DKjpKpYOFuCmwvuiKMB0hqIs0BUDJvktSaAJPv3j0gNfZvUuYWiVRABmNO6JYUPTDgNOl3w/RhDKjOI3nlGYadATPMr5LREfrvIelAFQ/mBeI4SLfTEZAHTdwvmmqi+jrgxHZ5GUI36cZDQsOUYpNj3J3+MQ5LNcnp9RM6TX4vnmSikAMW//TN4nCz3R49qQZ64td8nQAtCGoyLnt6e4qiTHfvJoAPu1QHWPqMGZeK8taDn3g18BFDIpU4ncCrkD6X6xr6uuDWNC5E/bWO8xX2dFLDrgoS8plghTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iorLoNSwTkulvYUYqmFQQWE/fgVQDm8iymncLfa9SuY=; b=RH34uZGsw5N51DsgF1Mc2lCyu8/G8zWrMRjA76bTpPqJWU3ws1qq/O4ZnDMEhWt+dsCi6UAuTiO0vjVueO2kI88n85AgZr9PIOEmuQyqja3OrOFs++cDIsJtFlQcYzY5CKBdyorrblaxFwrpvtYXJLmqCAP6pbyzTFqA/+1LglnbBPCerCDQ3eJGVjpTpNV3lQVDI/tMYg+nGR0GNjFOFfs4wa8c7wP65HKD95FfaXzSaQ4mpvUzcvEGElME3psLDsMJOqhlE59AwZKDtIcVPLZbjaV5yTF1tKtWmKucD8ne/2ucqJZHC7mcFDZ8qEwgTH+euBlZtt0cbDT09OuPCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iorLoNSwTkulvYUYqmFQQWE/fgVQDm8iymncLfa9SuY=; b=g+FgKHEqXJvi7aKY2XN7tJKg6EER3g86uvj6ihMD9rcOSEWN7nI0dg1VJ2dBnTgIITh7piEz2P9ZJSIaWfkViNgV0A6pCBOCBwOaIGDOCYYWtop9KLprCaj0SqUNoq9bdKcPUE54m8ClF7CmRM57yBQOulYcOgAqrjL6C6vtllu/qV1sVwWl82JzgMjaRo6Ws+r0uxw+9Tl9m5nmiykJzuel6bTpkRbgbqTJ8ADew0CP3wcVCJ8OPOiivvPp4zeKv/5Ed+oG0syhxBiQ03VsxvLuQOn50FQT7nATE5hN708fO1yvBszl+HtNW0tTCadmK7zTQiFNrwxRDfBjnjKS4A== Received: from VI1EUR04FT056.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::41) by VI1EUR04HT057.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::444) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27; Fri, 30 Apr 2021 14:35:57 +0000 Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:7e0e::50) by VI1EUR04FT056.mail.protection.outlook.com (2a01:111:e400:7e0e::242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Fri, 30 Apr 2021 14:35:57 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:6DE4B2671586AF6981D7DC0EB55274B826CB071D50D2F79ACCEECF9A6E0925B0; UpperCasedChecksum:CA95ECC92206B98FC67119FBFF33877015D78D55D46515AE3E4B003C7AB5AA26; SizeAsReceived:7645; Count:46 Received: from AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::d1c1:2a0d:3b2b:4591]) by AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::d1c1:2a0d:3b2b:4591%7]) with mapi id 15.20.4065.027; Fri, 30 Apr 2021 14:35:57 +0000 From: Arthur Miller To: Nick Dokos Subject: Re: Programmatically set TODO labels per file? References: <875z04lgti.fsf@alphaville.usersys.redhat.com> Date: Fri, 30 Apr 2021 16:35:56 +0200 In-Reply-To: (Arthur Miller's message of "Fri, 30 Apr 2021 12:13:12 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (windows-nt) Content-Type: multipart/mixed; boundary="=-=-=" X-TMN: [MBSNIGt1UBoxit1yoQSuilSBYatadyuN] X-ClientProxiedBy: AM6PR02CA0026.eurprd02.prod.outlook.com (2603:10a6:20b:6e::39) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <82zgxf3kmr.fsf@live.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from HP-Laptop.homepc (81.232.177.30) by AM6PR02CA0026.eurprd02.prod.outlook.com (2603:10a6:20b:6e::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Fri, 30 Apr 2021 14:35:56 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: aa039a66-f351-4aab-d4d1-08d90be54434 X-MS-TrafficTypeDiagnostic: VI1EUR04HT057: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C5LCmbQzsi2CEJ3+NCYncZy6eFYw52qYdoq9YGqqzv2qpaefhsxcrBTkmt0HqkHXA/4WT/i60YdLLkYTJu/1HmWCPxnPn6m9UbL/Dxa35Dbq2VApCHwzVrDdVuxJPL2Uw4/0xcBJww83FjT7YAnNfUY/Y5j2VoMIInIbFmaGDrWnTByG2odL9PsE1Eg1YsEkQsIwlj9Rr6YB3FVgY87SoMLmCP3ItTsZ/bVC8wU361SdLm/mYvD4LJ/4SR2JNbnLzhlmYSHWmnaU2eD7xZdHowx27dTDrHfDtmyM/haA5qmpa/p6hOdsL6XqQnB0E4PPTUspDVBJKr3Q9Wh+eiMggQBcVMXGLnmf+IsNwOeaV26qlbT/nYjWIiHg6xC+C5CeyLNGIh7RkwtofF5LZcJHRQ== X-MS-Exchange-AntiSpam-MessageData: hJz2PXqZGpw3sAW/NP6SHh1TbZGgNLIq59WUEPSsabF4u1GHbquUx7FiLbbPot3sQRXCUmDHFe8X0AjP1oaE64KHSya6pqC1yIA2oFuAZa7epq90ezwidUw1oDpOkFH5zmbJKvXOe7bxR8wjDw1rhQ== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa039a66-f351-4aab-d4d1-08d90be54434 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2021 14:35:57.2192 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VI1EUR04FT056.eop-eur04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1EUR04HT057 Received-SPF: pass client-ip=40.92.75.68; envelope-from=arthur.miller@live.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619793797; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=iorLoNSwTkulvYUYqmFQQWE/fgVQDm8iymncLfa9SuY=; b=f4KkdalvDwTl7y1Ecw0DboN87UfCgxm89eBR0C95nnyFmVK+y2OcSd+zo/gJVWAQKVyhbt yqThhB/y0XQKD36zjO2Sy3Ak+rlSlLiDZ7Rvbod4qds+BrE8D7RHB+t01Kr4jfCNQzJyx0 rODDtsHelWsduGOcZaCi2wW+X7glTQ/NeHA0fx8nUfVc76ub9GuYd1aCPGYtfgsROr+N+/ xcfsvIo+4PqwfIXn8rJ6XcYG9///pTKzJAW9FxrIibevT/1mR8S3ANGZMgoswlRIll/+no 48XUG0d7+13G+PaSb+YzDn7oLYwDIS/D64Yh09RbOI7WAkhspYSWS0LfaVLwGw== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1619793797; a=rsa-sha256; cv=pass; b=IfCdB761r6gqnsko7cs+pzQySuYL0dzQGcZ1fDSi9pmXcTp4rc1SCk18qbIKuF7sjf5yIk w9XFSvn93LO5bzoFiQ0p3+paiPsT8F87AM/P3F/+nW0v5EzcHMWYrzmh0MlRfbzowa7ywb FWkZpVZFEkjIRM+H2cGG8B5dGKx8KK4iMhV2v9MKFrVYvD6Dzj/AXPgJC/+kTe3U/v5M9J RdXvWRBRNV+UAIrg1RtUHaSkRyLZQ7X2fvnuqKzLuxJy7rMDGsjq+BP/omfv51AMra/jO/ /q1p9vDyFt0/2Iu8MmXYWVLQCZSuOFK7GlU6zrXe49dnEZ7V+DM1oFWxyL+rsQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=live.com header.s=selector1 header.b=g+FgKHEq; arc=pass ("microsoft.com:s=arcselector9901:i=1"); 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-Migadu-Spam-Score: -3.16 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=live.com header.s=selector1 header.b=g+FgKHEq; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=live.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-Migadu-Queue-Id: 0420A26F5B X-Spam-Score: -3.16 X-Migadu-Scanner: scn0.migadu.com X-TUID: U+HluUhpMQ38 --=-=-= Content-Type: text/plain Arthur Miller 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 :-). --=-=-= Content-Type: text/x-org Content-Disposition: attachment; filename=test.org #+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 --=-=-=--