Mercurial > emacs
annotate lisp/org/org-id.el @ 100267:c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-id.el (org-id-locations-file): Wrap file name with
`convert-standard-filename'.
(org-id-files): New variable.
(org-id-use-hash): New option.
(org-id-update-id-locations): Also search in all files current
listed in `org-id-files'. Convert the resulting alist to a hash
if the user customation says so.
(org-id-locations-save): Handle he case if `org-id-locations' is a
hash.
(org-id-locations-load): Convert the alist to a hash.
(org-id-add-location): Handle the hast case.
(kill-emacs-hook): Make sure id locations are saved when Emacs is
exited.
(org-id-hash-to-alist, org-id-alist-to-hash)
(org-id-paste-tracker): New functions.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-agenda.el (org-agenda-goto-calendar): Remove duplicate let
bindings of calendar variables.
* org-table.el (org-table-find-row-type): Renamed from
`org-find-row-type'.
(org-table-rewrite-old-row-references): Renamed from
`org-rewrite-old-row-references'.
(org-table-shift-refpart): Renamed from `org-shift-refpart'.
(org-table-cleanup-narrow-column-properties): Renamed from
`org-cleanup-narrow-column-properties'.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-table.el (org-find-row-type): New arguments DESC and CLINE,
for better error messages.
(org-table-get-descriptor-line): Supply the new arguments to
`org-find-row-type'.
(org-table-error-on-row-ref-crossing-hline): New option.
* org.el (org-target-link-regexp): Make buffer-local.
(org-move-subtree-down): Fix bug with trees at beginning of
buffer.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-faces.el (org-set-tag-faces): New function.
(org-tags-special-faces-re): New variable.
* org.el (org-font-lock-add-tag-faces, org-get-tag-face): New functions.
* org-faces.el (org-tag-faces): New option.
(org-tag): Mention `org-tag-faces' in the docstring.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-exp.el (org-export-html-style-default): Implement new
quoting.
* org-jsinfo.el (org-infojs-template): Implement new quoting.
* org-w3m.el (w3m-minor-mode-hook): Also add the special copy
command to the `w3m-minor-mode-map'.
* org-archive.el (org-archive-to-archive-sibling): Protect
`this-command' to avoid appending kills during archiving.
* org-exp.el (org-export-with-priority): New variable.
(org-export-add-options-to-plist): Use `org-export-plist-vars'
instead of internal list of strings and properties.
(org-print-icalendar-entries): Retrieve the location property with
inheritance.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-exp.el (org-export-with-todo-keywords): New option.
(org-export-plist-vars): Include also the keys for the #+OPTIONS
line.
(org-default-export-plist, org-export-add-options-to-plist)
(org-export-as-ascii, org-export-as-html): Use the new structure
of `org-export-plist-vars'.
* org.el (org-map-entries): Return all values.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-matcher-time): Recognize more special values.
* org-gnus.el (fboundp): Fix defvaralias for XEmacs.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-tags-exclude-from-inheritance): New option.
(org-tag-inherit-p, org-remove-uniherited-tags): Respect
`org-tags-exclude-from-inheritance'.
* org-agenda.el (org-agenda-show-inherited-tags): New option.
(org-format-agenda-item): Add inherited tags to the agenda line
string, and make sure that properties are kept when downcasing the
tags list.
(org-agenda-add-inherited-tags): New function.
(org-downcase-keep-props): New function.
* org.el (org-scan-tags): Mark inherited tags with a text
property.
(org-get-tags-at): Mark inherited tags with a text property.
(org-add-prop-inherited): New function.
* org-agenda.el (org-agenda-add-inherited-tags): New function.
(org-agenda-show-inherited-tags): New option.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-modules): Add org-w3m to the default modules.
* org-table.el (orgtbl-self-insert-command): Make S-SPC work in
orgtbl-mode.
(orgtabl-create-or-convert-from-region): New command.
* org-exp.el (org-export-as-ascii): Remove the handling of
targets.
(org-export-ascii-preprocess): Handle targets already in this
function.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-timer.el (org-timer-start-time): Define this variable.
(org-timer-item): Make argument optional.
* org-list.el (org-insert-item): Automatically insert a timer item
if the current list is a timer list.
* org-timer.el: New file.
* org-publish.el (org-publish-org-index): Only exclude the index
file in the main directory from being added to the site-map.
(org-publish-get-project-from-filename): If the current project is
a component, start publishing from the parent project.
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
* org-table.el (orgtbl-ret): Fix RET at beginning-of-buffer.
* org-publish.el (org-publish-org-index): Improve removal of
temporary buffers.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Sun, 07 Dec 2008 18:36:02 +0000 |
parents | 57447f70a253 |
children | 032aa24b2125 |
rev | line source |
---|---|
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
1 ;;; org-id.el --- Global identifiers for Org-mode entries |
96045 | 2 ;; Copyright (C) 2008 Free Software Foundation, Inc. |
3 ;; | |
4 ;; Author: Carsten Dominik <carsten at orgmode dot org> | |
5 ;; Keywords: outlines, hypermedia, calendar, wp | |
6 ;; Homepage: http://orgmode.org | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
7 ;; Version: 6.14 |
96045 | 8 ;; |
9 ;; This file is part of GNU Emacs. | |
10 ;; | |
11 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation, either version 3 of the License, or | |
14 ;; (at your option) any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
24 ;; | |
25 ;;; Commentary: | |
26 | |
27 ;; This file implements globally unique identifiers for Org-mode entries. | |
28 ;; Identifiers are stored in the entry as an :ID: property. Functions | |
29 ;; are provided that create and retrieve such identifiers, and that find | |
30 ;; entries based on the identifier. | |
31 | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
32 ;; Identifiers consist of a prefix (default "Org" given by the variable |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
33 ;; `org-id-prefix') and a unique part that can be created by a number |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
34 ;; of different methods, see the variable `org-id-method'. |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
35 ;; Org has a builtin method that uses a compact encoding of the creation |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
36 ;; time of the ID, with microsecond accuracy. This virtually |
96045 | 37 ;; guarantees globally unique identifiers, even if several people are |
38 ;; creating ID's at the same time in files that will eventually be used | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
39 ;; together. As an exernal method `uuidgen' is supported, if installed |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
40 ;; on the system. |
96045 | 41 ;; |
42 ;; This file defines the following API: | |
43 ;; | |
44 ;; org-id-get-create | |
45 ;; Create an ID for the entry at point if it does not yet have one. | |
46 ;; Returns the ID (old or new). This function can be used | |
47 ;; interactively, with prefix argument the creation of a new ID is | |
48 ;; forced, even if there was an old one. | |
49 ;; | |
50 ;; org-id-get | |
51 ;; Get the ID property of an entry. Using appropriate arguments | |
52 ;; to the function, it can also create the ID for this entry. | |
53 ;; | |
54 ;; org-id-goto | |
55 ;; Command to go to a specific ID, this command can be used | |
56 ;; interactively. | |
57 ;; | |
58 ;; org-id-get-with-outline-path-completion | |
59 ;; Retrieve the ID of an entry, using outline path completion. | |
60 ;; This function can work for multiple files. | |
61 ;; | |
62 ;; org-id-get-with-outline-drilling | |
63 ;; Retrieve the ID of an entry, using outline path completion. | |
64 ;; This function only works for the current file. | |
65 ;; | |
66 ;; org-id-find | |
67 ;; Find the location of an entry with specific id. | |
68 ;; | |
69 | |
70 (require 'org) | |
71 | |
72 (declare-function message-make-fqdn "message" ()) | |
73 | |
74 ;;; Customization | |
75 | |
76 (defgroup org-id nil | |
77 "Options concerning global entry identifiers in Org-mode." | |
78 :tag "Org ID" | |
79 :group 'org) | |
80 | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
81 (defcustom org-id-method 'org |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
82 "The method that should be used to create new ID's. |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
83 |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
84 An ID will consist of the prefix specified in `org-id-prefix', and a unique |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
85 part created by the method this variable specifies. |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
86 |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
87 Allowed values are: |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
88 |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
89 org Org's own internal method, using an encoding of the current time, |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
90 and the current domain of the computer. This method will |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
91 honor the variable `org-id-include-domain'. |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
92 |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
93 uuidgen Call the external command uuidgen." |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
94 :group 'org-id |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
95 :type '(choice |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
96 (const :tag "Org's internal method" org) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
97 (const :tag "external: uuidgen" uuidgen))) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
98 |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
99 (defcustom org-id-prefix nil |
96045 | 100 "The prefix for IDs. |
101 | |
102 This may be a string, or it can be nil to indicate that no prefix is required. | |
103 When a string, the string should have no space characters as IDs are expected | |
104 to have no space characters in them." | |
105 :group 'org-id | |
106 :type '(choice | |
107 (const :tag "No prefix") | |
108 (string :tag "Prefix"))) | |
109 | |
110 (defcustom org-id-include-domain t | |
111 "Non-nil means, add the domain name to new IDs. | |
112 This ensures global uniqueness of ID's, and is also suggested by | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
113 RFC 2445 in combination with RFC 822. This is only relevant if |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
114 `org-id-method' is `org'. When uuidgen is used, the domain will never |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
115 be added." |
96045 | 116 :group 'org-id |
117 :type 'boolean) | |
118 | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
119 (defcustom org-id-track-globally t |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
120 "Non-nil means, track ID's trhough files, so that links work globally. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
121 This work by maintaining a hash table for ID's and writing this table |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
122 to disk when exiting Emacs. Because of this, it works best if you use |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
123 a single Emacs process, not many. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
124 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
125 When nil, ID's are not tracked. Links to ID's will still work within |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
126 a buffer, but not if the entry is located in another file. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
127 ID's can still be used if the entry with the id is in the same file as |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
128 the link." |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
129 :group 'org-id |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
130 :type 'boolean) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
131 |
99139
8fa7ef477c04
2008-10-26 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents:
98871
diff
changeset
|
132 (defcustom org-id-locations-file (convert-standard-filename |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
133 "~/.emacs.d/.org-id-locations") |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
134 "The file for remembering in which file an ID was defined. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
135 This variable is only relevant when `org-id-track-globally' is set." |
96045 | 136 :group 'org-id |
137 :type 'file) | |
138 | |
139 (defvar org-id-locations nil | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
140 "List of files with ID's in those files. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
141 Depending on `org-id-use-hash' this can also be a hash table mapping ID's |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
142 to files.") |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
143 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
144 (defvar org-id-files nil |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
145 "List of files that contain ID's.") |
96045 | 146 |
147 (defcustom org-id-extra-files 'org-agenda-text-search-extra-files | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
148 "Files to be searched for ID's, besides the agenda files. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
149 When Org reparses files to remake the list of files and ID's it is tracking, |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
150 it will normally scan the agenda files, the archives related to agenda files, |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
151 any files that are listed as ID containing in the current register, and |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
152 any Org-mode files currently visited by Emacs. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
153 You can list additional files here. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
154 This variable is only relevant when `org-id-track-globally' is set." |
96045 | 155 :group 'org-id |
156 :type | |
157 '(choice | |
158 (symbol :tag "Variable") | |
159 (repeat :tag "List of files" | |
160 (file)))) | |
161 | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
162 (defcustom org-id-search-archives t |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
163 "Non-nil means, search also the archive files of agenda files for entries. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
164 This is a possibility to reduce overhead, but it measn that entries moved |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
165 to the archives can no longer be found by ID. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
166 This variable is only relevant when `org-id-track-globally' is set." |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
167 :group 'org-id |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
168 :type 'boolean) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
169 |
96045 | 170 ;;; The API functions |
171 | |
172 ;;;###autoload | |
173 (defun org-id-get-create (&optional force) | |
174 "Create an ID for the current entry and return it. | |
175 If the entry already has an ID, just return it. | |
176 With optional argument FORCE, force the creation of a new ID." | |
177 (interactive "P") | |
178 (when force | |
179 (org-entry-put (point) "ID" nil)) | |
180 (org-id-get (point) 'create)) | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
181 |
96045 | 182 ;;;###autoload |
183 (defun org-id-copy () | |
184 "Copy the ID of the entry at point to the kill ring. | |
185 Create an ID if necessary." | |
186 (interactive) | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
187 (kill-new (org-id-get nil 'create))) |
96045 | 188 |
189 ;;;###autoload | |
190 (defun org-id-get (&optional pom create prefix) | |
191 "Get the ID property of the entry at point-or-marker POM. | |
192 If POM is nil, refer to the entry at point. | |
193 If the entry does not have an ID, the function returns nil. | |
194 However, when CREATE is non nil, create an ID if none is present already. | |
195 PREFIX will be passed through to `org-id-new'. | |
196 In any case, the ID of the entry is returned." | |
197 (let ((id (org-entry-get pom "ID"))) | |
198 (cond | |
199 ((and id (stringp id) (string-match "\\S-" id)) | |
200 id) | |
201 (create | |
202 (setq id (org-id-new prefix)) | |
203 (org-entry-put pom "ID" id) | |
204 (org-id-add-location id (buffer-file-name (buffer-base-buffer))) | |
205 id) | |
206 (t nil)))) | |
207 | |
208 ;;;###autoload | |
209 (defun org-id-get-with-outline-path-completion (&optional targets) | |
210 "Use outline-path-completion to retrieve the ID of an entry. | |
211 TARGETS may be a setting for `org-refile-targets' to define the eligible | |
212 headlines. When omitted, all headlines in all agenda files are | |
213 eligible. | |
214 It returns the ID of the entry. If necessary, the ID is created." | |
215 (let* ((org-refile-targets (or targets '((nil . (:maxlevel . 10))))) | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
216 (org-refile-use-outline-path |
96045 | 217 (if (caar org-refile-targets) 'file t)) |
218 (spos (org-refile-get-location "Entry: ")) | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
219 (pom (and spos (move-marker (make-marker) (nth 3 spos) |
96045 | 220 (get-file-buffer (nth 1 spos)))))) |
221 (prog1 (org-id-get pom 'create) | |
222 (move-marker pom nil)))) | |
223 | |
224 ;;;###autoload | |
225 (defun org-id-get-with-outline-drilling (&optional targets) | |
226 "Use an outline-cycling interface to retrieve the ID of an entry. | |
227 This only finds entries in the current buffer, using `org-get-location'. | |
228 It returns the ID of the entry. If necessary, the ID is created." | |
229 (let* ((spos (org-get-location (current-buffer) org-goto-help)) | |
230 (pom (and spos (move-marker (make-marker) (car spos))))) | |
231 (prog1 (org-id-get pom 'create) | |
232 (move-marker pom nil)))) | |
233 | |
234 ;;;###autoload | |
235 (defun org-id-goto (id) | |
236 "Switch to the buffer containing the entry with id ID. | |
237 Move the cursor to that entry in that buffer." | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
238 (interactive "sID: ") |
96045 | 239 (let ((m (org-id-find id 'marker))) |
240 (unless m | |
241 (error "Cannot find entry with ID \"%s\"" id)) | |
242 (switch-to-buffer (marker-buffer m)) | |
243 (goto-char m) | |
244 (move-marker m nil) | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
245 (org-show-context))) |
96045 | 246 |
247 ;;;###autoload | |
248 (defun org-id-find (id &optional markerp) | |
249 "Return the location of the entry with the id ID. | |
250 The return value is a cons cell (file-name . position), or nil | |
251 if there is no entry with that ID. | |
252 With optional argument MARKERP, return the position as a new marker." | |
253 (let ((file (org-id-find-id-file id)) | |
254 org-agenda-new-buffers where) | |
255 (when file | |
256 (setq where (org-id-find-id-in-file id file markerp))) | |
257 (unless where | |
258 (org-id-update-id-locations) | |
259 (setq file (org-id-find-id-file id)) | |
260 (when file | |
261 (setq where (org-id-find-id-in-file id file markerp)))) | |
262 where)) | |
263 | |
264 ;;; Internal functions | |
265 | |
266 ;; Creating new IDs | |
267 | |
268 (defun org-id-new (&optional prefix) | |
269 "Create a new globally unique ID. | |
270 | |
271 An ID consists of two parts separated by a colon: | |
272 - a prefix | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
273 - a unique part that will be created according to `org-id-method'. |
96045 | 274 |
275 PREFIX can specify the prefix, the default is given by the variable | |
276 `org-id-prefix'. However, if PREFIX is the symbol `none', don't use any | |
277 prefix even if `org-id-prefix' specifies one. | |
278 | |
279 So a typical ID could look like \"Org:4nd91V40HI\"." | |
280 (let* ((prefix (if (eq prefix 'none) | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
281 "" |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
282 (concat (or prefix org-id-prefix) ":"))) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
283 unique) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
284 (if (equal prefix ":") (setq prefix "")) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
285 (cond |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
286 ((eq org-id-method 'uuidgen) |
99501
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
287 (setq unique (org-trim (shell-command-to-string "uuidgen")))) |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
288 ((eq org-id-method 'org) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
289 (let* ((etime (org-id-reverse-string (org-id-time-to-b36))) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
290 (postfix (if org-id-include-domain |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
291 (progn |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
292 (require 'message) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
293 (concat "@" (message-make-fqdn)))))) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
294 (setq unique (concat etime postfix)))) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
295 (t (error "Invalid `org-id-method'"))) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
296 (concat prefix unique))) |
96045 | 297 |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
298 (defun org-id-reverse-string (s) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
299 (mapconcat 'char-to-string (nreverse (string-to-list s)) "")) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
300 |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
301 (defun org-id-int-to-b36-one-digit (i) |
96045 | 302 "Turn an integer between 0 and 61 into a single character 0..9, A..Z, a..z." |
303 (cond | |
304 ((< i 10) (+ ?0 i)) | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
305 ((< i 36) (+ ?a i -10)) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
306 (t (error "Larger that 35")))) |
96045 | 307 |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
308 (defun org-id-b36-to-int-one-digit (i) |
96045 | 309 "Turn a character 0..9, A..Z, a..z into a number 0..61. |
310 The input I may be a character, or a single-letter string." | |
311 (and (stringp i) (setq i (string-to-char i))) | |
312 (cond | |
313 ((and (>= i ?0) (<= i ?9)) (- i ?0)) | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
314 ((and (>= i ?a) (<= i ?z)) (+ (- i ?a) 10)) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
315 (t (error "Invalid b36 letter")))) |
96045 | 316 |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
317 (defun org-id-int-to-b36 (i &optional length) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
318 "Convert an integer to a base-36 number represented as a string." |
96045 | 319 (let ((s "")) |
320 (while (> i 0) | |
321 (setq s (concat (char-to-string | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
322 (org-id-int-to-b36-one-digit (mod i 36))) s) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
323 i (/ i 36))) |
96045 | 324 (setq length (max 1 (or length 1))) |
325 (if (< (length s) length) | |
326 (setq s (concat (make-string (- length (length s)) ?0) s))) | |
327 s)) | |
328 | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
329 (defun org-id-b36-to-int (s) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
330 "Convert a base-36 string into the corresponding integer." |
96045 | 331 (let ((r 0)) |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
332 (mapc (lambda (i) (setq r (+ (* r 36) (org-id-b36-to-int-one-digit i)))) |
96045 | 333 s) |
334 r)) | |
335 | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
336 (defun org-id-time-to-b36 (&optional time) |
96045 | 337 "Encode TIME as a 10-digit string. |
338 This string holds the time to micro-second accuracy, and can be decoded | |
339 using `org-id-decode'." | |
340 (setq time (or time (current-time))) | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
341 (concat (org-id-int-to-b36 (nth 0 time) 4) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
342 (org-id-int-to-b36 (nth 1 time) 4) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
343 (org-id-int-to-b36 (or (nth 2 time) 0) 4))) |
96045 | 344 |
345 (defun org-id-decode (id) | |
346 "Split ID into the prefix and the time value that was used to create it. | |
347 The return value is (prefix . time) where PREFIX is nil or a string, | |
348 and time is the usual three-integer representation of time." | |
349 (let (prefix time parts) | |
350 (setq parts (org-split-string id ":")) | |
351 (if (= 2 (length parts)) | |
352 (setq prefix (car parts) time (nth 1 parts)) | |
353 (setq prefix nil time (nth 0 parts))) | |
98644
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
354 (setq time (org-id-reverse-string time)) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
355 (setq time (list (org-id-b36-to-int (substring time 0 4)) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
356 (org-id-b36-to-int (substring time 4 8)) |
e1cc41b9282d
2008-10-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
97027
diff
changeset
|
357 (org-id-b36-to-int (substring time 8 12)))) |
96045 | 358 (cons prefix time))) |
359 | |
360 ;; Storing ID locations (files) | |
361 | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
362 (defun org-id-update-id-locations (&optional files check) |
96045 | 363 "Scan relevant files for ID's. |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
364 Store the relation between files and corresponding ID's. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
365 This will scan all agenda files, all associated archives, and all |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
366 files currently mentioned in `org-id-locations'. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
367 When FILES is given, scan these files instead." |
96045 | 368 (interactive) |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
369 (if (not org-id-track-globally) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
370 (error "Please turn on `org-id-track-globally' if you want to track id's.") |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
371 (let ((files |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
372 (or files |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
373 (append |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
374 ;; Agenda files and all associated archives |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
375 (org-agenda-files t org-id-search-archives) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
376 ;; Explicit extra files |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
377 (if (symbolp org-id-extra-files) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
378 (symbol-value org-id-extra-files) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
379 org-id-extra-files) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
380 ;; Files associated with live org-mode buffers |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
381 (delq nil |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
382 (mapcar (lambda (b) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
383 (with-current-buffer b |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
384 (and (org-mode-p) (buffer-file-name)))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
385 (buffer-list))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
386 ;; All files known to have id's |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
387 org-id-files))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
388 org-agenda-new-buffers |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
389 file nfiles tfile ids reg found id seen (ndup 0)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
390 (setq nfiles (length files)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
391 (while (setq file (pop files)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
392 (message "Finding ID locations (%d/%d files): %s" |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
393 (- nfiles (length files)) nfiles file) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
394 (setq tfile (file-truename file)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
395 (when (and (file-exists-p file) (not (member tfile seen))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
396 (push tfile seen) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
397 (setq ids nil) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
398 (with-current-buffer (org-get-agenda-file-buffer file) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
399 (save-excursion |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
400 (save-restriction |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
401 (widen) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
402 (goto-char (point-min)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
403 (while (re-search-forward "^[ \t]*:ID:[ \t]+\\(\\S-+\\)[ \t]*$" |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
404 nil t) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
405 (setq id (org-match-string-no-properties 1)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
406 (if (member id found) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
407 (progn |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
408 (message "Duplicate ID \"%s\"" id) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
409 (setq ndup (1+ ndup))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
410 (push id found) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
411 (push id ids))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
412 (push (cons (abbreviate-file-name file) ids) reg)))))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
413 (org-release-buffers org-agenda-new-buffers) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
414 (setq org-agenda-new-buffers nil) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
415 (setq org-id-locations reg) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
416 (setq org-id-files (mapcar 'car org-id-locations)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
417 (org-id-locations-save) ;; this function can also handle the alist form |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
418 ;; now convert to a hash |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
419 (setq org-id-locations (org-id-alist-to-hash org-id-locations)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
420 (if (> ndup 0) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
421 (message "WARNING: %d duplicate ID's found, check *Messages* buffer" ndup) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
422 (message "%d unique files scanned for ID's" (length org-id-files))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
423 org-id-locations))) |
96045 | 424 |
425 (defun org-id-locations-save () | |
426 "Save `org-id-locations' in `org-id-locations-file'." | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
427 (when org-id-track-globally |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
428 (let ((out (if (hash-table-p org-id-locations) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
429 (org-id-hash-to-alist org-id-locations) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
430 org-id-locations))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
431 (with-temp-file org-id-locations-file |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
432 (print out (current-buffer)))))) |
96045 | 433 |
434 (defun org-id-locations-load () | |
435 "Read the data from `org-id-locations-file'." | |
436 (setq org-id-locations nil) | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
437 (when org-id-track-globally |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
438 (with-temp-buffer |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
439 (condition-case nil |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
440 (progn |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
441 (insert-file-contents-literally org-id-locations-file) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
442 (goto-char (point-min)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
443 (setq org-id-locations (read (current-buffer)))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
444 (error |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
445 (message "Could not read org-id-values from %s. Setting it to nil." |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
446 org-id-locations-file)))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
447 (setq org-id-files (mapcar 'car org-id-locations)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
448 (setq org-id-locations (org-id-alist-to-hash org-id-locations)))) |
96045 | 449 |
450 (defun org-id-add-location (id file) | |
451 "Add the ID with location FILE to the database of ID loations." | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
452 ;; Only if global tracking is on, and when the buffer has a file |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
453 (when (and org-id-track-globally id file) |
99849
621e15919df0
2008-11-23 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99501
diff
changeset
|
454 (unless org-id-locations (org-id-locations-load)) |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
455 (puthash id (abbreviate-file-name file) org-id-locations) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
456 (add-to-list 'org-id-files (abbreviate-file-name file)))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
457 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
458 (add-hook 'kill-emacs-hook 'org-id-locations-save) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
459 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
460 (defun org-id-hash-to-alist (hash) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
461 "Turn an org-id hash into an alist, so that it can be written to a file." |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
462 (let (res x) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
463 (maphash |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
464 (lambda (k v) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
465 (if (setq x (member v res)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
466 (push k (cdr x)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
467 (push (list v k) res))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
468 hash) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
469 res)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
470 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
471 (defun org-id-alist-to-hash (list) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
472 "Turn an org-id location list into a hash table." |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
473 (let ((res (make-hash-table |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
474 :test 'equal |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
475 :size (apply '+ (mapcar 'length list)))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
476 f i) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
477 (mapc |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
478 (lambda (x) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
479 (setq f (car x)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
480 (mapc (lambda (i) (puthash i f res)) (cdr x))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
481 list) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
482 res)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
483 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
484 (defun org-id-paste-tracker (txt &optional buffer-or-file) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
485 "Update any ID's in TXT and assign BUFFER-OR-FILE to them." |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
486 (when org-id-track-globally |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
487 (save-match-data |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
488 (setq buffer-or-file (or buffer-or-file (current-buffer))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
489 (when (bufferp buffer-or-file) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
490 (setq buffer-or-file (or (buffer-base-buffer buffer-or-file) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
491 buffer-or-file)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
492 (setq buffer-or-file (buffer-file-name buffer-or-file))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
493 (when buffer-or-file |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
494 (let ((fname (abbreviate-file-name buffer-or-file)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
495 (s 0)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
496 (while (string-match "^[ \t]*:ID:[ \t]+\\([^ \t\n\r]+\\)" txt s) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
497 (setq s (match-end 0)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
498 (org-id-add-location (match-string 1 txt) fname))))))) |
96045 | 499 |
500 ;; Finding entries with specified id | |
501 | |
502 (defun org-id-find-id-file (id) | |
503 "Query the id database for the file in which this ID is located." | |
504 (unless org-id-locations (org-id-locations-load)) | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
505 (or (gethash id org-id-locations) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
506 ;; ball back on current buffer |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
507 (buffer-file-name (or (buffer-base-buffer (current-buffer)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
508 (current-buffer))))) |
96045 | 509 |
510 (defun org-id-find-id-in-file (id file &optional markerp) | |
511 "Return the position of the entry ID in FILE. | |
512 If that files does not exist, or if it does not contain this ID, | |
513 return nil. | |
514 The position is returned as a cons cell (file-name . position). With | |
515 optional argument MARKERP, return the position as a new marker." | |
516 (let (org-agenda-new-buffers m buf pos) | |
517 (cond | |
518 ((not file) nil) | |
519 ((not (file-exists-p file)) nil) | |
520 (t (with-current-buffer (setq buf (org-get-agenda-file-buffer file)) | |
521 (setq pos (org-find-entry-with-id id)) | |
522 (when pos | |
523 (if markerp | |
524 (move-marker (make-marker) pos buf) | |
525 (cons file pos)))))))) | |
526 | |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
527 ;; id link type |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
528 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
529 ;; Calling the following function is hard-coded into `org-store-link', |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
530 ;; so we do have to add it to `org-store-link-functions'. |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
531 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
532 (defun org-id-store-link () |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
533 "Store a link to the current entry, using it's ID." |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
534 (interactive) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
535 (let* ((link (org-make-link "id:" (org-id-get-create))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
536 (desc (save-excursion |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
537 (org-back-to-heading t) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
538 (or (and (looking-at org-complex-heading-regexp) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
539 (if (match-end 4) (match-string 4) (match-string 0))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
540 link)))) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
541 (org-store-link-props :link link :description desc :type "id") |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
542 link)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
543 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
544 (defun org-id-open (id) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
545 "Go to the entry with id ID." |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
546 (org-mark-ring-push) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
547 (switch-to-buffer-other-window (current-buffer)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
548 (org-id-goto id)) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
549 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
550 (org-add-link-type "id" 'org-id-open) |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
551 |
96045 | 552 (provide 'org-id) |
553 | |
554 ;;; org-id.el ends here | |
555 | |
96052 | 556 ;; arch-tag: e5abaca4-e16f-4b25-832a-540cfb63a712 |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
557 |
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
558 |