summaryrefslogtreecommitdiff
path: root/lisp/org.el
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2008-11-17 10:27:44 +0100
committerCarsten Dominik <carsten.dominik@gmail.com>2008-12-10 14:31:18 +0100
commitb2ad719f51138274ce978806c7bbf36d1c078f0e (patch)
tree2c0ba4cddd163d3d002d70b2625df8f8e5ddb4c7 /lisp/org.el
parent27e0d70267bccc87e5a9767992ea3c4d1b80bb48 (diff)
Implement a new link type "id:" to link to entry ids.
Diffstat (limited to 'lisp/org.el')
-rw-r--r--lisp/org.el93
1 files changed, 69 insertions, 24 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 9406b2bb4..984864ce2 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -956,6 +956,36 @@ It should match if the message is from the user him/herself."
:group 'org-link-store
:type 'regexp)
+(defcustom org-link-to-org-use-id 'create-if-interactive
+ "Non-nil means, storing a link to an Org file will use entry ID's.
+The variable can have the following values:
+
+t Create an ID if needed to make a link to the current entry.
+
+create-if-interactive
+ If `org-store-link' is called directly (interactively, as a user
+ command), do create an ID to support the link. But when doing the
+ job for remember, only use the ID if it already exists. The
+ purpose of this setting is to avoid proliferation of unwanted
+ ID's, just because you happen to be in an Org file when you
+ call `org-remember' that automatically and preemptively
+ creates a link. If you do want to get an ID link in a remember
+ template to an entry not having an ID, create it first by
+ explicitly creating a link to it, using `C-c C-l' first.
+
+use-existing
+ Use existing ID, do not create one.
+
+nil Never use an ID to make a link, instead link using a text search for
+ the headline text."
+ :group 'org-link-store
+ :type '(choice
+ (const :tag "Create ID to make link" t)
+ (const :tag "Create if string link interactively"
+ 'create-if-interactive)
+ (const :tag "Only use existing" 'use-existing)
+ (const :tag "Do not use ID to create link" nil)))
+
(defcustom org-context-in-file-links t
"Non-nil means, file links from `org-store-link' contain context.
A search string will be added to the file name with :: as separator and
@@ -2806,11 +2836,12 @@ collapsed state."
;; Autoload ID code
+(declare-function org-id-store-link "org-id")
(org-autoload "org-id"
'(org-id-get-create org-id-new org-id-copy org-id-get
org-id-get-with-outline-path-completion
org-id-get-with-outline-drilling
- org-id-goto org-id-find))
+ org-id-goto org-id-find org-id-store-link))
;;; Variables for pre-computed regular expressions, all buffer local
@@ -6202,29 +6233,43 @@ For file links, arg negates `org-context-in-file-links'."
link (org-make-link cpltxt)))
((and buffer-file-name (org-mode-p))
- ;; Just link to current headline
- (setq cpltxt (concat "file:"
- (abbreviate-file-name buffer-file-name)))
- ;; Add a context search string
- (when (org-xor org-context-in-file-links arg)
- ;; Check if we are on a target
- (if (org-in-regexp "<<\\(.*?\\)>>")
- (setq cpltxt (concat cpltxt "::" (match-string 1)))
- (setq txt (cond
- ((org-on-heading-p) nil)
- ((org-region-active-p)
- (buffer-substring (region-beginning) (region-end)))
- (t nil)))
- (when (or (null txt) (string-match "\\S-" txt))
- (setq cpltxt
- (concat cpltxt "::"
- (condition-case nil
- (org-make-org-heading-search-string txt)
- (error "")))
- desc "NONE"))))
- (if (string-match "::\\'" cpltxt)
- (setq cpltxt (substring cpltxt 0 -2)))
- (setq link (org-make-link cpltxt)))
+ (cond
+ ((or (eq org-link-to-org-use-id t)
+ (and (eq org-link-to-org-use-id 'create-if-interactive)
+ (interactive-p))
+ (and org-link-to-org-use-id
+ (condition-case nil (org-entry-get nil "ID") (error nil))))
+ ;; We can make a link using the ID.
+ (setq link (condition-case nil
+ (org-id-store-link)
+ (error
+ ;; probably before first headling, link to file only
+ (concat "file:"
+ (abbreviate-file-name buffer-file-name))))))
+ (t
+ ;; Just link to current headline
+ (setq cpltxt (concat "file:"
+ (abbreviate-file-name buffer-file-name)))
+ ;; Add a context search string
+ (when (org-xor org-context-in-file-links arg)
+ ;; Check if we are on a target
+ (if (org-in-regexp "<<\\(.*?\\)>>")
+ (setq cpltxt (concat cpltxt "::" (match-string 1)))
+ (setq txt (cond
+ ((org-on-heading-p) nil)
+ ((org-region-active-p)
+ (buffer-substring (region-beginning) (region-end)))
+ (t nil)))
+ (when (or (null txt) (string-match "\\S-" txt))
+ (setq cpltxt
+ (concat cpltxt "::"
+ (condition-case nil
+ (org-make-org-heading-search-string txt)
+ (error "")))
+ desc "NONE")))))
+ (if (string-match "::\\'" cpltxt)
+ (setq cpltxt (substring cpltxt 0 -2)))
+ (setq link (org-make-link cpltxt))))
((buffer-file-name (buffer-base-buffer))
;; Just link to this file here.