Capture: Put final touched to file+regexp & file+function targets
[org-mode/org-tableheadings.git] / lisp / org-capture.el
blobafabb0ae1d9dcbcbc0542ce130f7cf29ad43b1fd
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) 'clock)
597 (if (and (markerp org-clock-hd-marker)
598 (marker-buffer org-clock-hd-marker))
599 (progn (set-buffer (marker-buffer org-clock-hd-marker))
600 (goto-char org-clock-hd-marker))
601 (error "No running clock that could be used as capture target")))
603 (t (error "Invalid capture target specification")))
605 (org-capture-put :buffer (current-buffer) :pos (point)
606 :target-entry-p target-entry-p))))
608 (defun org-capture-target-buffer (file)
609 "Get a buffer for FILE."
610 (or (org-find-base-buffer-visiting file)
611 (find-file-noselect (expand-file-name file org-directory))))
613 (defun org-capture-steal-local-variables (buffer)
614 "Install Org-mode local variables"
615 (mapc (lambda (v)
616 (ignore-errors (org-set-local (car v) (cdr v))))
617 (buffer-local-variables buffer)))
619 (defun org-capture-place-template ()
620 "Insert the template at the target location, and display the buffer."
621 (org-capture-put :return-to-wconf (current-window-configuration))
622 (delete-other-windows)
623 (org-switch-to-buffer-other-window
624 (org-capture-get-indirect-buffer (org-capture-get :buffer) "CAPTURE"))
625 (show-all)
626 (goto-char (org-capture-get :pos))
627 (org-set-local 'org-capture-target-marker
628 (move-marker (make-marker) (point)))
629 (let* ((template (org-capture-get :template))
630 (type (org-capture-get :type)))
631 (case type
632 ((nil entry) (org-capture-place-entry))
633 (table-line (org-capture-place-table-line))
634 (plain (org-capture-place-plain-text))
635 (item (org-capture-place-item))))
636 (org-capture-mode 1)
637 (org-set-local 'org-capture-current-plist org-capture-plist))
639 (defun org-capture-place-entry ()
640 "Place the template as a new Org entry."
641 (let* ((txt (org-capture-get :template))
642 (reversed (org-capture-get :prepend))
643 (target-entry-p (org-capture-get :target-entry-p))
644 level beg end)
645 (cond
646 ((org-capture-get :exact-position)
647 (goto-char (org-capture-get :exact-position)))
648 ((not target-entry-p)
649 ;; Insert as top-level entry, either at beginning or at end of file
650 (setq level 1)
651 (if reversed
652 (progn (goto-char (point-min))
653 (outline-next-heading))
654 (goto-char (point-max))
655 (or (bolp) (insert "\n"))))
657 ;; Insert as a child of the current entry
658 (and (looking-at "\\*+")
659 (setq level (- (match-end 0) (match-beginning 0))))
660 (setq level (org-get-valid-level (or level 1) 1))
661 (if reversed
662 (progn
663 (outline-next-heading)
664 (or (bolp) (insert "\n")))
665 (org-end-of-subtree t t)
666 (or (bolp) (insert "\n")))))
667 (org-capture-empty-lines-before)
668 (setq beg (point))
669 (org-paste-subtree level txt 'for-yank)
670 (org-capture-empty-lines-after 1)
671 (org-capture-position-for-last-stored beg)
672 (outline-next-heading)
673 (setq end (point))
674 (org-capture-mark-kill-region beg (1- end))
675 (org-capture-narrow beg (1- end))
676 (if (re-search-forward "%\\?" end t) (replace-match ""))))
678 (defun org-capture-place-item ()
679 "Place the template as a new plain list item."
680 (let* ((txt (org-capture-get :template))
681 (target-entry-p (org-capture-get :target-entry-p))
682 (ind 0)
683 beg end)
684 (cond
685 ((org-capture-get :exact-position)
686 (goto-char (org-capture-get :exact-position)))
687 ((not target-entry-p)
688 ;; Insert as top-level entry, either at beginning or at end of file
689 (setq beg (point-min) end (point-max)))
691 (setq beg (1+ (point-at-eol))
692 end (save-excursion (outline-next-heading) (point)))))
693 (if (org-capture-get :prepend)
694 (progn
695 (goto-char beg)
696 (if (re-search-forward (concat "^" (org-item-re)) nil t)
697 (progn
698 (goto-char (match-beginning 0))
699 (setq ind (org-get-indentation)))
700 (goto-char end)
701 (setq ind 0)))
702 (goto-char end)
703 (if (re-search-backward (concat "^" (org-item-re)) nil t)
704 (progn
705 (setq ind (org-get-indentation))
706 (org-end-of-item))
707 (setq ind 0)))
708 ;; Remove common indentation
709 (setq txt (org-remove-indentation txt))
710 ;; Make sure this is indeed an item
711 (unless (string-match (concat "\\`" (org-item-re)) txt)
712 (setq txt (concat "- "
713 (mapconcat 'identity (split-string txt "\n")
714 "\n "))))
715 ;; Set the correct indentation, depending on context
716 (setq ind (make-string ind ?\ ))
717 (setq txt (concat ind
718 (mapconcat 'identity (split-string txt "\n")
719 (concat "\n" ind))
720 "\n"))
721 ;; Insert, with surrounding empty lines
722 (org-capture-empty-lines-before)
723 (setq beg (point))
724 (insert txt)
725 (or (bolp) (insert "\n"))
726 (org-capture-empty-lines-after 1)
727 (org-capture-position-for-last-stored beg)
728 (forward-char 1)
729 (setq end (point))
730 (org-capture-mark-kill-region beg (1- end))
731 (org-capture-narrow beg (1- end))
732 (if (re-search-forward "%\\?" end t) (replace-match ""))))
734 (defun org-capture-place-table-line ()
735 "Place the template as a table line."
736 (require 'org-table)
737 (let* ((txt (org-capture-get :template))
738 (target-entry-p (org-capture-get :target-entry-p))
739 (table-line-pos (org-capture-get :table-line-pos))
740 ind beg end)
741 (cond
742 ((org-capture-get :exact-position)
743 (goto-char (org-capture-get :exact-position)))
744 ((not target-entry-p)
745 ;; Table is not necessarily under a heading
746 (setq beg (point-min) end (point-max)))
748 ;; WE are at a heading, limit search to the body
749 (setq beg (1+ (point-at-eol))
750 end (save-excursion (outline-next-heading) (point)))))
751 (if (re-search-forward org-table-dataline-regexp end t)
752 (let ((b (org-table-begin)) (e (org-table-end)))
753 (goto-char e)
754 (if (looking-at "[ \t]*#\\+TBLFM:")
755 (forward-line 1))
756 (narrow-to-region b (point)))
757 (goto-char end)
758 (insert "\n| |\n|----|\n| |\n")
759 (narrow-to-region (1+ end) (point)))
760 ;; We are narrowed to the table, or to an empty line if there was no table
762 ;; Check if the template is good
763 (if (not (string-match org-table-dataline-regexp txt))
764 (setq txt "| %?Bad template |\n"))
765 (cond
766 ((and table-line-pos
767 (string-match "\\(I+\\)\\([-+][0-9]\\)" table-line-pos))
768 ;; we have a complex line specification
769 (goto-char (point-min))
770 (let ((nh (- (match-end 1) (match-beginning 1)))
771 (delta (string-to-number (match-string 2 table-line-pos)))
773 ;; The user wants a special position in the table
774 (org-table-get-specials)
775 (setq ll (ignore-errors (aref org-table-hlines nh)))
776 (unless ll (error "Invalid table line specification \"%s\""
777 table-line-pos))
778 (setq ll (+ ll delta (if (< delta 0) 0 -1)))
779 (org-goto-line ll)
780 (org-table-insert-row 'below)
781 (beginning-of-line 1)
782 (delete-region (point) (1+ (point-at-eol)))
783 (setq beg (point))
784 (insert txt)
785 (setq end (point))))
786 ((org-capture-get :prepend)
787 (goto-char (point-min))
788 (re-search-forward org-table-hline-regexp nil t)
789 (beginning-of-line 1)
790 (re-search-forward org-table-dataline-regexp nil t)
791 (beginning-of-line 1)
792 (setq beg (point))
793 (org-table-insert-row)
794 (beginning-of-line 1)
795 (delete-region (point) (1+ (point-at-eol)))
796 (insert txt)
797 (setq end (point)))
799 (goto-char (point-max))
800 (re-search-backward org-table-dataline-regexp nil t)
801 (beginning-of-line 1)
802 (org-table-insert-row 'below)
803 (beginning-of-line 1)
804 (delete-region (point) (1+ (point-at-eol)))
805 (setq beg (point))
806 (insert txt)
807 (setq end (point))))
808 (goto-char beg)
809 (org-capture-position-for-last-stored 'table-line)
810 (if (re-search-forward "%\\?" end t) (replace-match ""))
811 (org-table-align)))
813 (defun org-capture-place-plain-text ()
814 "Place the template plainly."
815 (let* ((txt (org-capture-get :template))
816 beg end)
817 (goto-char (cond
818 ((org-capture-get :exact-position))
819 ((org-capture-get :prepend) (point-min))
820 (t (point-max))))
821 (or (bolp) (newline))
822 (org-capture-empty-lines-before)
823 (setq beg (point))
824 (insert txt)
825 (org-capture-empty-lines-after 1)
826 (org-capture-position-for-last-stored beg)
827 (setq end (point))
828 (org-capture-mark-kill-region beg (1- end))
829 (org-capture-narrow beg (1- end))
830 (if (re-search-forward "%\\?" end t) (replace-match ""))))
832 (defun org-capture-mark-kill-region (beg end)
833 "Mark the region that will have to be killed when aborting capture."
834 (let ((m1 (move-marker (make-marker) beg))
835 (m2 (move-marker (make-marker) end)))
836 (org-capture-put :begin-marker m1)
837 (org-capture-put :end-marker m2)))
839 (defun org-capture-position-for-last-stored (where)
840 "Memorize the position that should later become the position of last capture."
841 (cond
842 ((integerp where)
843 (org-capture-put :position-for-last-stored
844 (move-marker (make-marker) where
845 (or (buffer-base-buffer (current-buffer))
846 (current-buffer)))))
847 ((eq where 'table-line)
848 (org-capture-put :position-for-last-stored
849 (list 'table-line
850 (org-table-current-dline))))
851 (t (error "This should not happen"))))
853 (defun org-capture-bookmark-last-stored-position ()
854 "Bookmark the last-captured position."
855 (let* ((where (org-capture-get :position-for-last-stored 'local))
856 (pos (cond
857 ((markerp where)
858 (prog1 (marker-position where)
859 (move-marker where nil)))
860 ((and (listp where) (eq (car where) 'table-line))
861 (if (org-at-table-p)
862 (save-excursion
863 (org-table-goto-line (nth 1 where))
864 (point-at-bol))
865 (point))))))
866 (with-current-buffer (buffer-base-buffer (current-buffer))
867 (save-excursion
868 (save-restriction
869 (widen)
870 (goto-char pos)
871 (bookmark-set "org-capture-last-stored")
872 (move-marker org-capture-last-stored-marker (point)))))))
874 (defun org-capture-narrow (beg end)
875 "Narrow, unless configuraion says not to narrow."
876 (unless (org-capture-get :unnarrowed)
877 (narrow-to-region beg end)
878 (goto-char beg)))
880 (defun org-capture-empty-lines-before (&optional n)
881 "Arrange for the correct number of empty lines before the insertion point.
882 Point will be after the empty lines, so insertion can direcetly be done."
883 (setq n (or n (org-capture-get :empty-lines) 0))
884 (let ((pos (point)))
885 (org-back-over-empty-lines)
886 (delete-region (point) pos)
887 (newline n)))
889 (defun org-capture-empty-lines-after (&optional n)
890 "Arrange for the correct number of empty lines after the inserted string.
891 Point will remain at the first line after the inserted text."
892 (setq n (or n (org-capture-get :empty-lines) 0))
893 (org-back-over-empty-lines)
894 (while (looking-at "[ \t]*\n") (replace-match ""))
895 (let ((pos (point)))
896 (newline n)
897 (goto-char pos)))
899 (defvar org-clock-marker) ; Defined in org.el
900 ;;;###autoload
901 (defun org-capture-insert-template-here ()
902 (let* ((template (org-capture-get :template))
903 (type (org-capture-get :type))
904 beg end pp)
905 (or (bolp) (newline))
906 (setq beg (point))
907 (cond
908 ((and (eq type 'entry) (org-mode-p))
909 (org-paste-subtree nil template t))
910 ((and (memq type '(item checkitem))
911 (org-mode-p)
912 (save-excursion (skip-chars-backward " \t\n")
913 (setq pp (point))
914 (org-in-item-p)))
915 (goto-char pp)
916 (org-insert-item)
917 (skip-chars-backward " ")
918 (skip-chars-backward "-+*0123456789).")
919 (delete-region (point) (point-at-eol))
920 (setq beg (point))
921 (org-remove-indentation template)
922 (insert template)
923 (org-capture-empty-lines-after)
924 (goto-char beg)
925 (org-maybe-renumber-ordered-list)
926 (org-end-of-item)
927 (setq end (point)))
928 (t (insert template)))
929 (setq end (point))
930 (goto-char beg)
931 (if (re-search-forward "%\\?" end t)
932 (replace-match ""))))
934 (defun org-capture-set-plist (entry)
935 "Initialize the property list from the template definition."
936 (setq org-capture-plist (copy-sequence (nthcdr 5 entry)))
937 (org-capture-put :key (car entry) :description (nth 1 entry)
938 :target (nth 3 entry))
939 (let ((txt (nth 4 entry)) (type (or (nth 2 entry) 'entry)))
940 (when (or (not txt) (not (string-match "\\S-" txt)))
941 ;; The template may be empty or omitted for special types.
942 ;; Here we insert the default templates for such cases.
943 (cond
944 ((eq type 'item) (setq txt "- %?"))
945 ((eq type 'checkitem) (setq txt "- [ ] %?"))
946 ((eq type 'table-line) (setq txt "| %? |"))
947 ((member type '(nil entry)) (setq txt "* %?\n %a"))))
948 (org-capture-put :template txt :type type)))
950 (defun org-capture-goto-target (&optional template-key)
951 "Go to the target location of a capture template.
952 The user is queried for the template."
953 (interactive)
954 (let* (org-select-template-temp-major-mode
955 (entry (org-capture-select-template template-key)))
956 (unless entry
957 (error "No capture emplate selected"))
958 (org-capture-set-plist entry)
959 (org-capture-set-target-location)
960 (switch-to-buffer (org-capture-get :buffer))
961 (goto-char (org-capture-get :pos))))
963 (defun org-capture-get-indirect-buffer (&optional buffer prefix)
964 "Make an indirect buffer for a capture process.
965 Use PREFIX as a prefix for the name of the indirect buffer."
966 (setq buffer (or buffer (current-buffer)))
967 (let ((n 1) (base (buffer-name buffer)) bname)
968 (setq bname (concat prefix "-" base))
969 (while (buffer-live-p (get-buffer bname))
970 (setq bname (concat prefix "-" (number-to-string (incf n)) "-" base)))
971 (condition-case nil
972 (make-indirect-buffer buffer bname 'clone)
973 (error (make-indirect-buffer buffer bname)))))
976 ;;; The template code
978 (defun org-capture-select-template (&optional keys)
979 "Select a capture template.
980 Lisp programs can force the template by setting KEYS to a string."
981 (when org-capture-templates
982 (if keys
983 (or (assoc keys org-capture-templates)
984 (error "No capture template referred to by \"%s\" keys" keys))
985 (if (= 1 (length org-capture-templates))
986 (car org-capture-templates)
987 (org-mks org-capture-templates
988 "Select a capture template\n========================="
989 "Template key: "
990 '(("C" "Customize org-capture-templates")
991 ("q" "Abort")))))))
993 (defun org-capture-fill-template (&optional template initial annotation)
994 "Fill a template and return the filled template as a string.
995 The template may still contain \"%?\" for cursor positioning."
996 (setq template (or template (org-capture-get :template)))
997 (when (stringp initial)
998 (setq initial (org-no-properties initial))
999 (remove-text-properties 0 (length initial) '(read-only t) initial))
1000 (let* ((buffer (org-capture-get :buffer))
1001 (file (buffer-file-name (or (buffer-base-buffer buffer) buffer)))
1002 (ct (org-capture-get :default-time))
1003 (dct (decode-time ct))
1004 (ct1
1005 (if (< (nth 2 dct) org-extend-today-until)
1006 (encode-time 0 59 23 (1- (nth 3 dct)) (nth 4 dct) (nth 5 dct))
1007 ct))
1008 (plist-p (if org-store-link-plist t nil))
1009 (v-c (and (> (length kill-ring) 0) (current-kill 0)))
1010 (v-x (or (org-get-x-clipboard 'PRIMARY)
1011 (org-get-x-clipboard 'CLIPBOARD)
1012 (org-get-x-clipboard 'SECONDARY)))
1013 (v-t (format-time-string (car org-time-stamp-formats) ct))
1014 (v-T (format-time-string (cdr org-time-stamp-formats) ct))
1015 (v-u (concat "[" (substring v-t 1 -1) "]"))
1016 (v-U (concat "[" (substring v-T 1 -1) "]"))
1017 ;; `initial' and `annotation' might habe been passed.
1018 ;; But if the property list has them, we prefer those values
1019 (v-i (or (plist-get org-store-link-plist :initial)
1020 initial
1021 (org-capture-get :initial)
1022 ""))
1023 (v-a (or (plist-get org-store-link-plist :annotation)
1024 annotation
1025 (org-capture-get :annotation)
1026 ""))
1027 ;; Is the link empty? Then we do not want it...
1028 (v-a (if (equal v-a "[[]]") "" v-a))
1029 (clipboards (remove nil (list v-i
1030 (org-get-x-clipboard 'PRIMARY)
1031 (org-get-x-clipboard 'CLIPBOARD)
1032 (org-get-x-clipboard 'SECONDARY)
1033 v-c)))
1034 (v-A (if (and v-a
1035 (string-match
1036 "\\[\\(\\[.*?\\]\\)\\(\\[.*?\\]\\)?\\]" v-a))
1037 (replace-match "[\\1[%^{Link description}]]" nil nil v-a)
1038 v-a))
1039 (v-n user-full-name)
1040 (v-k (if (marker-buffer org-clock-marker)
1041 (org-substring-no-properties org-clock-heading)))
1042 (v-K (if (marker-buffer org-clock-marker)
1043 (org-make-link-string
1044 (buffer-file-name (marker-buffer org-clock-marker))
1045 org-clock-heading)))
1047 (org-startup-folded nil)
1048 (org-inhibit-startup t)
1049 org-time-was-given org-end-time-was-given x
1050 prompt completions char time pos default histvar)
1052 (setq org-store-link-plist
1053 (plist-put org-store-link-plist :annotation v-a)
1054 org-store-link-plist
1055 (plist-put org-store-link-plist :initial v-i))
1057 (unless template (setq template "") (message "No template") (ding)
1058 (sit-for 1))
1059 (save-window-excursion
1060 (delete-other-windows)
1061 (switch-to-buffer (get-buffer-create "*Capture*"))
1062 (erase-buffer)
1063 (insert template)
1064 (goto-char (point-min))
1065 (org-capture-steal-local-variables buffer)
1066 (setq buffer-file-name nil)
1067 ;; Simple %-escapes
1068 (while (re-search-forward "%\\([tTuUaiAcxkKI]\\)" nil t)
1069 (unless (org-capture-escaped-%)
1070 (when (and initial (equal (match-string 0) "%i"))
1071 (save-match-data
1072 (let* ((lead (buffer-substring
1073 (point-at-bol) (match-beginning 0))))
1074 (setq v-i (mapconcat 'identity
1075 (org-split-string initial "\n")
1076 (concat "\n" lead))))))
1077 (replace-match
1078 (or (eval (intern (concat "v-" (match-string 1)))) "")
1079 t t)))
1081 ;; %[] Insert contents of a file.
1082 (goto-char (point-min))
1083 (while (re-search-forward "%\\[\\(.+\\)\\]" nil t)
1084 (unless (org-capture-escaped-%)
1085 (let ((start (match-beginning 0))
1086 (end (match-end 0))
1087 (filename (expand-file-name (match-string 1))))
1088 (goto-char start)
1089 (delete-region start end)
1090 (condition-case error
1091 (insert-file-contents filename)
1092 (error (insert (format "%%![Couldn't insert %s: %s]"
1093 filename error)))))))
1094 ;; %() embedded elisp
1095 (goto-char (point-min))
1096 (while (re-search-forward "%\\((.+)\\)" nil t)
1097 (unless (org-capture-escaped-%)
1098 (goto-char (match-beginning 0))
1099 (let ((template-start (point)))
1100 (forward-char 1)
1101 (let ((result
1102 (condition-case error
1103 (eval (read (current-buffer)))
1104 (error (format "%%![Error: %s]" error)))))
1105 (delete-region template-start (point))
1106 (insert result)))))
1108 ;; From the property list
1109 (when plist-p
1110 (goto-char (point-min))
1111 (while (re-search-forward "%\\(:[-a-zA-Z]+\\)" nil t)
1112 (unless (org-capture-escaped-%)
1113 (and (setq x (or (plist-get org-store-link-plist
1114 (intern (match-string 1))) ""))
1115 (replace-match x t t)))))
1117 ;; Turn on org-mode in temp buffer, set local variables
1118 ;; This is to support completion in interactive prompts
1119 (let ((org-inhibit-startup t)) (org-mode))
1120 ;; Interactive template entries
1121 (goto-char (point-min))
1122 (while (re-search-forward "%^\\({\\([^}]*\\)}\\)?\\([gGtTuUCLp]\\)?"
1123 nil t)
1124 (unless (org-capture-escaped-%)
1125 (setq char (if (match-end 3) (match-string 3))
1126 prompt (if (match-end 2) (match-string 2)))
1127 (goto-char (match-beginning 0))
1128 (replace-match "")
1129 (setq completions nil default nil)
1130 (when prompt
1131 (setq completions (org-split-string prompt "|")
1132 prompt (pop completions)
1133 default (car completions)
1134 histvar (intern (concat
1135 "org-capture-template-prompt-history::"
1136 (or prompt "")))
1137 completions (mapcar 'list completions)))
1138 (cond
1139 ((member char '("G" "g"))
1140 (let* ((org-last-tags-completion-table
1141 (org-global-tags-completion-table
1142 (if (equal char "G")
1143 (org-agenda-files)
1144 (and file (list file)))))
1145 (org-add-colon-after-tag-completion t)
1146 (ins (org-icompleting-read
1147 (if prompt (concat prompt ": ") "Tags: ")
1148 'org-tags-completion-function nil nil nil
1149 'org-tags-history)))
1150 (setq ins (mapconcat 'identity
1151 (org-split-string
1152 ins (org-re "[^[:alnum:]_@]+"))
1153 ":"))
1154 (when (string-match "\\S-" ins)
1155 (or (equal (char-before) ?:) (insert ":"))
1156 (insert ins)
1157 (or (equal (char-after) ?:) (insert ":")))))
1158 ((equal char "C")
1159 (cond ((= (length clipboards) 1) (insert (car clipboards)))
1160 ((> (length clipboards) 1)
1161 (insert (read-string "Clipboard/kill value: "
1162 (car clipboards) '(clipboards . 1)
1163 (car clipboards))))))
1164 ((equal char "L")
1165 (cond ((= (length clipboards) 1)
1166 (org-insert-link 0 (car clipboards)))
1167 ((> (length clipboards) 1)
1168 (org-insert-link 0 (read-string "Clipboard/kill value: "
1169 (car clipboards)
1170 '(clipboards . 1)
1171 (car clipboards))))))
1172 ((equal char "p")
1173 (let*
1174 ((prop (org-substring-no-properties prompt))
1175 (pall (concat prop "_ALL"))
1176 (allowed
1177 (with-current-buffer
1178 (get-buffer (file-name-nondirectory file))
1179 (or (cdr (assoc pall org-file-properties))
1180 (cdr (assoc pall org-global-properties))
1181 (cdr (assoc pall org-global-properties-fixed)))))
1182 (existing (with-current-buffer
1183 (get-buffer (file-name-nondirectory file))
1184 (mapcar 'list (org-property-values prop))))
1185 (propprompt (concat "Value for " prop ": "))
1186 (val (if allowed
1187 (org-completing-read
1188 propprompt
1189 (mapcar 'list (org-split-string allowed
1190 "[ \t]+"))
1191 nil 'req-match)
1192 (org-completing-read-no-i propprompt
1193 existing nil nil
1194 "" nil ""))))
1195 (org-set-property prop val)))
1196 (char
1197 ;; These are the date/time related ones
1198 (setq org-time-was-given (equal (upcase char) char))
1199 (setq time (org-read-date (equal (upcase char) char) t nil
1200 prompt))
1201 (if (equal (upcase char) char) (setq org-time-was-given t))
1202 (org-insert-time-stamp time org-time-was-given
1203 (member char '("u" "U"))
1204 nil nil (list org-end-time-was-given)))
1206 (let (org-completion-use-ido)
1207 (insert (org-completing-read-no-i
1208 (concat (if prompt prompt "Enter string")
1209 (if default (concat " [" default "]"))
1210 ": ")
1211 completions nil nil nil histvar default)))))))
1212 ;; Make sure there are no empty lines before the text, and that
1213 ;; it ends with a newline character
1214 (goto-char (point-min))
1215 (while (looking-at "[ \t]*\n") (replace-match ""))
1216 (if (re-search-forward "[ \t\n]*\\'" nil t) (replace-match "\n"))
1217 ;; Return the expanded tempate and kill the temporary buffer
1218 (untabify (point-min) (point-max))
1219 (set-buffer-modified-p nil)
1220 (prog1 (buffer-string) (kill-buffer (current-buffer))))))
1222 (defun org-capture-escaped-% ()
1223 "Check if % was escaped - if yes, unescape it now."
1224 (if (equal (char-before (match-beginning 0)) ?\\)
1225 (progn
1226 (delete-region (1- (match-beginning 0)) (match-beginning 0))
1228 nil))
1230 ;;;###autoload
1231 (defun org-capture-import-remember-templates ()
1232 "Set org-capture-templates to be similar to `org-remember-templates'."
1233 (interactive)
1234 (when (and (yes-or-no-p
1235 "Import old remember templates into org-capture-templates? ")
1236 (yes-or-no-p
1237 "Note that this will remove any templates currently defined in `org-capture-templates'. Do you still want to go ahead? "))
1238 (require 'org-remember)
1239 (setq org-capture-templates
1240 (mapcar
1241 (lambda (entry)
1242 (let ((desc (car entry))
1243 (key (char-to-string (nth 1 entry)))
1244 (template (nth 2 entry))
1245 (file (or (nth 3 entry) org-default-notes-file))
1246 (position (or (nth 4 entry) org-remember-default-headline))
1247 (type 'entry)
1248 (prepend org-reverse-note-order)
1249 immediate target)
1250 (cond
1251 ((member position '(top bottom))
1252 (setq target (list 'file file)
1253 prepend (eq position 'top)))
1254 ((eq position 'date-tree)
1255 (setq target (list 'file+datetree file)
1256 prepend nil))
1257 (t (setq target (list 'file+headline file position))))
1259 (when (string-match "%!" template)
1260 (setq template (replace-match "" t t template)
1261 immediate t))
1263 (append (list key desc type target template)
1264 (if prepend '(:prepend t))
1265 (if immediate '(:immediate-finish t)))))
1267 org-remember-templates))))
1269 (provide 'org-capture)
1271 ;; arch-tag: 986bf41b-8ada-4e28-bf20-e8388a7205a0
1273 ;;; org-capture.el ends here