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 /lisp/org-id.el | |
parent | baa44bd705024a4ddc56f98de561dbc4d68a6acb (diff) |
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>
Diffstat (limited to 'lisp/org-id.el')
-rw-r--r-- | lisp/org-id.el | 13 |
1 files changed, 11 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 @@ 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) |