X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/322b7dab59b98b5d8625d2cd29e48f1ce605f769..8a28a5b8d8acb314d8850b85fe5cd956a86e8ff9:/lisp/org/org-id.el diff --git a/lisp/org/org-id.el b/lisp/org/org-id.el index b979097dee..ecf67f72f3 100644 --- a/lisp/org/org-id.el +++ b/lisp/org/org-id.el @@ -1,11 +1,10 @@ ;;; org-id.el --- Global identifiers for Org-mode entries ;; -;; Copyright (C) 2008-2011 Free Software Foundation, Inc. +;; Copyright (C) 2008-2013 Free Software Foundation, Inc. ;; ;; Author: Carsten Dominik ;; Keywords: outlines, hypermedia, calendar, wp ;; Homepage: http://orgmode.org -;; Version: 7.4 ;; ;; This file is part of GNU Emacs. ;; @@ -74,6 +73,8 @@ (require 'org) (declare-function message-make-fqdn "message" ()) +(declare-function org-pop-to-buffer-same-window + "org-compat" (&optional buffer-or-name norecord label)) ;;; Customization @@ -82,6 +83,47 @@ :tag "Org ID" :group 'org) +(define-obsolete-variable-alias + 'org-link-to-org-use-id 'org-id-link-to-org-use-id "24.3") +(defcustom org-id-link-to-org-use-id nil + "Non-nil means storing a link to an Org file will use entry IDs. + +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 capture, only use the ID if it already exists. The + purpose of this setting is to avoid proliferation of unwanted + IDs, just because you happen to be in an Org file when you + call `org-capture' that automatically and preemptively creates a + link. If you do want to get an ID link in a capture template to + an entry not having an ID, create it first by explicitly creating + a link to it, using `C-c C-l' first. + +create-if-interactive-and-no-custom-id + Like create-if-interactive, but do not create an ID if there is + a CUSTOM_ID property defined in the entry. + +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 + :group 'org-id + :version "24.3" + :type '(choice + (const :tag "Create ID to make link" t) + (const :tag "Create if storing link interactively" + create-if-interactive) + (const :tag "Create if storing link interactively and no CUSTOM_ID is present" + create-if-interactive-and-no-custom-id) + (const :tag "Only use existing" use-existing) + (const :tag "Do not use ID to create link" nil))) + (defcustom org-id-uuid-program "uuidgen" "The uuidgen program." :group 'org-id @@ -151,9 +193,7 @@ This variable is only relevant when `org-id-track-globally' is set." :type 'file) (defvar org-id-locations nil - "List of files with IDs in those files. -Depending on `org-id-use-hash' this can also be a hash table mapping IDs -to files.") + "List of files with IDs in those files.") (defvar org-id-files nil "List of files that contain IDs.") @@ -193,7 +233,6 @@ With optional argument FORCE, force the creation of a new ID." (org-entry-put (point) "ID" nil)) (org-id-get (point) 'create)) -;;;###autoload (defun org-id-copy () "Copy the ID of the entry at point to the kill ring. Create an ID if necessary." @@ -217,27 +256,24 @@ In any case, the ID of the entry is returned." (setq id (org-id-new prefix)) (org-entry-put pom "ID" id) (org-id-add-location id (buffer-file-name (buffer-base-buffer))) - id) - (t nil))))) + id))))) -;;;###autoload (defun org-id-get-with-outline-path-completion (&optional targets) - "Use outline-path-completion to retrieve the ID of an entry. -TARGETS may be a setting for `org-refile-targets' to define the eligible -headlines. When omitted, all headlines in all agenda files are -eligible. -It returns the ID of the entry. If necessary, the ID is created." + "Use `outline-path-completion' to retrieve the ID of an entry. +TARGETS may be a setting for `org-refile-targets' to define +eligible headlines. When omitted, all headlines in the current +file are eligible. This function returns the ID of the entry. +If necessary, the ID is created." (let* ((org-refile-targets (or targets '((nil . (:maxlevel . 10))))) (org-refile-use-outline-path (if (caar org-refile-targets) 'file t)) (org-refile-target-verify-function nil) - (spos (org-refile-get-location "Entry: ")) + (spos (org-refile-get-location "Entry")) (pom (and spos (move-marker (make-marker) (nth 3 spos) (get-file-buffer (nth 1 spos)))))) (prog1 (org-id-get pom 'create) (move-marker pom nil)))) -;;;###autoload (defun org-id-get-with-outline-drilling (&optional targets) "Use an outline-cycling interface to retrieve the ID of an entry. This only finds entries in the current buffer, using `org-get-location'. @@ -255,7 +291,7 @@ Move the cursor to that entry in that buffer." (let ((m (org-id-find id 'marker))) (unless m (error "Cannot find entry with ID \"%s\"" id)) - (switch-to-buffer (marker-buffer m)) + (org-pop-to-buffer-same-window (marker-buffer m)) (goto-char m) (move-marker m nil) (org-show-context))) @@ -274,7 +310,7 @@ With optional argument MARKERP, return the position as a new marker." (when file (setq where (org-id-find-id-in-file id file markerp))) (unless where - (org-id-update-id-locations) + (org-id-update-id-locations nil t) (setq file (org-id-find-id-file id)) (when file (setq where (org-id-find-id-in-file id file markerp)))) @@ -319,7 +355,7 @@ So a typical ID could look like \"Org:4nd91V40HI\"." (defun org-id-uuid () "Return string with random (version 4) UUID." (let ((rnd (md5 (format "%s%s%s%s%s%s%s" - (random t) + (random) (current-time) (user-uid) (emacs-pid) @@ -404,7 +440,7 @@ and time is the usual three-integer representation of time." ;; Storing ID locations (files) -(defun org-id-update-id-locations (&optional files) +(defun org-id-update-id-locations (&optional files silent) "Scan relevant files for IDs. Store the relation between files and corresponding IDs. This will scan all agenda files, all associated archives, and all @@ -428,11 +464,11 @@ When CHECK is given, prepare detailed information about duplicate IDs." (if (symbolp org-id-extra-files) (symbol-value org-id-extra-files) org-id-extra-files) - ;; Files associated with live org-mode buffers + ;; Files associated with live org-mode buffers (delq nil (mapcar (lambda (b) (with-current-buffer b - (and (org-mode-p) (buffer-file-name)))) + (and (derived-mode-p 'org-mode) (buffer-file-name)))) (buffer-list))) ;; All files known to have IDs org-id-files))) @@ -442,8 +478,9 @@ When CHECK is given, prepare detailed information about duplicate IDs." (setq files (delq 'agenda-archives (copy-sequence files)))) (setq nfiles (length files)) (while (setq file (pop files)) - (message "Finding ID locations (%d/%d files): %s" - (- nfiles (length files)) nfiles file) + (unless silent + (message "Finding ID locations (%d/%d files): %s" + (- nfiles (length files)) nfiles file)) (setq tfile (file-truename file)) (when (and (file-exists-p file) (not (member tfile seen))) (push tfile seen) @@ -506,7 +543,7 @@ When CHECK is given, prepare detailed information about duplicate IDs." (goto-char (point-min)) (setq org-id-locations (read (current-buffer)))) (error - (message "Could not read org-id-values from %s. Setting it to nil." + (message "Could not read org-id-values from %s. Setting it to nil." org-id-locations-file)))) (setq org-id-files (mapcar 'car org-id-locations)) (setq org-id-locations (org-id-alist-to-hash org-id-locations)))) @@ -601,8 +638,8 @@ optional argument MARKERP, return the position as a new marker." (defun org-id-store-link () "Store a link to the current entry, using its ID." (interactive) - (when (and (buffer-file-name (buffer-base-buffer)) (org-mode-p)) - (let* ((link (org-make-link "id:" (org-id-get-create))) + (when (and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 'org-mode)) + (let* ((link (concat "id:" (org-id-get-create))) (case-fold-search nil) (desc (save-excursion (org-back-to-heading t) @@ -641,7 +678,8 @@ optional argument MARKERP, return the position as a new marker." (provide 'org-id) -;;; org-id.el ends here - - +;; Local variables: +;; generated-autoload-file: "org-loaddefs.el" +;; End: +;;; org-id.el ends here