From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id cHDJHhK+dWW0NgEAauVa8A:P1 (envelope-from ) for ; Sun, 10 Dec 2023 14:33:06 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id cHDJHhK+dWW0NgEAauVa8A (envelope-from ) for ; Sun, 10 Dec 2023 14:33:06 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=LQntSzeM; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1702215186; 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=uRMn7JlnVRq0tzGTBpOEkc3rQk3dRwLA7gZaSwuFbQ8=; b=sPNpq1d6A6AfChgJRdiMjxinDhNUGqXJCwwjKbEXV8C9mtvnuXkD2jW0B1OUfueDLIcQ4U PGNuAr7ecagbk18RnERfCB9b25p5hIkp48uBTgPkY9j9Xfky96iTrFMmlegk7GAJeFc6jj xGK5qFFb/6a8yVUpt/7RiUwFkN/hoH12YaTF47wb8+kz3oWgeJVL2Mp8ST0X46bbYyshj5 jnuwLE29SczyYilpwy9Pon7AqAFz1qo1yQ6Vsxf1yzIlG/dNRAXi2GzQgs0vB4czHSPCEq 5tTqxrAMx1bOD4LUG/wIRMfjTLyk7yTCEBo2ZKpMmtN94WoA1nlZwi5Aon4F0A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1702215186; a=rsa-sha256; cv=none; b=jQ75pIz4WktasQfeVLTkLI9JNNveCwfTUEI5PTJ+/pKRPAl5eKhMoWxqOCUIbPzz074fVw qmCUaRTqQl6SJL7DKAy1oN+KQyK9y5MeU3s7saT/WCxP5ySrC1wyGkDPUKdNlhbogPw4WM o7xiLoWRh/g2uMvT7Iazt01w0ilmBVHvNj7knCIWkyTByIW0e0NVTafuj9ybQDqmr0LrtL 9E+9B5gEN7+l0Z6jpx3FCxxJvvDtQL5liHtoPf2wJnDn7oRfUtiqx5hQfLClBFUppV1ST1 kD2zYYv27xCzHEswde0e7kyzWfiBsY6Mf6vpDmDQzw9p6MYkijclnDO4i33IWQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=LQntSzeM; 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"; dmarc=pass (policy=none) header.from=posteo.net 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 E71705B97F for ; Sun, 10 Dec 2023 14:33:05 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rCJuw-0006mU-Am; Sun, 10 Dec 2023 08:32:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rCJut-0006lx-MA for emacs-orgmode@gnu.org; Sun, 10 Dec 2023 08:32:19 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rCJuq-0005CK-3k for emacs-orgmode@gnu.org; Sun, 10 Dec 2023 08:32:19 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id EDF29240028 for ; Sun, 10 Dec 2023 14:32:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1702215134; bh=yg/QjKEz1zmzAKd/saG+ldB+uz78qdr8cIGvxuIDuFs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=LQntSzeMFZLBN1DoZr7VKLQGNe0btCqszlmlfQAv+pAEwJeHu2szi9zSliA/JIsJr yzKq6dHeCKqdoKzXaWB0aqwPF7Jt895O4B1dSPNSeUKvvEDoEr9NjO3mg3/SqbiXfO xczoNM9McciPIkRgnUjbpVknUcqoE0rlOdpGG5H6Z0nOPLHqo4KPbtLdK/P+NlG+xB dsN6MKoMf/q2Q/eJwLf7lnbKAo/G7d+PO4oGT4Cw0/v0jvC40v+kTwo7Z9tsKihRZq h3Wg1fF79mK38NNQXwt6Frsx1cUp/sqinkRBCodrGomTGNaeVBOar23OzbRNs57Jd1 zbdEEHQWR20TA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Sp5QP0Dlhz9rxK; Sun, 10 Dec 2023 14:32:12 +0100 (CET) From: Ihor Radchenko To: Rick Lupton Cc: emacs-orgmode list Subject: Re: [PATCH] org-id: allow using parent's existing id in links to headlines In-Reply-To: References: <118435e8-0b20-46fd-af6a-88de8e19fac6@app.fastmail.com> <87edkwsafe.fsf@localhost> <87cywh2ad6.fsf@localhost> Date: Sun, 10 Dec 2023 13:35:19 +0000 Message-ID: <87jzpmqiy0.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.38 X-Spam-Score: -9.38 X-Migadu-Queue-Id: E71705B97F X-Migadu-Scanner: mx12.migadu.com X-TUID: wqYoInK4KAKC "Rick Lupton" writes: > Here's an updated patch, which adds (optional) search strings to ID links, and the option to inherit ID targets from parent headline / the top level file properties. I've also updated ORG-NEWS and the manual, and added tests. > > I think I've fixed all the issues with my first patch about which headline gets used for the description when inheriting IDs, what happens if there is no ID, etc. Thanks! > +*** ~org-id-store-link~ now adds search strings for precise link targets > + > +Previously, search strings are supported for =file:= links but not for > +=id:= links. This change adds support for search strings to =id:= > +links. "This change..." part sounds like a commit message, not a NEWS item. You may probably remove this paragraph. > > +(defun org-link--try-link-store-functions (interactive?) > + "Try storing external links, prompting if more than one is possible. > + > +Each function returned by `org-store-link-functions` is called in > +turn. If multiple functions return non-nil, prompt for which link > +should be stored. We use `...' Elisp quoting, not markdown. Also, please keep two spaces between sentences - you do it inconsistently across the patch. > +Return t if a function has successfully stored a link, which will > +be stored in `org-link-store-props`. I'd better say "Return t when the link is stored in `org-store-link-plist'." > +(defcustom org-id-link-consider-parent-id nil > + "Non-nil means storing a link to an Org file will consider parent entry IDs. > + > +Use this with `org-id-link-use-context` set to `t` to allow > +linking to uniquely-named sub-entries within a parent entry with > +an ID, without requiring every sub-entry to have its own ID." 1. `...' quoting 2. The docstring is slightly confusing. Having an example would be helpful. > +(defcustom org-id-link-use-context t > + "Non-nil means org-id links from `org-id-store-link' contain context. > +\\ > +A search string is added to the id with \"::\" as separator and > +used to find the context when the link is activated by the > +command `org-open-at-point'. When this option is t, the entire > +active region is be placed in the search string of the file link. > +If set to a positive integer N, only the first N lines of context > +are stored. It does not look like integer value is respected in the patch. > +Using a prefix argument to the commands `org-store-link' \ > +\(`\\[universal-argument] \\[org-store-link]') or > +`org-id-store-link` negates this setting for the duration of the > +command." You should also update the docstring of `org-store-link' accordingly. > ;;;###autoload > -(defun org-id-get-create (&optional force) > +(defun org-id-get-create (&optional force inherit) >... > ;;;###autoload > -(defun org-id-get (&optional epom create prefix) > +(defun org-id-get (&optional epom create prefix inherit) Please document this new optional arguments in the NEWS. > - (let ((id (org-entry-get epom "ID"))) > + (let ((id (org-entry-get epom "ID" inherit))) This makes your description of INHERIT argument slightly inaccurate - for `org-entry-get', INHERIT can also be a special symbol 'selective. > -(defun org-id-store-link () > +(defun org-id-store-link (interactive?) Please make this new argument optional and document the argument in the docstring and NEWS. Non-optional new argument is a breaking change that may break third-party code. > "Store a link to the current entry, using its ID. > > +See also `org-id-link-to-org-use-id`, > +`org-id-link-use-context`, > +`org-id-link-consider-parent-id`. > + > If before first heading store first title-keyword as description > or filename if no title." > - (interactive) > - (when (and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 'org-mode)) > - (let* ((link (concat "id:" (org-id-get-create))) > + (interactive "p") > + (when (and (buffer-file-name (buffer-base-buffer)) > + (derived-mode-p 'org-mode) > + (or (eq org-id-link-to-org-use-id t) I do not like this change - `org-id-store-link' is not only used by `org-store-link'. Suddenly honoring `org-id-link-to-org-use-id' will be a breaking change. Instead, I suggest you to write a wrapper function, like `org-id-store-link-maybe' and use it as :store id link property. That function will call `org-id-store-link' as necessary according to user customization. > + ;; Prefix to `org-store-link` negates preference from `org-id-link-use-context`. > + (when (org-xor current-prefix-arg org-id-link-use-context) This is not reliable. `org-id-store-link' may be called from a completely different command, not `org-store-link'. Then, the effect of prefix argument will be unexpected. You should instead process prefix argument right in `org-store-link' by let-binding `org-id-link-use-context' around the call to `org-id-store-link'. > + (pcase (org-link-precise-link-target id-location) Why not passing the RELATIVE-TO argument? > (defun org-id-open (id _) > "Go to the entry with id ID." > - (org-mark-ring-push) > - (let ((m (org-id-find id 'marker)) > - cmd) > + (let* ((option (and (string-match "::\\(.*\\)\\'" id) > + (match-string 1 id))) > + (id (if (not option) id > + (substring id 0 (match-beginning 0)))) > + m cmd) > + (org-mark-ring-push) > + (setq m (org-id-find id 'marker)) This means that the existing IDs that happen to contain :: will be broken. For such IDs, we should (1) document the problem in the news; (2) try harder to match them calling `org-id-find' with all the possible ID values until one matches. > + (when option > + (org-link-search option)) > (org-fold-show-context))) `org-link-search' does not always search from point. So, you may end up matching, for example, a duplicate CUSTOM_ID above. Moreover, regular expression match option will be broken - `org-link-search' creates sparse tree in the whole buffer and will disregard the ID part of the link. I suspect that you will need to make dedicated modifications to `org-link-search' as well in order to implement opening ID links with search option cleanly. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at