Capture: fix the function target
[org-mode/org-jambu.git] / lisp / org-capture.el
blobde1e5f8b37e04876a87b394620e0d72aa2df6511
1 ;;; org-capture.el --- Fast note taking in Org-mode
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 6.36trans
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 ;; This file contains an alternaive implementation of the same functionality
29 ;; that is also provided by org-remember.el. The implementation is more
30 ;; streamlined, can produce more target types (e.g. plain list items or
31 ;; table lines). Also, it does not use a temporary buffer for editing
32 ;; the captured entry - instead it uses an indirect buffer that visits
33 ;; the new entry already in the target buffer (this was an idea by Samuel
34 ;; Wales). John Wiegley's excellent `remember.el' is not needed for this
35 ;; implementation, even though we borrow heavily from its ideas.
37 ;; This implementation heavily draws on ideas by James TD Smith and
38 ;; Samuel Wales, and, of cause, uses John Wiegley's remember.el as inspiration.
40 ;;; TODO
42 ;; - find a clever way to not always insert an annotation maybe a
43 ;; predicate function that can check for conditions for %a to be
44 ;; used. This could be one of the properties.
46 ;; - Should there be plist members that arrange for properties to be
47 ;; asked for, like James proposed in his RFC?
49 ;;; Code:
51 (eval-when-compile
52 (require 'cl))
53 (require 'org)
54 (require 'org-mks)
56 (declare-function org-datetree-find-date-create "org-datetree"
57 (DATE &optional KEEP-RESTRICTION))
58 (declare-function org-table-get-specials "org-table" ())
59 (declare-function org-table-goto-line "org-table" (N))
60 (defvar org-remember-default-headline)
61 (defvar org-remember-templates)
62 (defvar org-table-hlines)
64 (defvar org-capture-clock-was-started nil
65 "Internal flag, noting if the clock was started.")
67 (defvar org-capture-last-stored-marker (make-marker)
68 "Marker pointing to the entry most recently stored with `org-capture'.")
70 ;; The following variable is scoped dynamically by org-protocol
71 ;; to indicate that the link properties have already been stored
72 (defvar org-capture-link-is-already-stored nil)
74 (defgroup org-capture nil
75 "Options concerning capturing new entries."
76 :tag "Org Capture"
77 :group 'org)
79 (defcustom org-capture-templates nil
80 "Templates for the creation of new entries.
82 Each entry is a list with the following items:
84 keys The keys that will select the template, as a string, characters
85 only, for example \"a\" for a template to be selected with a
86 single key, or \"bt\" for selection with two keys. When using
87 several keys, keys using the same prefix key must be together
88 in the list and preceded by a 2-element entry explaining the
89 prefix key, for example
91 (\"b\" \"Templates for marking stuff to buy\")
93 The \"C\" key is used by default for quick access to the
94 customization of the template variable. But if you want to use
95 that key for a template, you can.
97 description A short string describing the template, will be shown during
98 selection.
100 type The type of entry. Valid are:
101 entry an Org-mode node, with a headline. Will be
102 filed as the child of the target entry or as
103 a top-level entry.
104 item a plain list item, placed in the first plain
105 list a the target location.
106 checkitem a checkbox item. This only differs from the
107 plain lis item by the default template.
108 table-line a new line in the first table at target location.
109 plain text to be inserted as it is.
111 target Specification of where the captured item should be placed.
112 In Org-mode files, targets usually define a node. Entries will
113 become children of this node, other types will be added to the
114 table or list in the body of this node.
116 Valid values are:
118 (file \"path/to/file\")
119 Text will be placed at the beginning or end of that file
121 (id \"id of existing org entry\")
122 Filing as child of this entry, or in the body of the entry
124 (file+headline \"path/to/file\" \"node headline\")
125 Fast configuration if the target heading is unique in the file
127 (file+olp \"path/to/file\" \"Level 1 heading\" \"Level 2\" ...)
128 For non-unique headings, the full path is safer
130 (file+regexp \"path/to/file\" \"regexp to find location\")
132 (file+datetree \"path/to/file\")
133 Will create a heading in a date tree.
135 (file+function \"path/to/file\" function-finding-location)
136 A function to find the right location in the file.
138 (clock)
139 File to the entry that is currently being clocked.
141 (function function-finding-location)
142 Most general way, write your own function to find both
143 file and location.
146 template The template for creating the capture item. If you leave this
147 empty, an appropriate default template will be used. See below
148 for more details.
150 The rest of the entry is a property list of additional options. Recognized
151 properties are:
153 :prepend Normally new captured information will be appended at
154 the target location (last child, last table line,
155 last list item...). Setting this property will
156 change that.
158 :immediate-finish When set, do not offer to edit the information, just
159 file it away immediately. This makes sense if the
160 template only needs information that can be added
161 automatically.
163 :empty-lines Set this to the number of lines the should be inserted
164 before and after the new item. Default 0, only common
165 other value is 1.
167 :clock-in Start the clock in this item.
169 :clock-resume Start the interrupted clock when finishing the capture.
171 :unnarrowed Do not narrow the target buffer, simply show the
172 full buffer. Default is to narrow it so that you
173 only see the new stuff.
175 :table-line-pos Specification of the location in the table where the
176 new line should be inserted. It looks like \"II-3\"
177 which means that the new line should become the third
178 line before the second horizontal separaor line.
180 The template defined the text to be inserted. Often then this is an org-mode
181 entry (so the first line should start with a star) that will be filed as a
182 child of the target headline. It can also be freely formatted text.
183 Furthermore, the following %-escapes will be replaced with content:
185 %^{prompt} Prompt the user for a string and replace this sequence with it.
186 A default value and a completion table ca be specified like this:
187 %^{prompt|default|completion2|completion3|...}
188 %t time stamp, date only
189 %T time stamp with date and time
190 %u, %U like the above, but inactive time stamps
191 %^t like %t, but prompt for date. Similarly %^T, %^u, %^U.
192 You may define a prompt like %^{Please specify birthday
193 %n user name (taken from `user-full-name')
194 %a annotation, normally the link created with `org-store-link'
195 %i initial content, copied from the active region. If %i is
196 indented, the entire inserted text will be indented as well.
197 %c current kill ring head
198 %x content of the X clipboard
199 %^C Interactive selection of which kill or clip to use
200 %^L Like %^C, but insert as link
201 %k title of currently clocked task
202 %K link to currently clocked task
203 %^g prompt for tags, with completion on tags in target file
204 %^G prompt for tags, with completion all tags in all agenda files
205 %^{prop}p Prompt the user for a value for property `prop'
206 %:keyword specific information for certain link types, see below
207 %[pathname] insert the contents of the file given by `pathname'
208 %(sexp) evaluate elisp `(sexp)' and replace with the result
210 %? After completing the template, position cursor here.
212 Apart from these general escapes, you can access information specific to the
213 link type that is created. For example, calling `org-capture' in emails
214 or gnus will record the author and the subject of the message, which you
215 can access with \"%:author\" and \"%:subject\", respectively. Here is a
216 complete list of what is recorded for each link type.
218 Link type | Available information
219 -------------------+------------------------------------------------------
220 bbdb | %:type %:name %:company
221 vm, wl, mh, rmail | %:type %:subject %:message-id
222 | %:from %:fromname %:fromaddress
223 | %:to %:toname %:toaddress
224 | %:fromto (either \"to NAME\" or \"from NAME\")
225 gnus | %:group, for messages also all email fields
226 w3, w3m | %:type %:url
227 info | %:type %:file %:node
228 calendar | %:type %:date"
229 :group 'org-capture
230 :type
231 '(repeat
232 (choice :value ("" "" entry (file "~/org/notes.org") "")
233 (list :tag "Multikey description"
234 (string :tag "Keys ")
235 (string :tag "Description"))
236 (list :tag "Template entry"
237 (string :tag "Keys ")
238 (string :tag "Description ")
239 (choice :tag "Capture Type " :value entry
240 (const :tag "Org entry" entry)
241 (const :tag "Plain list item" item)
242 (const :tag "Checkbox item" checkitem)
243 (const :tag "Plain text" plain)
244 (const :tag "Table line" table-line))
245 (choice :tag "Target location"
246 (list :tag "File"
247 (const :format "" file)
248 (file :tag " File"))
249 (list :tag "ID"
250 (const :format "" id)
251 (string :tag " ID"))
252 (list :tag "File & Headline"
253 (const :format "" file+headline)
254 (file :tag " File ")
255 (string :tag " Headline"))
256 (list :tag "File & Outline path"
257 (const :format "" file+olp)
258 (file :tag " File ")
259 (repeat :tag "Outline path" :inline t
260 (string :tag "Headline")))
261 (list :tag "File & Regexp"
262 (const :format "" file+regexp)
263 (file :tag " File ")
264 (regexp :tag " Regexp"))
265 (list :tag "File & Date tree"
266 (const :format "" file+datetree)
267 (file :tag " File"))
268 (list :tag "File & function"
269 (const :format "" file+function)
270 (file :tag " File ")
271 (sexp :tag " Function"))
272 (list :tag "Current clocking task"
273 (const :format "" clock))
274 (list :tag "Function"
275 (const :format "" function)
276 (sexp :tag " Function")))
277 (string :tag "Template (opt) ")
278 (plist :inline t
279 ;; Give the most common options as checkboxes
280 :options (((const :format "%v " :prepend) (const t))
281 ((const :format "%v " :immediate-finish) (const t))
282 ((const :format "%v " :empty-lines) (const 1))
283 ((const :format "%v " :clock-in) (const t))
284 ((const :format "%v " :clock-resume) (const t))
285 ((const :format "%v " :unnarrowed) (const t))))))))
287 (defcustom org-capture-before-finalize-hook nil
288 "Hook that is run right before a remember process is finalized.
289 The remember buffer is still current when this hook runs."
290 :group 'org-capture
291 :type 'hook)
293 ;;; The property list for keeping information about the capture process
295 (defvar org-capture-plist nil
296 "Plist for the current capture process, global, to avoid having to pass it.")
297 (defvar org-capture-current-plist nil
298 "Local variable holding the plist in a capture buffer.
299 This is used to store the plist for use when finishing a capture process.
300 Another such process might have changed the global varaible by then.")
302 (defun org-capture-put (&rest stuff)
303 (while stuff
304 (setq org-capture-plist (plist-put org-capture-plist
305 (pop stuff) (pop stuff)))))
306 (defun org-capture-get (prop &optional local)
307 (plist-get (if local org-capture-current-plist org-capture-plist) prop))
309 (defun org-capture-member (prop)
310 (plist-get org-capture-plist prop))
312 ;;; The minor mode
314 (defvar org-capture-mode-map (make-sparse-keymap)
315 "Keymap for org-capture-mode, a minor mode.
316 Use this map to set additional keybindings for when Org-mode is used
317 for a Remember buffer.")
319 (defvar org-capture-mode-hook nil
320 "Hook for the minor `org-capture-mode'.")
322 (define-minor-mode org-capture-mode
323 "Minor mode for special key bindings in a remember buffer."
324 nil " Rem" org-capture-mode-map
325 (org-set-local
326 'header-line-format
327 "Capture buffer. Finish `C-c C-c', refile `C-c C-w', abort `C-c C-k'.")
328 (run-hooks 'org-capture-mode-hook))
329 (define-key org-capture-mode-map "\C-c\C-c" 'org-capture-finalize)
330 (define-key org-capture-mode-map "\C-c\C-k" 'org-capture-kill)
331 (define-key org-capture-mode-map "\C-c\C-w" 'org-capture-refile)
333 ;;; The main commands
335 ;;;###autoload
336 (defun org-capture (&optional goto keys)
337 "Capture something.
339 This will let you select a template from org-capture-templates, and then
340 file new captured information. The text is immediately inserted at the
341 target location, and an indirect buffer is shown where you can edit it.
342 Pressing `C-c C-c' brings you back to the previous state of Emacs,
343 so that you can continue your work.
345 When called interactively with a `C-u' prefix argument GOTO, don't capture
346 anything, just go to the file/headline where the selected template
347 stores its notes. With a double prefix arg `C-u C-u', go to the last
348 note stored.
350 When called with a `C-0' (zero) prefix, insert a template at point.
352 Lisp programs can set KEYS to a string associated with a template in
353 `org-capture-templates'. In this case, interactive selection will be
354 bypassed."
355 (interactive "P")
356 (cond
357 ((equal goto '(4)) (org-capture-goto-target))
358 ((equal goto '(16)) (org-capture-goto-last-stored))
360 ;; FIXME: Are these needed?
361 (let* ((orig-buf (current-buffer))
362 (annotation (if org-capture-link-is-already-stored
363 (plist-get org-store-link-plist :annotation)
364 (org-store-link nil)))
365 (initial (and (org-region-active-p)
366 (buffer-substring (point) (mark))))
367 (entry (org-capture-select-template keys)))
368 (cond
369 ((equal entry "C")
370 (customize-variable 'org-capture-templates))
371 ((equal entry "q")
372 (error "Abort"))
374 (org-capture-set-plist entry)
375 (org-capture-put :original-buffer orig-buf :annotation annotation
376 :initial initial)
377 (org-capture-put :default-time
378 (or org-overriding-default-time
379 (org-current-time)))
380 (org-capture-set-target-location)
381 (condition-case error
382 (org-capture-put :template (org-capture-fill-template))
383 ((error quit)
384 (if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
385 (error "Capture abort: %s" error)))
387 (if (equal goto 0)
388 ;;insert at point
389 (org-capture-insert-template-here)
390 (condition-case error
391 (org-capture-place-template)
392 ((error quit)
393 (if (and (buffer-base-buffer (current-buffer))
394 (string-match "\\`CAPTURE-" (buffer-name)))
395 (kill-buffer (current-buffer)))
396 (set-window-configuration (org-capture-get :return-to-wconf))
397 (error "Capture template `%s': %s"
398 (org-capture-get :key)
399 (nth 1 error))))
400 (if (org-capture-get :immediate-finish)
401 (org-capture-finalize)
402 (if (and (org-mode-p)
403 (org-capture-get :clock-in))
404 (condition-case nil
405 (progn
406 (if (org-clock-is-active)
407 (org-capture-put :interrupted-clock
408 (copy-marker org-clock-marker)))
409 (org-clock-in)
410 (org-set-local 'org-capture-clock-was-started t))
411 (error
412 "Could not start the clock in this capture buffer")))))))))))
414 (defun org-capture-finalize ()
415 "Finalize the capture process."
416 (interactive)
417 (unless (and org-capture-mode
418 (buffer-base-buffer (current-buffer)))
419 (error "This does not seem to be a capture buffer for Org-mode"))
421 ;; Did we start the clock in this capture buffer?
422 (when (and org-capture-clock-was-started
423 org-clock-marker (marker-buffer org-clock-marker)
424 (equal (marker-buffer org-clock-marker) (buffer-base-buffer))
425 (> org-clock-marker (point-min))
426 (< org-clock-marker (point-max)))
427 ;; Looks like the clock we started is still running. Clock out.
428 (let (org-log-note-clock-out) (org-clock-out))
429 (when (and (org-capture-get :clock-resume 'local)
430 (markerp (org-capture-get :interrupted-clock 'local))
431 (buffer-live-p (marker-buffer
432 (org-capture-get :interrupted-clock 'local))))
433 (org-with-point-at (org-capture-get :interrupted-clock 'local)
434 (org-clock-in))
435 (message "Interrupted clock has been resumed")))
437 (let ((beg (point-min))
438 (end (point-max))
439 (abort-note nil))
440 (widen)
442 (if org-note-abort
443 (let ((m1 (org-capture-get :begin-marker 'local))
444 (m2 (org-capture-get :end-marker 'local)))
445 (if (and m1 m2 (= m1 beg) (= m2 end))
446 (progn
447 (setq abort-note 'clean)
448 (kill-region m1 m2))
449 (setq abort-note 'dirty)))
451 ;; Make sure that the empty lines after are correct
452 (when (and (> (point-max) end) ; indeed, the buffer was still narrowed
453 (member (org-capture-get :type 'local)
454 '(entry item checkitem plain)))
455 (save-excursion
456 (goto-char end)
457 (or (bolp) (newline))
458 (org-capture-empty-lines-after
459 (or (org-capture-get :empty-lines 'local) 0))))
460 ;; Postprocessing: Update Statistics cookies, do the sorting
461 (when (org-mode-p)
462 (save-excursion
463 (when (ignore-errors (org-back-to-heading))
464 (org-update-parent-todo-statistics)
465 (org-update-checkbox-count)))
466 ;; FIXME Here we should do the sorting
467 ;; If we have added a table line, maybe recompute?
468 (when (and (eq (org-capture-get :type 'local) 'table-line)
469 (org-at-table-p))
470 (if (org-table-get-stored-formulas)
471 (org-table-recalculate 'all) ;; FIXME: Should we iterate???
472 (org-table-align)))
474 ;; Store this place as the last one where we stored something
475 ;; Do the marking in the base buffer, so that it makes sense after
476 ;; the indirect buffer has been killed.
477 (org-capture-bookmark-last-stored-position)
479 ;; Run the hook
480 (run-hooks 'org-capture-before-finalize-hook)
483 ;; Kill the indirect buffer
484 (save-buffer)
485 (let ((return-wconf (org-capture-get :return-to-wconf 'local)))
486 (kill-buffer (current-buffer))
487 ;; Restore the window configuration before capture
488 (set-window-configuration return-wconf))
489 (when abort-note
490 (cond
491 ((equal abort-note 'clean)
492 (message "Capture process aborted and target file cleaned up"))
493 ((equal abort-note 'dirty)
494 (error "Capture process aborted, but target buffer could not be cleaned up correctly"))))))
496 (defun org-capture-refile ()
497 "Finalize the current capture and then refile the entry.
498 Refiling is done from the base buffer, because the indirect buffer is then
499 already gone."
500 (interactive)
501 (unless (eq (org-capture-get :type 'local) 'entry)
502 (error
503 "Refiling from a capture buffer makes only sense for `entry'-type templates"))
504 (let ((pos (point)) (base (buffer-base-buffer (current-buffer))))
505 (org-capture-finalize)
506 (save-window-excursion
507 (with-current-buffer (or base (current-buffer))
508 (save-excursion
509 (save-restriction
510 (widen)
511 (goto-char pos)
512 (call-interactively 'org-refile)))))))
514 (defun org-capture-kill ()
515 "Abort the current capture process."
516 (interactive)
517 ;; FIXME: This does not do the right thing, we need to remove the new stuff
518 ;; By hand it is easy: undo, then kill the buffer
519 (let ((org-note-abort t) (org-capture-before-finalize-hook nil))
520 (org-capture-finalize)))
522 (defun org-capture-goto-last-stored ()
523 "Go to the location where the last remember note was stored."
524 (interactive)
525 (org-goto-marker-or-bmk org-capture-last-stored-marker
526 "org-capture-last-stored")
527 (message "This is the last note stored by a capture process"))
529 ;;; Supporting functions for handling the process
531 (defun org-capture-set-target-location (&optional target)
532 "Find target buffer and position and store then in the property list."
533 (let ((target-entry-p t))
534 (setq target (or target (org-capture-get :target)))
535 (save-excursion
536 (cond
537 ((eq (car target) 'file)
538 (set-buffer (org-capture-target-buffer (nth 1 target)))
539 (setq target-entry-p nil))
541 ((eq (car target) 'id)
542 (let ((loc (org-id-find (nth 1 target))))
543 (if (not loc)
544 (error "Cannot find target ID \"%s\"" (nth 1 target))
545 (set-buffer (org-capture-target-buffer (car loc)))
546 (goto-char (cdr loc)))))
548 ((eq (car target) 'file+headline)
549 (set-buffer (org-capture-target-buffer (nth 1 target)))
550 (let ((hd (nth 2 target)))
551 (goto-char (point-min))
552 (if (re-search-forward
553 (format org-complex-heading-regexp-format (regexp-quote hd))
554 nil t)
555 (goto-char (point-at-bol))
556 (goto-char (point-max))
557 (or (bolp) (insert "\n"))
558 (insert "* " hd "\n")
559 (beginning-of-line 0))))
561 ((eq (car target) 'file+olp)
562 (let ((m (org-find-olp (cdr target))))
563 (set-buffer (marker-buffer m))
564 (goto-char m)))
566 ((eq (car target) 'file+regexp)
567 (set-buffer (org-capture-target-buffer (nth 1 target)))
568 (goto-char (point-min))
569 (if (re-search-forward (nth 2 target) nil t)
570 (progn
571 (goto-char (if (org-capture-get :prepend)
572 (match-beginning 0) (match-end 0)))
573 (org-capture-put :exact-position (point))
574 (setq target-entry-p (and (org-mode-p) (org-at-heading-p))))
575 (error "No match for target regexp in file %s" (nth 1 target))))
577 ((eq (car target) 'file+datetree)
578 (require 'org-datetree)
579 (set-buffer (org-capture-target-buffer (nth 1 target)))
580 ;; Make a date tree entry, with the current date (or yesterday,
581 ;; if we are extending dates for a couple of hours)
582 (org-datetree-find-date-create
583 (calendar-gregorian-from-absolute
584 (if org-overriding-default-time
585 (time-to-days org-overriding-default-time)
586 (time-to-days
587 (time-subtract (current-time)
588 (list 0 (* 3600 org-extend-today-until) 0)))))))
590 ((eq (car target) 'file+function)
591 (set-buffer (org-capture-target-buffer (nth 1 target)))
592 (funcall (nth 2 target))
593 (org-capture-put :exact-position (point))
594 (setq target-entry-p (and (org-mode-p) (org-at-heading-p))))
596 ((eq (car target) 'function)
597 (funcall (nth 1 target))
598 (org-capture-put :exact-position (point))
599 (setq target-entry-p (and (org-mode-p) (org-at-heading-p))))
601 ((eq (car target) 'clock)
602 (if (and (markerp org-clock-hd-marker)
603 (marker-buffer org-clock-hd-marker))
604 (progn (set-buffer (marker-buffer org-clock-hd-marker))
605 (goto-char org-clock-hd-marker))
606 (error "No running clock that could be used as capture target")))
608 (t (error "Invalid capture target specification")))
610 (org-capture-put :buffer (current-buffer) :pos (point)
611 :target-entry-p target-entry-p))))
613 (defun org-capture-target-buffer (file)
614 "Get a buffer for FILE."
615 (or (org-find-base-buffer-visiting file)
616 (find-file-noselect (expand-file-name file org-directory))))
618 (defun org-capture-steal-local-variables (buffer)
619 "Install Org-mode local variables"
620 (mapc (lambda (v)
621 (ignore-errors (org-set-local (car v) (cdr v))))
622 (buffer-local-variables buffer)))
624 (defun org-capture-place-template ()
625 "Insert the template at the target location, and display the buffer."
626 (org-capture-put :return-to-wconf (current-window-configuration))
627 (delete-other-windows)
628 (org-switch-to-buffer-other-window
629 (org-capture-get-indirect-buffer (org-capture-get :buffer) "CAPTURE"))
630 (show-all)
631 (goto-char (org-capture-get :pos))
632 (org-set-local 'org-capture-target-marker
633 (move-marker (make-marker) (point)))
634 (let* ((template (org-capture-get :template))
635 (type (org-capture-get :type)))
636 (case type
637 ((nil entry) (org-capture-place-entry))
638 (table-line (org-capture-place-table-line))
639 (plain (org-capture-place-plain-text))
640 (item (org-capture-place-item))))
641 (org-capture-mode 1)
642 (org-set-local 'org-capture-current-plist org-capture-plist))
644 (defun org-capture-place-entry ()
645 "Place the template as a new Org entry."
646 (let* ((txt (org-capture-get :template))
647 (reversed (org-capture-get :prepend))
648 (target-entry-p (org-capture-get :target-entry-p))
649 level beg end)
650 (cond
651 ((org-capture-get :exact-position)
652 (goto-char (org-capture-get :exact-position)))
653 ((not target-entry-p)
654 ;; Insert as top-level entry, either at beginning or at end of file
655 (setq level 1)
656 (if reversed
657 (progn (goto-char (point-min))
658 (outline-next-heading))
659 (goto-char (point-max))
660 (or (bolp) (insert "\n"))))
662 ;; Insert as a child of the current entry
663 (and (looking-at "\\*+")
664 (setq level (- (match-end 0) (match-beginning 0))))
665 (setq level (org-get-valid-level (or level 1) 1))
666 (if reversed
667 (progn
668 (outline-next-heading)
669 (or (bolp) (insert "\n")))
670 (org-end-of-subtree t t)
671 (or (bolp) (insert "\n")))))
672 (org-capture-empty-lines-before)
673 (setq beg (point))
674 (org-paste-subtree level txt 'for-yank)
675 (org-capture-empty-lines-after 1)
676 (org-capture-position-for-last-stored beg)
677 (outline-next-heading)
678 (setq end (point))
679 (org-capture-mark-kill-region beg (1- end))
680 (org-capture-narrow beg (1- end))
681 (if (re-search-forward "%\\?" end t) (replace-match ""))))
683 (defun org-capture-place-item ()
684 "Place the template as a new plain list item."
685 (let* ((txt (org-capture-get :template))
686 (target-entry-p (org-capture-get :target-entry-p))
687 (ind 0)
688 beg end)
689 (cond
690 ((org-capture-get :exact-position)
691 (goto-char (org-capture-get :exact-position)))
692 ((not target-entry-p)
693 ;; Insert as top-level entry, either at beginning or at end of file
694 (setq beg (point-min) end (point-max)))
696 (setq beg (1+ (point-at-eol))
697 end (save-excursion (outline-next-heading) (point)))))
698 (if (org-capture-get :prepend)
699 (progn
700 (goto-char beg)
701 (if (re-search-forward (concat "^" (org-item-re)) nil t)
702 (progn
703 (goto-char (match-beginning 0))
704 (setq ind (org-get-indentation)))
705 (goto-char end)
706 (setq ind 0)))
707 (goto-char end)
708 (if (re-search-backward (concat "^" (org-item-re)) nil t)
709 (progn
710 (setq ind (org-get-indentation))
711 (org-end-of-item))
712 (setq ind 0)))
713 ;; Remove common indentation
714 (setq txt (org-remove-indentation txt))
715 ;; Make sure this is indeed an item
716 (unless (string-match (concat "\\`" (org-item-re)) txt)
717 (setq txt (concat "- "
718 (mapconcat 'identity (split-string txt "\n")
719 "\n "))))
720 ;; Set the correct indentation, depending on context
721 (setq ind (make-string ind ?\ ))
722 (setq txt (concat ind
723 (mapconcat 'identity (split-string txt "\n")
724 (concat "\n" ind))
725 "\n"))
726 ;; Insert, with surrounding empty lines
727 (org-capture-empty-lines-before)
728 (setq beg (point))
729 (insert txt)
730 (or (bolp) (insert "\n"))
731 (org-capture-empty-lines-after 1)
732 (org-capture-position-for-last-stored beg)
733 (forward-char 1)
734 (setq end (point))
735 (org-capture-mark-kill-region beg (1- end))
736 (org-capture-narrow beg (1- end))
737 (if (re-search-forward "%\\?" end t) (replace-match ""))))
739 (defun org-capture-place-table-line ()
740 "Place the template as a table line."
741 (require 'org-table)
742 (let* ((txt (org-capture-get :template))
743 (target-entry-p (org-capture-get :target-entry-p))
744 (table-line-pos (org-capture-get :table-line-pos))
745 ind beg end)
746 (cond
747 ((org-capture-get :exact-position)
748 (goto-char (org-capture-get :exact-position)))
749 ((not target-entry-p)
750 ;; Table is not necessarily under a heading
751 (setq beg (point-min) end (point-max)))
753 ;; WE are at a heading, limit search to the body
754 (setq beg (1+ (point-at-eol))
755 end (save-excursion (outline-next-heading) (point)))))
756 (if (re-search-forward org-table-dataline-regexp end t)
757 (let ((b (org-table-begin)) (e (org-table-end)))
758 (goto-char e)
759 (if (looking-at "[ \t]*#\\+TBLFM:")
760 (forward-line 1))
761 (narrow-to-region b (point)))
762 (goto-char end)
763 (insert "\n| |\n|----|\n| |\n")
764 (narrow-to-region (1+ end) (point)))
765 ;; We are narrowed to the table, or to an empty line if there was no table
767 ;; Check if the template is good
768 (if (not (string-match org-table-dataline-regexp txt))
769 (setq txt "| %?Bad template |\n"))
770 (cond
771 ((and table-line-pos
772 (string-match "\\(I+\\)\\([-+][0-9]\\)" table-line-pos))
773 ;; we have a complex line specification
774 (goto-char (point-min))
775 (let ((nh (- (match-end 1) (match-beginning 1)))
776 (delta (string-to-number (match-string 2 table-line-pos)))
778 ;; The user wants a special position in the table
779 (org-table-get-specials)
780 (setq ll (ignore-errors (aref org-table-hlines nh)))
781 (unless ll (error "Invalid table line specification \"%s\""
782 table-line-pos))
783 (setq ll (+ ll delta (if (< delta 0) 0 -1)))
784 (org-goto-line ll)
785 (org-table-insert-row 'below)
786 (beginning-of-line 1)
787 (delete-region (point) (1+ (point-at-eol)))
788 (setq beg (point))
789 (insert txt)
790 (setq end (point))))
791 ((org-capture-get :prepend)
792 (goto-char (point-min))
793 (re-search-forward org-table-hline-regexp nil t)
794 (beginning-of-line 1)
795 (re-search-forward org-table-dataline-regexp nil t)
796 (beginning-of-line 1)
797 (setq beg (point))
798 (org-table-insert-row)
799 (beginning-of-line 1)
800 (delete-region (point) (1+ (point-at-eol)))
801 (insert txt)
802 (setq end (point)))
804 (goto-char (point-max))
805 (re-search-backward org-table-dataline-regexp nil t)
806 (beginning-of-line 1)
807 (org-table-insert-row 'below)
808 (beginning-of-line 1)
809 (delete-region (point) (1+ (point-at-eol)))
810 (setq beg (point))
811 (insert txt)
812 (setq end (point))))
813 (goto-char beg)
814 (org-capture-position-for-last-stored 'table-line)
815 (if (re-search-forward "%\\?" end t) (replace-match ""))
816 (org-table-align)))
818 (defun org-capture-place-plain-text ()
819 "Place the template plainly."
820 (let* ((txt (org-capture-get :template))
821 beg end)
822 (goto-char (cond
823 ((org-capture-get :exact-position))
824 ((org-capture-get :prepend) (point-min))
825 (t (point-max))))
826 (or (bolp) (newline))
827 (org-capture-empty-lines-before)
828 (setq beg (point))
829 (insert txt)
830 (org-capture-empty-lines-after 1)
831 (org-capture-position-for-last-stored beg)
832 (setq end (point))
833 (org-capture-mark-kill-region beg (1- end))
834 (org-capture-narrow beg (1- end))
835 (if (re-search-forward "%\\?" end t) (replace-match ""))))
837 (defun org-capture-mark-kill-region (beg end)
838 "Mark the region that will have to be killed when aborting capture."
839 (let ((m1 (move-marker (make-marker) beg))
840 (m2 (move-marker (make-marker) end)))
841 (org-capture-put :begin-marker m1)
842 (org-capture-put :end-marker m2)))
844 (defun org-capture-position-for-last-stored (where)
845 "Memorize the position that should later become the position of last capture."
846 (cond
847 ((integerp where)
848 (org-capture-put :position-for-last-stored
849 (move-marker (make-marker) where
850 (or (buffer-base-buffer (current-buffer))
851 (current-buffer)))))
852 ((eq where 'table-line)
853 (org-capture-put :position-for-last-stored
854 (list 'table-line
855 (org-table-current-dline))))
856 (t (error "This should not happen"))))
858 (defun org-capture-bookmark-last-stored-position ()
859 "Bookmark the last-captured position."
860 (let* ((where (org-capture-get :position-for-last-stored 'local))
861 (pos (cond
862 ((markerp where)
863 (prog1 (marker-position where)
864 (move-marker where nil)))
865 ((and (listp where) (eq (car where) 'table-line))
866 (if (org-at-table-p)
867 (save-excursion
868 (org-table-goto-line (nth 1 where))
869 (point-at-bol))
870 (point))))))
871 (with-current-buffer (buffer-base-buffer (current-buffer))
872 (save-excursion
873 (save-restriction
874 (widen)
875 (goto-char pos)
876 (bookmark-set "org-capture-last-stored")
877 (move-marker org-capture-last-stored-marker (point)))))))
879 (defun org-capture-narrow (beg end)
880 "Narrow, unless configuraion says not to narrow."
881 (unless (org-capture-get :unnarrowed)
882 (narrow-to-region beg end)
883 (goto-char beg)))
885 (defun org-capture-empty-lines-before (&optional n)
886 "Arrange for the correct number of empty lines before the insertion point.
887 Point will be after the empty lines, so insertion can direcetly be done."
888 (setq n (or n (org-capture-get :empty-lines) 0))
889 (let ((pos (point)))
890 (org-back-over-empty-lines)
891 (delete-region (point) pos)
892 (newline n)))
894 (defun org-capture-empty-lines-after (&optional n)
895 "Arrange for the correct number of empty lines after the inserted string.
896 Point will remain at the first line after the inserted text."
897 (setq n (or n (org-capture-get :empty-lines) 0))
898 (org-back-over-empty-lines)
899 (while (looking-at "[ \t]*\n") (replace-match ""))
900 (let ((pos (point)))
901 (newline n)
902 (goto-char pos)))
904 (defvar org-clock-marker) ; Defined in org.el
905 ;;;###autoload
906 (defun org-capture-insert-template-here ()
907 (let* ((template (org-capture-get :template))
908 (type (org-capture-get :type))
909 beg end pp)
910 (or (bolp) (newline))
911 (setq beg (point))
912 (cond
913 ((and (eq type 'entry) (org-mode-p))
914 (org-paste-subtree nil template t))
915 ((and (memq type '(item checkitem))
916 (org-mode-p)
917 (save-excursion (skip-chars-backward " \t\n")
918 (setq pp (point))
919 (org-in-item-p)))
920 (goto-char pp)
921 (org-insert-item)
922 (skip-chars-backward " ")
923 (skip-chars-backward "-+*0123456789).")
924 (delete-region (point) (point-at-eol))
925 (setq beg (point))
926 (org-remove-indentation template)
927 (insert template)
928 (org-capture-empty-lines-after)
929 (goto-char beg)
930 (org-maybe-renumber-ordered-list)
931 (org-end-of-item)
932 (setq end (point)))
933 (t (insert template)))
934 (setq end (point))
935 (goto-char beg)
936 (if (re-search-forward "%\\?" end t)
937 (replace-match ""))))
939 (defun org-capture-set-plist (entry)
940 "Initialize the property list from the template definition."
941 (setq org-capture-plist (copy-sequence (nthcdr 5 entry)))
942 (org-capture-put :key (car entry) :description (nth 1 entry)
943 :target (nth 3 entry))
944 (let ((txt (nth 4 entry)) (type (or (nth 2 entry) 'entry)))
945 (when (or (not txt) (not (string-match "\\S-" txt)))
946 ;; The template may be empty or omitted for special types.
947 ;; Here we insert the default templates for such cases.
948 (cond
949 ((eq type 'item) (setq txt "- %?"))
950 ((eq type 'checkitem) (setq txt "- [ ] %?"))
951 ((eq type 'table-line) (setq txt "| %? |"))
952 ((member type '(nil entry)) (setq txt "* %?\n %a"))))
953 (org-capture-put :template txt :type type)))
955 (defun org-capture-goto-target (&optional template-key)
956 "Go to the target location of a capture template.
957 The user is queried for the template."
958 (interactive)
959 (let* (org-select-template-temp-major-mode
960 (entry (org-capture-select-template template-key)))
961 (unless entry
962 (error "No capture emplate selected"))
963 (org-capture-set-plist entry)
964 (org-capture-set-target-location)
965 (switch-to-buffer (org-capture-get :buffer))
966 (goto-char (org-capture-get :pos))))
968 (defun org-capture-get-indirect-buffer (&optional buffer prefix)
969 "Make an indirect buffer for a capture process.
970 Use PREFIX as a prefix for the name of the indirect buffer."
971 (setq buffer (or buffer (current-buffer)))
972 (let ((n 1) (base (buffer-name buffer)) bname)
973 (setq bname (concat prefix "-" base))
974 (while (buffer-live-p (get-buffer bname))
975 (setq bname (concat prefix "-" (number-to-string (incf n)) "-" base)))
976 (condition-case nil
977 (make-indirect-buffer buffer bname 'clone)
978 (error (make-indirect-buffer buffer bname)))))
981 ;;; The template code
983 (defun org-capture-select-template (&optional keys)
984 "Select a capture template.
985 Lisp programs can force the template by setting KEYS to a string."
986 (when org-capture-templates
987 (if keys
988 (or (assoc keys org-capture-templates)
989 (error "No capture template referred to by \"%s\" keys" keys))
990 (if (= 1 (length org-capture-templates))
991 (car org-capture-templates)
992 (org-mks org-capture-templates
993 "Select a capture template\n========================="
994 "Template key: "
995 '(("C" "Customize org-capture-templates")
996 ("q" "Abort")))))))
998 (defun org-capture-fill-template (&optional template initial annotation)
999 "Fill a template and return the filled template as a string.
1000 The template may still contain \"%?\" for cursor positioning."
1001 (setq template (or template (org-capture-get :template)))
1002 (when (stringp initial)
1003 (setq initial (org-no-properties initial))
1004 (remove-text-properties 0 (length initial) '(read-only t) initial))
1005 (let* ((buffer (org-capture-get :buffer))
1006 (file (buffer-file-name (or (buffer-base-buffer buffer) buffer)))
1007 (ct (org-capture-get :default-time))
1008 (dct (decode-time ct))
1009 (ct1
1010 (if (< (nth 2 dct) org-extend-today-until)
1011 (encode-time 0 59 23 (1- (nth 3 dct)) (nth 4 dct) (nth 5 dct))
1012 ct))
1013 (plist-p (if org-store-link-plist t nil))
1014 (v-c (and (> (length kill-ring) 0) (current-kill 0)))
1015 (v-x (or (org-get-x-clipboard 'PRIMARY)
1016 (org-get-x-clipboard 'CLIPBOARD)
1017 (org-get-x-clipboard 'SECONDARY)))
1018 (v-t (format-time-string (car org-time-stamp-formats) ct))
1019 (v-T (format-time-string (cdr org-time-stamp-formats) ct))
1020 (v-u (concat "[" (substring v-t 1 -1) "]"))
1021 (v-U (concat "[" (substring v-T 1 -1) "]"))
1022 ;; `initial' and `annotation' might habe been passed.
1023 ;; But if the property list has them, we prefer those values
1024 (v-i (or (plist-get org-store-link-plist :initial)
1025 initial
1026 (org-capture-get :initial)
1027 ""))
1028 (v-a (or (plist-get org-store-link-plist :annotation)
1029 annotation
1030 (org-capture-get :annotation)
1031 ""))
1032 ;; Is the link empty? Then we do not want it...
1033 (v-a (if (equal v-a "[[]]") "" v-a))
1034 (clipboards (remove nil (list v-i
1035 (org-get-x-clipboard 'PRIMARY)
1036 (org-get-x-clipboard 'CLIPBOARD)
1037 (org-get-x-clipboard 'SECONDARY)
1038 v-c)))
1039 (v-A (if (and v-a
1040 (string-match
1041 "\\[\\(\\[.*?\\]\\)\\(\\[.*?\\]\\)?\\]" v-a))
1042 (replace-match "[\\1[%^{Link description}]]" nil nil v-a)
1043 v-a))
1044 (v-n user-full-name)
1045 (v-k (if (marker-buffer org-clock-marker)
1046 (org-substring-no-properties org-clock-heading)))
1047 (v-K (if (marker-buffer org-clock-marker)
1048 (org-make-link-string
1049 (buffer-file-name (marker-buffer org-clock-marker))
1050 org-clock-heading)))
1052 (org-startup-folded nil)
1053 (org-inhibit-startup t)
1054 org-time-was-given org-end-time-was-given x
1055 prompt completions char time pos default histvar)
1057 (setq org-store-link-plist
1058 (plist-put org-store-link-plist :annotation v-a)
1059 org-store-link-plist
1060 (plist-put org-store-link-plist :initial v-i))
1062 (unless template (setq template "") (message "No template") (ding)
1063 (sit-for 1))
1064 (save-window-excursion
1065 (delete-other-windows)
1066 (switch-to-buffer (get-buffer-create "*Capture*"))
1067 (erase-buffer)
1068 (insert template)
1069 (goto-char (point-min))
1070 (org-capture-steal-local-variables buffer)
1071 (setq buffer-file-name nil)
1072 ;; Simple %-escapes
1073 (while (re-search-forward "%\\([tTuUaiAcxkKI]\\)" nil t)
1074 (unless (org-capture-escaped-%)
1075 (when (and initial (equal (match-string 0) "%i"))
1076 (save-match-data
1077 (let* ((lead (buffer-substring
1078 (point-at-bol) (match-beginning 0))))
1079 (setq v-i (mapconcat 'identity
1080 (org-split-string initial "\n")
1081 (concat "\n" lead))))))
1082 (replace-match
1083 (or (eval (intern (concat "v-" (match-string 1)))) "")
1084 t t)))
1086 ;; %[] Insert contents of a file.
1087 (goto-char (point-min))
1088 (while (re-search-forward "%\\[\\(.+\\)\\]" nil t)
1089 (unless (org-capture-escaped-%)
1090 (let ((start (match-beginning 0))
1091 (end (match-end 0))
1092 (filename (expand-file-name (match-string 1))))
1093 (goto-char start)
1094 (delete-region start end)
1095 (condition-case error
1096 (insert-file-contents filename)
1097 (error (insert (format "%%![Couldn't insert %s: %s]"
1098 filename error)))))))
1099 ;; %() embedded elisp
1100 (goto-char (point-min))
1101 (while (re-search-forward "%\\((.+)\\)" nil t)
1102 (unless (org-capture-escaped-%)
1103 (goto-char (match-beginning 0))
1104 (let ((template-start (point)))
1105 (forward-char 1)
1106 (let ((result
1107 (condition-case error
1108 (eval (read (current-buffer)))
1109 (error (format "%%![Error: %s]" error)))))
1110 (delete-region template-start (point))
1111 (insert result)))))
1113 ;; From the property list
1114 (when plist-p
1115 (goto-char (point-min))
1116 (while (re-search-forward "%\\(:[-a-zA-Z]+\\)" nil t)
1117 (unless (org-capture-escaped-%)
1118 (and (setq x (or (plist-get org-store-link-plist
1119 (intern (match-string 1))) ""))
1120 (replace-match x t t)))))
1122 ;; Turn on org-mode in temp buffer, set local variables
1123 ;; This is to support completion in interactive prompts
1124 (let ((org-inhibit-startup t)) (org-mode))
1125 ;; Interactive template entries
1126 (goto-char (point-min))
1127 (while (re-search-forward "%^\\({\\([^}]*\\)}\\)?\\([gGtTuUCLp]\\)?"
1128 nil t)
1129 (unless (org-capture-escaped-%)
1130 (setq char (if (match-end 3) (match-string 3))
1131 prompt (if (match-end 2) (match-string 2)))
1132 (goto-char (match-beginning 0))
1133 (replace-match "")
1134 (setq completions nil default nil)
1135 (when prompt
1136 (setq completions (org-split-string prompt "|")
1137 prompt (pop completions)
1138 default (car completions)
1139 histvar (intern (concat
1140 "org-capture-template-prompt-history::"
1141 (or prompt "")))
1142 completions (mapcar 'list completions)))
1143 (cond
1144 ((member char '("G" "g"))
1145 (let* ((org-last-tags-completion-table
1146 (org-global-tags-completion-table
1147 (if (equal char "G")
1148 (org-agenda-files)
1149 (and file (list file)))))
1150 (org-add-colon-after-tag-completion t)
1151 (ins (org-icompleting-read
1152 (if prompt (concat prompt ": ") "Tags: ")
1153 'org-tags-completion-function nil nil nil
1154 'org-tags-history)))
1155 (setq ins (mapconcat 'identity
1156 (org-split-string
1157 ins (org-re "[^[:alnum:]_@]+"))
1158 ":"))
1159 (when (string-match "\\S-" ins)
1160 (or (equal (char-before) ?:) (insert ":"))
1161 (insert ins)
1162 (or (equal (char-after) ?:) (insert ":")))))
1163 ((equal char "C")
1164 (cond ((= (length clipboards) 1) (insert (car clipboards)))
1165 ((> (length clipboards) 1)
1166 (insert (read-string "Clipboard/kill value: "
1167 (car clipboards) '(clipboards . 1)
1168 (car clipboards))))))
1169 ((equal char "L")
1170 (cond ((= (length clipboards) 1)
1171 (org-insert-link 0 (car clipboards)))
1172 ((> (length clipboards) 1)
1173 (org-insert-link 0 (read-string "Clipboard/kill value: "
1174 (car clipboards)
1175 '(clipboards . 1)
1176 (car clipboards))))))
1177 ((equal char "p")
1178 (let*
1179 ((prop (org-substring-no-properties prompt))
1180 (pall (concat prop "_ALL"))
1181 (allowed
1182 (with-current-buffer
1183 (get-buffer (file-name-nondirectory file))
1184 (or (cdr (assoc pall org-file-properties))
1185 (cdr (assoc pall org-global-properties))
1186 (cdr (assoc pall org-global-properties-fixed)))))
1187 (existing (with-current-buffer
1188 (get-buffer (file-name-nondirectory file))
1189 (mapcar 'list (org-property-values prop))))
1190 (propprompt (concat "Value for " prop ": "))
1191 (val (if allowed
1192 (org-completing-read
1193 propprompt
1194 (mapcar 'list (org-split-string allowed
1195 "[ \t]+"))
1196 nil 'req-match)
1197 (org-completing-read-no-i propprompt
1198 existing nil nil
1199 "" nil ""))))
1200 (org-set-property prop val)))
1201 (char
1202 ;; These are the date/time related ones
1203 (setq org-time-was-given (equal (upcase char) char))
1204 (setq time (org-read-date (equal (upcase char) char) t nil
1205 prompt))
1206 (if (equal (upcase char) char) (setq org-time-was-given t))
1207 (org-insert-time-stamp time org-time-was-given
1208 (member char '("u" "U"))
1209 nil nil (list org-end-time-was-given)))
1211 (let (org-completion-use-ido)
1212 (insert (org-completing-read-no-i
1213 (concat (if prompt prompt "Enter string")
1214 (if default (concat " [" default "]"))
1215 ": ")
1216 completions nil nil nil histvar default)))))))
1217 ;; Make sure there are no empty lines before the text, and that
1218 ;; it ends with a newline character
1219 (goto-char (point-min))
1220 (while (looking-at "[ \t]*\n") (replace-match ""))
1221 (if (re-search-forward "[ \t\n]*\\'" nil t) (replace-match "\n"))
1222 ;; Return the expanded tempate and kill the temporary buffer
1223 (untabify (point-min) (point-max))
1224 (set-buffer-modified-p nil)
1225 (prog1 (buffer-string) (kill-buffer (current-buffer))))))
1227 (defun org-capture-escaped-% ()
1228 "Check if % was escaped - if yes, unescape it now."
1229 (if (equal (char-before (match-beginning 0)) ?\\)
1230 (progn
1231 (delete-region (1- (match-beginning 0)) (match-beginning 0))
1233 nil))
1235 ;;;###autoload
1236 (defun org-capture-import-remember-templates ()
1237 "Set org-capture-templates to be similar to `org-remember-templates'."
1238 (interactive)
1239 (when (and (yes-or-no-p
1240 "Import old remember templates into org-capture-templates? ")
1241 (yes-or-no-p
1242 "Note that this will remove any templates currently defined in `org-capture-templates'. Do you still want to go ahead? "))
1243 (require 'org-remember)
1244 (setq org-capture-templates
1245 (mapcar
1246 (lambda (entry)
1247 (let ((desc (car entry))
1248 (key (char-to-string (nth 1 entry)))
1249 (template (nth 2 entry))
1250 (file (or (nth 3 entry) org-default-notes-file))
1251 (position (or (nth 4 entry) org-remember-default-headline))
1252 (type 'entry)
1253 (prepend org-reverse-note-order)
1254 immediate target)
1255 (cond
1256 ((member position '(top bottom))
1257 (setq target (list 'file file)
1258 prepend (eq position 'top)))
1259 ((eq position 'date-tree)
1260 (setq target (list 'file+datetree file)
1261 prepend nil))
1262 (t (setq target (list 'file+headline file position))))
1264 (when (string-match "%!" template)
1265 (setq template (replace-match "" t t template)
1266 immediate t))
1268 (append (list key desc type target template)
1269 (if prepend '(:prepend t))
1270 (if immediate '(:immediate-finish t)))))
1272 org-remember-templates))))
1274 (provide 'org-capture)
1276 ;; arch-tag: 986bf41b-8ada-4e28-bf20-e8388a7205a0
1278 ;;; org-capture.el ends here