From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id rRq+JuTql15BNQAA0tVLHw (envelope-from ) for ; Thu, 16 Apr 2020 05:19:32 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id sCJ/HOjql175PwAAbx9fmQ (envelope-from ) for ; Thu, 16 Apr 2020 05:19:36 +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 CFC7B941E36 for ; Thu, 16 Apr 2020 05:19:32 +0000 (UTC) Received: from localhost ([::1]:57944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOwvz-0005yo-W6 for larch@yhetil.org; Thu, 16 Apr 2020 01:19:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54138) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOwvU-0005yb-4T for emacs-orgmode@gnu.org; Thu, 16 Apr 2020 01:19:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOwvS-0003xo-Jd for emacs-orgmode@gnu.org; Thu, 16 Apr 2020 01:18:59 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:55119) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOwvS-0003ve-Aj for emacs-orgmode@gnu.org; Thu, 16 Apr 2020 01:18:58 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id DE0BF4F282; Thu, 16 Apr 2020 01:18:55 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:in-reply-to:references:date:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=RKEKo00tF191 d8DjDeTaCyflDQU=; b=XTH42z19jC8qXmOTZ4/M8mu2sD81/5kQIomEKbFwPWPR v5z1H7UTb4py3xTcnAC8JORDyXOpXDYNxR32ODubIL5Yk2uWyr/HEFoh3lICB4RR KR9PvCqDY1MvkHQmzl3PxR8hXBMM8Nv2aezElPqBUE8umd3cLhhyTk1IpvqcZZU= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id D548E4F281; Thu, 16 Apr 2020 01:18:55 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:in-reply-to:references:date:message-id:mime-version:content-type:content-transfer-encoding; s=mesmtp; bh=zPo1fknr+nYDXn/KnyYpAVGS3BfEzQ+7jGKrdA5ONy0=; b=fQaGE+fBq3sBiLixeZ/hcUlgvgYGvxYzyVFWzGUPy5UqBIpYOfDevJNxfNEWCLY7jiaGHBWQIVoey5jE7STDq+tjZmeatqzbHsFAFlF98zxRJ6xoP/WORzHag1I3sVbv7ZmPGj6fqhkCjuSeit6Yi3Ku7IuAkOewcrWKaxZy3/c= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 59E5F4F280; Thu, 16 Apr 2020 01:18:55 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Ian Eure Subject: Subject: [PATCH] org-id: Allow file name to be overridden on ID creation In-Reply-To: <87a73caayj.fsf@phaktory> References: <87a73caayj.fsf@phaktory> Date: Thu, 16 Apr 2020 05:18:54 +0000 Message-ID: <87o8rs80u9.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: C4A4DDE2-7FA1-11EA-9BAD-C28CBED8090B-24757444!pb-smtp1.pobox.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.147.108.70 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-Scanner: scn0 X-Spam-Score: -1.21 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=XTH42z19; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=fQaGE+fB; dmarc=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-Scan-Result: default: False [-1.21 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.57491903499478]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.51.188.0/24:c]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.26), country: US(-0.01), ip: 209.51.188.17(-0.57)]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[pobox.com:+,kyleam.com:+]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:209.51.188.0/24, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[kyle@kyleam.com,emacs-orgmode-bounces@gnu.org]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[pobox.com:s=sasl,kyleam.com:s=mesmtp]; FROM_HAS_DN(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[kyleam.com]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_SEVEN(0.00)[8]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: Wcq7o4Ugo5rA Ian Eure writes: > If you have a subtree of entries with :ID: properties and call M-x=20 > `org-clone-subtree-with-time-shift' on it, an error occurs: > > Wrong type argument: stringp, nil > > This is due to the interaction of=20 > `org-clone-subtree-with-time-shift' and `org-id-add-location'.=20 > [...] Thanks for the nice analysis. > I=E2=80=99ve confirmed that this is still a problem in the 9.3.6, which i= s=20 > the latest release, as well as Git master. Yeah, I suspect this worked at one time, given there is dedicated handling of IDs in org-clone-subtree-with-time-shift. [... bisecting ...] The failure started with 9865e6bd8 (org-id: Speedup, minor functional change and fix, 2019-08-01), which was part of the 9.3 release. Interestingly that seems to be functionally equivalent to what you mentioned next: > A simplistic fix would be to swap the let and when lines in=20 > `org-id-add-location': > > diff --git a/lisp/org-id.el b/lisp/org-id.el > index 1ff433bd8..945a9a1f6 100644 > --- a/lisp/org-id.el > +++ b/lisp/org-id.el > @@ -572,8 +572,8 @@ When FILES is given, scan also these files." > (defun org-id-add-location (id file) > "Add the ID with location FILE to the database of ID=20 > locations." > ;; Only if global tracking is on, and when the buffer has a=20 > file > - (let ((afile (abbreviate-file-name file))) > - (when (and org-id-track-globally id file) > + (when (and org-id-track-globally id file) > + (let ((afile (abbreviate-file-name file))) > (unless org-id-locations (org-id-locations-load)) > (puthash id afile org-id-locations) > (unless (member afile org-id-files) > > However, this causes a more subtle bug, which is that the IDs of=20 > cloned subtrees won=E2=80=99t be tracked correctly. That sounds right, so it seems it was just broken in a quieter way before. > Perhaps a solution to that is to use an indirect buffer of the source > when cloning, instead of a temp buffer. Hmm, that should indeed work, but I'd be leery of it introducing other bugs and complications. How about something like this? -- >8 -- Subject: [PATCH] org-id: Allow file name to be overridden on ID creation * lisp/org-id.el (org-id-overriding-file-name): New variable. (org-id-get): Prefer org-id-overriding-file-name over the buffer's file name if set. (org-id-locations-load): Give a more informative error when file is nil. * lisp/org.el (org-clone-subtree-with-time-shift): Let-bind org-id-overriding-file-name, enabling an ID to be created for a cloned subtree rather than crashing with a type error. Note that, before 9865e6bd8 (org-id: Speedup, minor functional change and fix, 2019-08-01), this wouldn't fail with a type error. However, the ID would not be added correctly because org-id-add-location simply wouldn't process the id at all if the passed file was nil. Reported-by: Ian Eure <87a73caayj.fsf@phaktory> --- lisp/org-id.el | 13 +++++++++++-- lisp/org.el | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lisp/org-id.el b/lisp/org-id.el index 14a461500..90d13275f 100644 --- a/lisp/org-id.el +++ b/lisp/org-id.el @@ -259,6 +259,11 @@ (defun org-id-copy () (interactive) (org-kill-new (org-id-get nil 'create))) =20 +(defvar org-id-overriding-file-name nil + "Tell `org-id-get' to use this as the file name when creating an ID. +This is useful when working with contents in a temporary buffer +that will be copied back to the original.") + ;;;###autoload (defun org-id-get (&optional pom create prefix) "Get the ID property of the entry at point-or-marker POM. @@ -275,7 +280,9 @@ (defun org-id-get (&optional pom create prefix) (create (setq id (org-id-new prefix)) (org-entry-put pom "ID" id) - (org-id-add-location id (buffer-file-name (buffer-base-buffer))) + (org-id-add-location id + (or org-id-overriding-file-name + (buffer-file-name (buffer-base-buffer)))) id))))) =20 ;;;###autoload @@ -572,8 +579,10 @@ (defun org-id-locations-load () (defun org-id-add-location (id file) "Add the ID with location FILE to the database of ID locations." ;; Only if global tracking is on, and when the buffer has a file + (unless file + (error "bug: org-id-get expects a file-visiting buffer")) (let ((afile (abbreviate-file-name file))) - (when (and org-id-track-globally id file) + (when (and org-id-track-globally id) (unless org-id-locations (org-id-locations-load)) (puthash id afile org-id-locations) (unless (member afile org-id-files) diff --git a/lisp/org.el b/lisp/org.el index 275120662..879d3a03a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -192,6 +192,7 @@ (defvar org-indent-indentation-per-level) (defvar org-radio-target-regexp) (defvar org-target-link-regexp) (defvar org-target-regexp) +(defvar org-id-overriding-file-name) =20 ;; load languages based on value of `org-babel-load-languages' (defvar org-babel-load-languages) @@ -7863,6 +7864,7 @@ (defun org-clone-subtree-with-time-shift (n &optional= shift) (nmin 1) (nmax n) (n-no-remove -1) + (org-id-overriding-file-name (buffer-file-name (buffer-base-buffer))) (idprop (org-entry-get beg "ID"))) (when (and doshift (string-match-p "<[^<>\n]+ [.+]?\\+[0-9]+[hdwmy][^<>\n]*>" base-commit: 4f9e07cbb4bd9e9353e941b0a00bbd401f8696c4 --=20 2.26.0