diff options
author | Kyle Meyer <kyle@kyleam.com> | 2020-04-16 01:07:38 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2020-04-20 20:46:56 -0400 |
commit | c716b7c085757ffb50b9211b8c31b09adee683f3 (patch) | |
tree | 0342effb3da2a92bd7a9777e3fb6410fc450d914 | |
parent | baa44bd705024a4ddc56f98de561dbc4d68a6acb (diff) | |
download | org-mode-c716b7c085757ffb50b9211b8c31b09adee683f3.tar.gz |
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 <ian@retrospec.tv>
<87a73caayj.fsf@phaktory>
-rw-r--r-- | lisp/org-id.el | 13 | ||||
-rw-r--r-- | lisp/org.el | 2 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lisp/org-id.el b/lisp/org-id.el index 14a4615..90d1327 100644 --- a/lisp/org-id.el +++ b/lisp/org-id.el @@ -259,6 +259,11 @@ Create an ID if necessary." (interactive) (org-kill-new (org-id-get nil 'create))) +(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 @@ In any case, the ID of the entry is returned." (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))))) ;;;###autoload @@ -572,8 +579,10 @@ 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 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 912d6d4..bf82a49 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -192,6 +192,7 @@ Stars are put in group 1 and the trimmed body in group 2.") (defvar org-radio-target-regexp) (defvar org-target-link-regexp) (defvar org-target-regexp) +(defvar org-id-overriding-file-name) ;; load languages based on value of `org-babel-load-languages' (defvar org-babel-load-languages) @@ -7863,6 +7864,7 @@ with the original repeater." (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]*>" |