From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id iFdlEHG6tmIeLAEAbAwnHQ (envelope-from ) for ; Sat, 25 Jun 2022 09:34:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id YFQ2EHG6tmL9IQAA9RJhRA (envelope-from ) for ; Sat, 25 Jun 2022 09:34:09 +0200 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 C7D8BC2E8 for ; Sat, 25 Jun 2022 09:34:08 +0200 (CEST) Received: from localhost ([::1]:59388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o50Iw-0005Oq-Rz for larch@yhetil.org; Sat, 25 Jun 2022 03:34:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o50G8-0005Kq-Dv for emacs-orgmode@gnu.org; Sat, 25 Jun 2022 03:31:15 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:37684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o50G6-0006bC-GR for emacs-orgmode@gnu.org; Sat, 25 Jun 2022 03:31:12 -0400 Received: by mail-pg1-x52f.google.com with SMTP id h192so4402815pgc.4 for ; Sat, 25 Jun 2022 00:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=wBGaNJsEyGnJuhQMAq6WO8/5Dg6k/D48h8zji3iifdM=; b=MXMdCIlAWki+PUwuu4Dh8cD0EBE8WcgvE64J17DbhRHWUK+9sVJI9JYXdwiyQCfbr2 k2D2X1quhxeWqa2WhS3xnq4x5ZiXZhsEnJJelUBecaQoqYeU0fQJV3dzfvRzXdL1Gv3z QtbGhMhrwWO8S9sN6H7KfZROuG+jpKy1PaOs1CavRdSJG+i3icvV+PiyVc2ProyAUgJc HH64t0C1sXcBAQvaAC8TiN2ODGDq4ZMPghSJ2e/3ZEpoDt2SkSxPH9KFn4zb6R4OJqgF xDwBacIEi9MaxUfDGknk89sPQwq0r+gvYZs1lVjq+DSGc1peBmyIz6FIAXjUMoj7laco q3xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=wBGaNJsEyGnJuhQMAq6WO8/5Dg6k/D48h8zji3iifdM=; b=mqr48SyUmV0wfYcq5gMkRojSQbD3w0svRnwlOiNosvZHYVZaRdSOgmSh3cy0VDbCro nvMVuPH6/DZwH7GvIvRtgvl5a11bjjd4ozkSAAJSS6Vb1RR201GQ7xyhZfDQMI6chrFO 4P6IpfPLyqi1ZD07USjbCtD7Frs5SI35GqJ6rAyiw1GFkjbryqA8V3HpYNAxK+L2CKo8 7CadS0eJQCLjyRa9t6AXCG3N58fgtimtPBsQg6zp93KJ/OXz/JRwihwQ/NUkH1+xSwF2 Xd6GJuDWAy4ogmSs7mZlmihfTp7XHxbaURJdPDDToIKmTMFEweX4CnncGmv2uTN/7BkZ wuIg== X-Gm-Message-State: AJIora8SiD61jvSADtWrNr5p4bR/4Rs91V4zo0k4/nixzHUeZljIpBNO XAksPlXJTyYs3TbvKw/fNQM= X-Google-Smtp-Source: AGRyM1v3YnBifKMrxO+mxnL99w6b0rHNRK1lF836aza4MYpEn1geSC6eElTtsR3sjXsMpfg8V3B0sw== X-Received: by 2002:a63:2a95:0:b0:40d:62ed:9625 with SMTP id q143-20020a632a95000000b0040d62ed9625mr2557098pgq.282.1656142268685; Sat, 25 Jun 2022 00:31:08 -0700 (PDT) Received: from localhost ([192.161.177.252]) by smtp.gmail.com with ESMTPSA id u3-20020a170903108300b0016a613012a0sm2964643pld.210.2022.06.25.00.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jun 2022 00:31:07 -0700 (PDT) From: Ihor Radchenko To: Arthur Miller Cc: Max Nikulin , emacs-orgmode@gnu.org Subject: Re: Proposal: 'executable' org-capture-templaes In-Reply-To: References: <87pmjyco0x.fsf@localhost> <87fskrobiw.fsf@localhost> <87a6ay1enh.fsf@localhost> <87edzvdb44.fsf@localhost> <878rpu5qf4.fsf@localhost> <87zgi7357y.fsf@localhost> <875ykuslpx.fsf@localhost> Date: Sat, 25 Jun 2022 15:32:20 +0800 Message-ID: <87h749urjv.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=yantar92@gmail.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 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-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1656142448; 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=wBGaNJsEyGnJuhQMAq6WO8/5Dg6k/D48h8zji3iifdM=; b=iDr5Mqao6gTTMhX7kioR2IkayRUAdbaqOHSGAUtuhPrMSo6Ic9kY2KdOGVNNbeFnuD07f2 4F08KHaZdQhABaxY7wHQ8ND6M5ExhUypIYyzh5y9pbA2KtZRI1DnJcKr9lL4WVVi77lGt3 ixv+SSNGHbQLRK7/q0L8aJyTd1nLiYNYYVPc8T1OvXW0jy5hGjPUCLotDn8DU2EzKd/EtH FapW5535mPHrSCByVMJVeICFH1u/S7jdAurquc5KrfOu/waSe7f7bz0JhWW8RsK8iQzocg 3fS+jwXDJvokI7SZ47VniYSX+piDevz/RHrsdSFYuk3/OlqXk63DT9R+BeEzrA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1656142448; a=rsa-sha256; cv=none; b=Ya37U7CI5p6d6FF2CWWBZTXhi3f8ymRzb1BiwHnkETNWMKH/oSEEMnoIh+y8nd+z2QFkeQ eS+lGGiX1d9Gl/ca1YMXpVQ4xqpcF1+UElT+cl0ChTsX9K4aBM5GgCpx8tS5l0SHOP0UwM phwdfy3SIKrZgu5L0Z31aiPEA6Tj/0UWdl09YnJlcCHj9uq+D44BB+gLMHIan4l1PODY+D YKJ0W2deWIN52Wx03itjLQw4NE2F6aHhJ6wCjshMKzGLwa25mCHbJ3kf8YGKMdKC+yhMWT 8Jk1IbOSWaj95L6JUQyImjZTQyFDijII9GVaqOtiBmW16X2PNpc0QgwIzhUFBA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MXMdCIlA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.47 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MXMdCIlA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: C7D8BC2E8 X-Spam-Score: -3.47 X-Migadu-Scanner: scn1.migadu.com X-TUID: GaDWZlwIic41 Arthur Miller writes: > I have reworked a bit org-capture, but I haven't yet worked on org-agenda > restrictions and other details. I do not think that you need to prioritize re-creating org-capture/org-agenda/etc The main point is making sure that org-select provides the required functionality. I'd prefer to first finalize the API and get a cleaner code of org-select itself. > (define-minor-mode org-select-mode "" > :interactive nil :global nil) Why don't you just make it a major mode derived from special-mode? It will make more sense considering that you are setting special-mode, keymap, etc. > (defun osl--prop (property list) > "Return value of PROPERTY from irregular plist LIST." > (cadr (member property list))) FYI, there is plist-get > (defun osl--init () > (buffer-local-value 'osl--init (current-buffer))) This is no different than just saying osl--init. > (defun org-select-abort () > (interactive) > (org-select-quit "Aborted")) Please make sure that all the functions and variables have docstrings. This is not just a boring convention, it really helps when you come back to the code in future and when other people are reading your code. > (defun osl--longest-line () > "Return the length of the longest line in current buffer." > (let ((n 1) (L 0) (e 0) (E (point-max)) l) > (while (< e E) > (setq e (line-end-position n) > l (- e (line-beginning-position n)) > n (1+ n)) > (if (> l L) (setq L l))) > L)) Please do not use single-char variable names for non-trivial variables. It is always better to provide self-explanatory names. It is not a programming context. We are targeting better readability, not fast typing. > (dolist (menu menus) > (cond ((symbolp menu) (setq menu (eval menu))) > ((symbolp (car menu)) (setq menu (eval (car menu))))) > (let ((handler (osl--prop :org-select-handler menu))) > (when handler > (setq menu (delete :org-select-handler (delete handler menu)))) Destructive modifications of arguments is a bad idea. I expect future bugs in such code. Please avoid this approach. > ;; we send in the entire menu so we can return next piece in chain, > ;; but *the* entry we work with is just the very first one (car menu) > (defun osl--do-entry (menu handler) > "Display a single entry in the buffer." AFAIU, the comment on top belongs to the docstring. At least the part talking about the return value. If the function is expected to return something, it should be documented. Otherwise, I expect bugs in future. > (defun org-select-run (entry &optional _org-select-buffer) > "Try to execute form found in ENTRY if any leave ORG-SELECT-BUFFER live. > > This handler provides an easy way to use the framework for the simple > use-cases for multiple choices. It relies on the user to press built-in choice > `q' or `C-g' to exit the menu." Please, do not use key bindings verbatim in docstring. Prefer commands. Docstrings do have special format for auto-detecting command bindings. See D.6 Tips for Documentation Strings section of Elisp manual. > ;; given a list of menus, display one menu at a time > (dolist (menu menus) > (cond ((symbolp menu) (setq menu (eval menu))) > ((symbolp (car menu)) (setq menu (eval (car menu))))) Please avoid eval when possible. It can behave not nicely in lexical/dynamic scope. > Each menu can be followed by some properties in form of a keu-value > pair. The ^key > entire menu or entry does not need to be a regular plist. Following keys are > recognized: > > :org-select-pin Pin this menu in org-select buffer. If group nodes are used, > when this option is `t', keep this menu visible even when > descending into a submenu. ;; FIXME Not implemented yet. > :org-select-handler Use this function to handle this particular menu or > entry. When none is specified, org-select uses > `org-select-run-once' to hande the menu. Entry handler > takes precedence over menu handler. This is confusing. What do you mean by "does not need to be a regular plist"? What do you mean by "menu can be followed"? Do you imply that MENUS may not be a list of MENU lists, but can also contain :key value pairs? In general, I'd prefer format similar to https://github.com/progfolio/doct/ or at least similar to org-capture-templates The global ARGS in org-select could be defined using cl-defun style. See 2.1 Argument Lists section of CL manual. Best, Ihor