org-remember.el 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. ;;; org-remember.el --- Fast note taking in Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 6.36trans
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the system to take fast notes with Org-mode.
  25. ;; This system is used together with John Wiegley's `remember.el'.
  26. ;;; Code:
  27. (eval-when-compile
  28. (require 'cl))
  29. (require 'org)
  30. (require 'org-datetree)
  31. (declare-function remember-mode "remember" ())
  32. (declare-function remember "remember" (&optional initial))
  33. (declare-function remember-buffer-desc "remember" ())
  34. (declare-function remember-finalize "remember" ())
  35. (defvar remember-save-after-remembering)
  36. (defvar remember-register)
  37. (defvar remember-buffer)
  38. (defvar remember-handler-functions)
  39. (defvar remember-annotation-functions)
  40. (defvar org-clock-heading)
  41. (defvar org-clock-heading-for-remember)
  42. (defgroup org-remember nil
  43. "Options concerning interaction with remember.el."
  44. :tag "Org Remember"
  45. :group 'org)
  46. (defcustom org-remember-store-without-prompt t
  47. "Non-nil means `C-c C-c' stores remember note without further prompts.
  48. It then uses the file and headline specified by the template or (if the
  49. template does not specify them) by the variables `org-default-notes-file'
  50. and `org-remember-default-headline'. To force prompting anyway, use
  51. `C-u C-c C-c' to file the note.
  52. When this variable is nil, `C-c C-c' gives you the prompts, and
  53. `C-u C-c C-c' triggers the fasttrack."
  54. :group 'org-remember
  55. :type 'boolean)
  56. (defcustom org-remember-interactive-interface 'refile
  57. "The interface to be used for interactive filing of remember notes.
  58. This is only used when the interactive mode for selecting a filing
  59. location is used (see the variable `org-remember-store-without-prompt').
  60. Allowed values are:
  61. outline The interface shows an outline of the relevant file
  62. and the correct heading is found by moving through
  63. the outline or by searching with incremental search.
  64. outline-path-completion Headlines in the current buffer are offered via
  65. completion.
  66. refile Use the refile interface, and offer headlines,
  67. possibly from different buffers."
  68. :group 'org-remember
  69. :type '(choice
  70. (const :tag "Refile" refile)
  71. (const :tag "Outline" outline)
  72. (const :tag "Outline-path-completion" outline-path-completion)))
  73. (defcustom org-remember-default-headline ""
  74. "The headline that should be the default location in the notes file.
  75. When filing remember notes, the cursor will start at that position.
  76. You can set this on a per-template basis with the variable
  77. `org-remember-templates'."
  78. :group 'org-remember
  79. :type 'string)
  80. (defcustom org-remember-templates nil
  81. "Templates for the creation of remember buffers.
  82. When nil, just let remember make the buffer.
  83. When non-nil, this is a list of (up to) 6-element lists. In each entry,
  84. the first element is the name of the template, which should be a single
  85. short word. The second element is a character, a unique key to select
  86. this template. The third element is the template.
  87. The fourth element is optional and can specify a destination file for
  88. remember items created with this template. The default file is given
  89. by `org-default-notes-file'. If the file name is not an absolute path,
  90. it will be interpreted relative to `org-directory'.
  91. An optional fifth element can specify the headline in that file that should
  92. be offered first when the user is asked to file the entry. The default
  93. headline is given in the variable `org-remember-default-headline'. When
  94. this element is `top' or `bottom', the note will be placed as a level-1
  95. entry at the beginning or end of the file, respectively.
  96. An optional sixth element specifies the contexts in which the template
  97. will be offered to the user. This element can be a list of major modes
  98. or a function, and the template will only be offered if `org-remember'
  99. is called from a mode in the list, or if the function returns t.
  100. Templates that specify t or nil for the context will always be added
  101. to the list of selectable templates.
  102. The template specifies the structure of the remember buffer. It should have
  103. a first line starting with a star, to act as the org-mode headline.
  104. Furthermore, the following %-escapes will be replaced with content:
  105. %^{PROMPT} Prompt the user for a string and replace this sequence with it.
  106. A default value and a completion table can be specified like this:
  107. %^{prompt|default|completion2|completion3|...}
  108. The arrow keys access a prompt-specific history.
  109. %a annotation, normally the link created with `org-store-link'
  110. %A like %a, but prompt for the description part
  111. %i Initial content, copied from the active region. If %i is
  112. indented, the entire inserted text will be indented as well.
  113. %t time stamp, date only
  114. %T time stamp with date and time
  115. %u, %U like the above, but inactive time stamps
  116. %^t like %t, but prompt for date. Similarly %^T, %^u, %^U.
  117. You may define a prompt like %^{Please specify birthday}t
  118. %n user name (taken from `user-full-name')
  119. %c current kill ring head
  120. %x content of the X clipboard
  121. %:keyword specific information for certain link types, see below
  122. %^C interactive selection of which kill or clip to use
  123. %^L like %^C, but insert as link
  124. %k title of the currently clocked task
  125. %K link to the currently clocked task
  126. %^g prompt for tags, completing tags in the target file
  127. %^G prompt for tags, completing all tags in all agenda files
  128. %^{PROP}p Prompt the user for a value for property PROP
  129. %[PATHNAME] insert the contents of the file given by PATHNAME
  130. %(SEXP) evaluate elisp `(SEXP)' and replace with the result
  131. %! store this note immediately after completing the template
  132. (skipping the `C-c C-c' that normally triggers storing)
  133. %& jump to target location immediately after storing note
  134. %? After completing the template, position cursor here.
  135. Apart from these general escapes, you can access information specific to the
  136. link type that is created. For example, calling `remember' in emails or gnus
  137. will record the author and the subject of the message, which you can access
  138. with %:author and %:subject, respectively. Here is a complete list of what
  139. is recorded for each link type.
  140. Link type | Available information
  141. -------------------+------------------------------------------------------
  142. bbdb | %:type %:name %:company
  143. vm, wl, mh, rmail | %:type %:subject %:message-id
  144. | %:from %:fromname %:fromaddress
  145. | %:to %:toname %:toaddress
  146. | %:fromto (either \"to NAME\" or \"from NAME\")
  147. gnus | %:group, for messages also all email fields
  148. w3, w3m | %:type %:url
  149. info | %:type %:file %:node
  150. calendar | %:type %:date"
  151. :group 'org-remember
  152. :get (lambda (var) ; Make sure all entries have at least 5 elements
  153. (mapcar (lambda (x)
  154. (if (not (stringp (car x))) (setq x (cons "" x)))
  155. (cond ((= (length x) 4) (append x '(nil)))
  156. ((= (length x) 3) (append x '(nil nil)))
  157. (t x)))
  158. (default-value var)))
  159. :type '(repeat
  160. :tag "enabled"
  161. (list :value ("" ?a "\n" nil nil nil)
  162. (string :tag "Name")
  163. (character :tag "Selection Key")
  164. (string :tag "Template")
  165. (choice :tag "Destination file"
  166. (file :tag "Specify")
  167. (function :tag "Function")
  168. (const :tag "Use `org-default-notes-file'" nil))
  169. (choice :tag "Destin. headline"
  170. (string :tag "Specify")
  171. (function :tag "Function")
  172. (const :tag "Use `org-remember-default-headline'" nil)
  173. (const :tag "At beginning of file" top)
  174. (const :tag "At end of file" bottom)
  175. (const :tag "In a date tree" date-tree))
  176. (choice :tag "Context"
  177. (const :tag "Use in all contexts" nil)
  178. (const :tag "Use in all contexts" t)
  179. (repeat :tag "Use only if in major mode"
  180. (symbol :tag "Major mode"))
  181. (function :tag "Perform a check against function")))))
  182. (defcustom org-remember-delete-empty-lines-at-end t
  183. "Non-nil means clean up final empty lines in remember buffer."
  184. :group 'org-remember
  185. :type 'boolean)
  186. (defcustom org-remember-before-finalize-hook nil
  187. "Hook that is run right before a remember process is finalized.
  188. The remember buffer is still current when this hook runs."
  189. :group 'org-remember
  190. :type 'hook)
  191. (defvar org-remember-mode-map (make-sparse-keymap)
  192. "Keymap for org-remember-mode, a minor mode.
  193. Use this map to set additional keybindings for when Org-mode is used
  194. for a Remember buffer.")
  195. (defvar org-remember-mode-hook nil
  196. "Hook for the minor `org-remember-mode'.")
  197. (define-minor-mode org-remember-mode
  198. "Minor mode for special key bindings in a remember buffer."
  199. nil " Rem" org-remember-mode-map
  200. (run-hooks 'org-remember-mode-hook))
  201. (define-key org-remember-mode-map "\C-c\C-c" 'org-remember-finalize)
  202. (define-key org-remember-mode-map "\C-c\C-k" 'org-remember-kill)
  203. (defcustom org-remember-clock-out-on-exit 'query
  204. "Non-nil means stop the clock when exiting a clocking remember buffer.
  205. This only applies if the clock is running in the remember buffer. If the
  206. clock is not stopped, it continues to run in the storage location.
  207. Instead of nil or t, this may also be the symbol `query' to prompt the
  208. user each time a remember buffer with a running clock is filed away. "
  209. :group 'org-remember
  210. :type '(choice
  211. (const :tag "Never" nil)
  212. (const :tag "Always" t)
  213. (const :tag "Query user" query)))
  214. (defcustom org-remember-backup-directory nil
  215. "Directory where to store all remember buffers, for backup purposes.
  216. After a remember buffer has been stored successfully, the backup file
  217. will be removed. However, if you forget to finish the remember process,
  218. the file will remain there.
  219. See also `org-remember-auto-remove-backup-files'."
  220. :group 'org-remember
  221. :type '(choice
  222. (const :tag "No backups" nil)
  223. (directory :tag "Directory")))
  224. (defcustom org-remember-auto-remove-backup-files t
  225. "Non-nil means remove remember backup files after successfully storage.
  226. When remember is finished successfully, with storing the note at the
  227. desired target, remove the backup files related to this remember process
  228. and show a message about remaining backup files, from previous, unfinished
  229. remember sessions.
  230. Backup files will only be made at all, when `org-remember-backup-directory'
  231. is set."
  232. :group 'org-remember
  233. :type 'boolean)
  234. (defcustom org-remember-warn-about-backups t
  235. "Non-nil means warn about backup files in `org-remember-backup-directory'.
  236. Set this to nil if you find that you don't need the warning.
  237. If you cancel remember calls frequently and know when they
  238. contain useful information (because you know that you made an
  239. error or emacs crashed, for example) nil is more useful. In the
  240. opposite case, the default, t, is more useful."
  241. :group 'org-remember
  242. :type 'boolean)
  243. (defvar annotation) ; from remember.el, dynamically scoped in `remember-mode'
  244. (defvar initial) ; from remember.el, dynamically scoped in `remember-mode'
  245. ;;;###autoload
  246. (defun org-remember-insinuate ()
  247. "Setup remember.el for use with Org-mode."
  248. (org-require-remember)
  249. (setq remember-annotation-functions '(org-remember-annotation))
  250. (setq remember-handler-functions '(org-remember-handler))
  251. (add-hook 'remember-mode-hook 'org-remember-apply-template))
  252. ;;;###autoload
  253. (defun org-remember-annotation ()
  254. "Return a link to the current location as an annotation for remember.el.
  255. If you are using Org-mode files as target for data storage with
  256. remember.el, then the annotations should include a link compatible with the
  257. conventions in Org-mode. This function returns such a link."
  258. (org-store-link nil))
  259. (defconst org-remember-help
  260. "Select a destination location for the note.
  261. UP/DOWN=headline TAB=cycle visibility [Q]uit RET/<left>/<right>=Store
  262. RET on headline -> Store as sublevel entry to current headline
  263. RET at beg-of-buf -> Append to file as level 2 headline
  264. <left>/<right> -> before/after current headline, same headings level")
  265. (defvar org-jump-to-target-location nil)
  266. (defvar org-remember-previous-location nil)
  267. (defvar org-remember-reference-date nil)
  268. (defvar org-force-remember-template-char) ;; dynamically scoped
  269. ;; Save the major mode of the buffer we called remember from
  270. (defvar org-select-template-temp-major-mode nil)
  271. ;; Temporary store the buffer where remember was called from
  272. (defvar org-select-template-original-buffer nil)
  273. (defun org-select-remember-template (&optional use-char)
  274. (when org-remember-templates
  275. (let* ((pre-selected-templates
  276. (mapcar
  277. (lambda (tpl)
  278. (let ((ctxt (nth 5 tpl))
  279. (mode org-select-template-temp-major-mode)
  280. (buf org-select-template-original-buffer))
  281. (and (or (not ctxt) (eq ctxt t)
  282. (and (listp ctxt) (memq mode ctxt))
  283. (and (functionp ctxt)
  284. (with-current-buffer buf
  285. ;; Protect the user-defined function from error
  286. (condition-case nil (funcall ctxt) (error nil)))))
  287. tpl)))
  288. org-remember-templates))
  289. ;; If no template at this point, add the default templates:
  290. (pre-selected-templates1
  291. (if (not (delq nil pre-selected-templates))
  292. (mapcar (lambda(x) (if (not (nth 5 x)) x))
  293. org-remember-templates)
  294. pre-selected-templates))
  295. ;; Then unconditionally add template for any contexts
  296. (pre-selected-templates2
  297. (append (mapcar (lambda(x) (if (eq (nth 5 x) t) x))
  298. org-remember-templates)
  299. (delq nil pre-selected-templates1)))
  300. (templates (mapcar (lambda (x)
  301. (if (stringp (car x))
  302. (append (list (nth 1 x) (car x)) (cddr x))
  303. (append (list (car x) "") (cdr x))))
  304. (delq nil pre-selected-templates2)))
  305. msg
  306. (char (or use-char
  307. (cond
  308. ((= (length templates) 1)
  309. (caar templates))
  310. ((and (boundp 'org-force-remember-template-char)
  311. org-force-remember-template-char)
  312. (if (stringp org-force-remember-template-char)
  313. (string-to-char org-force-remember-template-char)
  314. org-force-remember-template-char))
  315. (t
  316. (setq msg (format
  317. "Select template: %s%s"
  318. (mapconcat
  319. (lambda (x)
  320. (cond
  321. ((not (string-match "\\S-" (nth 1 x)))
  322. (format "[%c]" (car x)))
  323. ((equal (downcase (car x))
  324. (downcase (aref (nth 1 x) 0)))
  325. (format "[%c]%s" (car x)
  326. (substring (nth 1 x) 1)))
  327. (t (format "[%c]%s" (car x) (nth 1 x)))))
  328. templates " ")
  329. (if (assoc ?C templates)
  330. ""
  331. " [C]customize templates")))
  332. (let ((inhibit-quit t) char0)
  333. (while (not char0)
  334. (message msg)
  335. (setq char0 (read-char-exclusive))
  336. (when (and (not (assoc char0 templates))
  337. (not (equal char0 ?\C-g))
  338. (not (equal char0 ?C)))
  339. (message "No such template \"%c\"" char0)
  340. (ding) (sit-for 1)
  341. (setq char0 nil)))
  342. (when (equal char0 ?\C-g)
  343. (jump-to-register remember-register)
  344. (kill-buffer remember-buffer)
  345. (error "Abort"))
  346. (when (not (assoc char0 templates))
  347. (jump-to-register remember-register)
  348. (kill-buffer remember-buffer)
  349. (customize-variable 'org-remember-templates)
  350. (error "Customize templates"))
  351. char0))))))
  352. (cddr (assoc char templates)))))
  353. ;;;###autoload
  354. (defun org-remember-apply-template (&optional use-char skip-interactive)
  355. "Initialize *remember* buffer with template, invoke `org-mode'.
  356. This function should be placed into `remember-mode-hook' and in fact requires
  357. to be run from that hook to function properly."
  358. (when (and (boundp 'initial) (stringp initial))
  359. (setq initial (org-no-properties initial))
  360. (remove-text-properties 0 (length initial) '(read-only t) initial))
  361. (if org-remember-templates
  362. (let* ((entry (org-select-remember-template use-char))
  363. (ct (or org-overriding-default-time (org-current-time)))
  364. (dct (decode-time ct))
  365. (ct1
  366. (if (< (nth 2 dct) org-extend-today-until)
  367. (encode-time 0 59 23 (1- (nth 3 dct)) (nth 4 dct) (nth 5 dct))
  368. ct))
  369. (tpl (car entry))
  370. (plist-p (if org-store-link-plist t nil))
  371. (file (if (and (nth 1 entry)
  372. (or (and (stringp (nth 1 entry))
  373. (string-match "\\S-" (nth 1 entry)))
  374. (functionp (nth 1 entry))))
  375. (nth 1 entry)
  376. org-default-notes-file))
  377. (headline (nth 2 entry))
  378. (v-c (and (> (length kill-ring) 0) (current-kill 0)))
  379. (v-x (or (org-get-x-clipboard 'PRIMARY)
  380. (org-get-x-clipboard 'CLIPBOARD)
  381. (org-get-x-clipboard 'SECONDARY)))
  382. (v-t (format-time-string (car org-time-stamp-formats) ct))
  383. (v-T (format-time-string (cdr org-time-stamp-formats) ct))
  384. (v-u (concat "[" (substring v-t 1 -1) "]"))
  385. (v-U (concat "[" (substring v-T 1 -1) "]"))
  386. ;; `initial' and `annotation' are bound in `remember'.
  387. ;; But if the property list has them, we prefer those values
  388. (v-i (or (plist-get org-store-link-plist :initial)
  389. (and (boundp 'initial) initial)
  390. ""))
  391. (v-a (or (plist-get org-store-link-plist :annotation)
  392. (and (boundp 'annotation) annotation)
  393. ""))
  394. ;; Is the link empty? Then we do not want it...
  395. (v-a (if (equal v-a "[[]]") "" v-a))
  396. (clipboards (remove nil (list v-i
  397. (org-get-x-clipboard 'PRIMARY)
  398. (org-get-x-clipboard 'CLIPBOARD)
  399. (org-get-x-clipboard 'SECONDARY)
  400. v-c)))
  401. (v-A (if (and v-a
  402. (string-match "\\[\\(\\[.*?\\]\\)\\(\\[.*?\\]\\)?\\]" v-a))
  403. (replace-match "[\\1[%^{Link description}]]" nil nil v-a)
  404. v-a))
  405. (v-n user-full-name)
  406. (v-k (if (marker-buffer org-clock-marker)
  407. (org-substring-no-properties org-clock-heading)))
  408. (v-K (if (marker-buffer org-clock-marker)
  409. (org-make-link-string
  410. (buffer-file-name (marker-buffer org-clock-marker))
  411. org-clock-heading)))
  412. v-I
  413. (org-startup-folded nil)
  414. (org-inhibit-startup t)
  415. org-time-was-given org-end-time-was-given x
  416. prompt completions char time pos default histvar)
  417. (when (functionp file)
  418. (setq file (funcall file)))
  419. (when (functionp headline)
  420. (setq headline (funcall headline)))
  421. (when (and file (not (file-name-absolute-p file)))
  422. (setq file (expand-file-name file org-directory)))
  423. (setq org-store-link-plist
  424. (plist-put org-store-link-plist :annotation v-a)
  425. org-store-link-plist
  426. (plist-put org-store-link-plist :initial v-i))
  427. (unless tpl (setq tpl "") (message "No template") (ding) (sit-for 1))
  428. (erase-buffer)
  429. (insert (substitute-command-keys
  430. (format
  431. "## %s \"%s\" -> \"* %s\"
  432. ## C-u C-c C-c like C-c C-c, and immediately visit note at target location
  433. ## C-0 C-c C-c \"%s\" -> \"* %s\"
  434. ## %s to select file and header location interactively.
  435. ## C-2 C-c C-c as child (C-3: as sibling) of the currently clocked item
  436. ## To switch templates, use `\\[org-remember]'. To abort use `C-c C-k'.\n\n"
  437. (if org-remember-store-without-prompt " C-c C-c" " C-1 C-c C-c")
  438. (abbreviate-file-name (or file org-default-notes-file))
  439. (or headline "")
  440. (or (car org-remember-previous-location) "???")
  441. (or (cdr org-remember-previous-location) "???")
  442. (if org-remember-store-without-prompt "C-1 C-c C-c" " C-c C-c"))))
  443. (insert tpl)
  444. ;; %[] Insert contents of a file.
  445. (goto-char (point-min))
  446. (while (re-search-forward "%\\[\\(.+\\)\\]" nil t)
  447. (unless (org-remember-escaped-%)
  448. (let ((start (match-beginning 0))
  449. (end (match-end 0))
  450. (filename (expand-file-name (match-string 1))))
  451. (goto-char start)
  452. (delete-region start end)
  453. (condition-case error
  454. (insert-file-contents filename)
  455. (error (insert (format "%%![Couldn't insert %s: %s]"
  456. filename error)))))))
  457. ;; Simple %-escapes
  458. (goto-char (point-min))
  459. (while (re-search-forward "%\\([tTuUaiAcxkKI]\\)" nil t)
  460. (unless (org-remember-escaped-%)
  461. (when (and initial (equal (match-string 0) "%i"))
  462. (save-match-data
  463. (let* ((lead (buffer-substring
  464. (point-at-bol) (match-beginning 0))))
  465. (setq v-i (mapconcat 'identity
  466. (org-split-string initial "\n")
  467. (concat "\n" lead))))))
  468. (replace-match
  469. (or (eval (intern (concat "v-" (match-string 1)))) "")
  470. t t)))
  471. ;; %() embedded elisp
  472. (goto-char (point-min))
  473. (while (re-search-forward "%\\((.+)\\)" nil t)
  474. (unless (org-remember-escaped-%)
  475. (goto-char (match-beginning 0))
  476. (let ((template-start (point)))
  477. (forward-char 1)
  478. (let ((result
  479. (condition-case error
  480. (eval (read (current-buffer)))
  481. (error (format "%%![Error: %s]" error)))))
  482. (delete-region template-start (point))
  483. (insert result)))))
  484. ;; From the property list
  485. (when plist-p
  486. (goto-char (point-min))
  487. (while (re-search-forward "%\\(:[-a-zA-Z]+\\)" nil t)
  488. (unless (org-remember-escaped-%)
  489. (and (setq x (or (plist-get org-store-link-plist
  490. (intern (match-string 1))) ""))
  491. (replace-match x t t)))))
  492. ;; Turn on org-mode in the remember buffer, set local variables
  493. (let ((org-inhibit-startup t)) (org-mode) (org-remember-mode 1))
  494. (if (and file (string-match "\\S-" file) (not (file-directory-p file)))
  495. (org-set-local 'org-default-notes-file file))
  496. (if headline
  497. (org-set-local 'org-remember-default-headline headline))
  498. (org-set-local 'org-remember-reference-date
  499. (list (nth 4 dct) (nth 3 dct) (nth 5 dct)))
  500. ;; Interactive template entries
  501. (goto-char (point-min))
  502. (while (re-search-forward "%^\\({\\([^}]*\\)}\\)?\\([gGtTuUCLp]\\)?" nil t)
  503. (unless (org-remember-escaped-%)
  504. (setq char (if (match-end 3) (match-string 3))
  505. prompt (if (match-end 2) (match-string 2)))
  506. (goto-char (match-beginning 0))
  507. (replace-match "")
  508. (setq completions nil default nil)
  509. (when prompt
  510. (setq completions (org-split-string prompt "|")
  511. prompt (pop completions)
  512. default (car completions)
  513. histvar (intern (concat
  514. "org-remember-template-prompt-history::"
  515. (or prompt "")))
  516. completions (mapcar 'list completions)))
  517. (cond
  518. ((member char '("G" "g"))
  519. (let* ((org-last-tags-completion-table
  520. (org-global-tags-completion-table
  521. (if (equal char "G") (org-agenda-files) (and file (list file)))))
  522. (org-add-colon-after-tag-completion t)
  523. (ins (org-icompleting-read
  524. (if prompt (concat prompt ": ") "Tags: ")
  525. 'org-tags-completion-function nil nil nil
  526. 'org-tags-history)))
  527. (setq ins (mapconcat 'identity
  528. (org-split-string ins (org-re "[^[:alnum:]_@]+"))
  529. ":"))
  530. (when (string-match "\\S-" ins)
  531. (or (equal (char-before) ?:) (insert ":"))
  532. (insert ins)
  533. (or (equal (char-after) ?:) (insert ":")))))
  534. ((equal char "C")
  535. (cond ((= (length clipboards) 1) (insert (car clipboards)))
  536. ((> (length clipboards) 1)
  537. (insert (read-string "Clipboard/kill value: "
  538. (car clipboards) '(clipboards . 1)
  539. (car clipboards))))))
  540. ((equal char "L")
  541. (cond ((= (length clipboards) 1)
  542. (org-insert-link 0 (car clipboards)))
  543. ((> (length clipboards) 1)
  544. (org-insert-link 0 (read-string "Clipboard/kill value: "
  545. (car clipboards)
  546. '(clipboards . 1)
  547. (car clipboards))))))
  548. ((equal char "p")
  549. (let*
  550. ((prop (org-substring-no-properties prompt))
  551. (pall (concat prop "_ALL"))
  552. (allowed
  553. (with-current-buffer
  554. (or (find-buffer-visiting file)
  555. (find-file-noselect file))
  556. (or (cdr (assoc pall org-file-properties))
  557. (cdr (assoc pall org-global-properties))
  558. (cdr (assoc pall org-global-properties-fixed)))))
  559. (existing (with-current-buffer
  560. (or (find-buffer-visiting file)
  561. (find-file-noselect file))
  562. (mapcar 'list (org-property-values prop))))
  563. (propprompt (concat "Value for " prop ": "))
  564. (val (if allowed
  565. (org-completing-read
  566. propprompt
  567. (mapcar 'list (org-split-string allowed "[ \t]+"))
  568. nil 'req-match)
  569. (org-completing-read-no-i propprompt existing nil nil
  570. "" nil ""))))
  571. (org-set-property prop val)))
  572. (char
  573. ;; These are the date/time related ones
  574. (setq org-time-was-given (equal (upcase char) char))
  575. (setq time (org-read-date (equal (upcase char) "U") t nil
  576. prompt))
  577. (org-insert-time-stamp time org-time-was-given
  578. (member char '("u" "U"))
  579. nil nil (list org-end-time-was-given)))
  580. (t
  581. (let (org-completion-use-ido)
  582. (insert (org-without-partial-completion
  583. (org-completing-read-no-i
  584. (concat (if prompt prompt "Enter string")
  585. (if default (concat " [" default "]"))
  586. ": ")
  587. completions nil nil nil histvar default))))))))
  588. (goto-char (point-min))
  589. (if (re-search-forward "%\\?" nil t)
  590. (replace-match "")
  591. (and (re-search-forward "^[^#\n]" nil t) (backward-char 1))))
  592. (let ((org-inhibit-startup t)) (org-mode) (org-remember-mode 1)))
  593. (when (save-excursion
  594. (goto-char (point-min))
  595. (re-search-forward "%&" nil t))
  596. (replace-match "")
  597. (org-set-local 'org-jump-to-target-location t))
  598. (when org-remember-backup-directory
  599. (unless (file-directory-p org-remember-backup-directory)
  600. (make-directory org-remember-backup-directory))
  601. (org-set-local 'auto-save-file-name-transforms nil)
  602. (setq buffer-file-name
  603. (expand-file-name
  604. (format-time-string "remember-%Y-%m-%d-%H-%M-%S")
  605. org-remember-backup-directory))
  606. (save-buffer)
  607. (org-set-local 'auto-save-visited-file-name t)
  608. (auto-save-mode 1))
  609. (when (save-excursion
  610. (goto-char (point-min))
  611. (re-search-forward "%!" nil t))
  612. (replace-match "")
  613. (add-hook 'post-command-hook 'org-remember-finish-immediately 'append)))
  614. (defun org-remember-escaped-% ()
  615. (if (equal (char-before (match-beginning 0)) ?\\)
  616. (progn
  617. (delete-region (1- (match-beginning 0)) (match-beginning 0))
  618. t)
  619. nil))
  620. (defun org-remember-finish-immediately ()
  621. "File remember note immediately.
  622. This should be run in `post-command-hook' and will remove itself
  623. from that hook."
  624. (remove-hook 'post-command-hook 'org-remember-finish-immediately)
  625. (org-remember-finalize))
  626. (defun org-remember-visit-immediately ()
  627. "File remember note immediately.
  628. This should be run in `post-command-hook' and will remove itself
  629. from that hook."
  630. (org-remember '(16))
  631. (goto-char (or (text-property-any
  632. (point) (save-excursion (org-end-of-subtree t t))
  633. 'org-position-cursor t)
  634. (point)))
  635. (message "%s"
  636. (format
  637. (substitute-command-keys
  638. "Restore window configuration with \\[jump-to-register] %c")
  639. remember-register)))
  640. (defvar org-clock-marker) ; Defined in org.el
  641. (defun org-remember-finalize ()
  642. "Finalize the remember process."
  643. (interactive)
  644. (unless org-remember-mode
  645. (error "This does not seem to be a remember buffer for Org-mode"))
  646. (run-hooks 'org-remember-before-finalize-hook)
  647. (unless (fboundp 'remember-finalize)
  648. (defalias 'remember-finalize 'remember-buffer))
  649. (when (and org-clock-marker
  650. (equal (marker-buffer org-clock-marker) (current-buffer)))
  651. ;; the clock is running in this buffer.
  652. (when (and (equal (marker-buffer org-clock-marker) (current-buffer))
  653. (or (eq org-remember-clock-out-on-exit t)
  654. (and org-remember-clock-out-on-exit
  655. (y-or-n-p "The clock is running in this buffer. Clock out now? "))))
  656. (let (org-log-note-clock-out) (org-clock-out))))
  657. (when buffer-file-name
  658. (do-auto-save))
  659. (remember-finalize))
  660. (defun org-remember-kill ()
  661. "Abort the current remember process."
  662. (interactive)
  663. (let ((org-note-abort t))
  664. (org-remember-finalize)))
  665. ;;;###autoload
  666. (defun org-remember (&optional goto org-force-remember-template-char)
  667. "Call `remember'. If this is already a remember buffer, re-apply template.
  668. If there is an active region, make sure remember uses it as initial content
  669. of the remember buffer.
  670. When called interactively with a `C-u' prefix argument GOTO, don't remember
  671. anything, just go to the file/headline where the selected template usually
  672. stores its notes. With a double prefix arg `C-u C-u', go to the last
  673. note stored by remember.
  674. Lisp programs can set ORG-FORCE-REMEMBER-TEMPLATE-CHAR to a character
  675. associated with a template in `org-remember-templates'."
  676. (interactive "P")
  677. (org-require-remember)
  678. (cond
  679. ((equal goto '(4)) (org-go-to-remember-target))
  680. ((equal goto '(16)) (org-remember-goto-last-stored))
  681. (t
  682. ;; set temporary variables that will be needed in
  683. ;; `org-select-remember-template'
  684. (setq org-select-template-temp-major-mode major-mode)
  685. (setq org-select-template-original-buffer (current-buffer))
  686. (if org-remember-mode
  687. (progn
  688. (when (< (length org-remember-templates) 2)
  689. (error "No other template available"))
  690. (erase-buffer)
  691. (let ((annotation (plist-get org-store-link-plist :annotation))
  692. (initial (plist-get org-store-link-plist :initial)))
  693. (org-remember-apply-template))
  694. (message "Press C-c C-c to remember data"))
  695. (if (org-region-active-p)
  696. (org-do-remember (buffer-substring (point) (mark)))
  697. (org-do-remember))))))
  698. (defvar org-remember-last-stored-marker (make-marker)
  699. "Marker pointing to the entry most recently stored with `org-remember'.")
  700. (defun org-remember-goto-last-stored ()
  701. "Go to the location where the last remember note was stored."
  702. (interactive)
  703. (org-goto-marker-or-bmk org-remember-last-stored-marker
  704. "org-remember-last-stored")
  705. (message "This is the last note stored by remember"))
  706. (defun org-go-to-remember-target (&optional template-key)
  707. "Go to the target location of a remember template.
  708. The user is queried for the template."
  709. (interactive)
  710. (let* (org-select-template-temp-major-mode
  711. (entry (org-select-remember-template template-key))
  712. (file (nth 1 entry))
  713. (heading (nth 2 entry))
  714. visiting)
  715. (unless (and file (stringp file) (string-match "\\S-" file))
  716. (setq file org-default-notes-file))
  717. (when (and file (not (file-name-absolute-p file)))
  718. (setq file (expand-file-name file org-directory)))
  719. (unless (and heading (stringp heading) (string-match "\\S-" heading))
  720. (setq heading org-remember-default-headline))
  721. (setq visiting (org-find-base-buffer-visiting file))
  722. (if (not visiting) (find-file-noselect file))
  723. (switch-to-buffer (or visiting (get-file-buffer file)))
  724. (widen)
  725. (goto-char (point-min))
  726. (if (re-search-forward
  727. (format org-complex-heading-regexp-format (regexp-quote heading))
  728. nil t)
  729. (goto-char (match-beginning 0))
  730. (error "Target headline not found: %s" heading))))
  731. ;; FIXME (bzg): let's clean up of final empty lines happen only once
  732. ;; (see the org-remember-delete-empty-lines-at-end option below)
  733. ;;;###autoload
  734. (defun org-remember-handler ()
  735. "Store stuff from remember.el into an org file.
  736. When the template has specified a file and a headline, the entry is filed
  737. there, or in the location defined by `org-default-notes-file' and
  738. `org-remember-default-headline'.
  739. If no defaults have been defined, or if the current prefix argument
  740. is 1 (so you must use `C-1 C-c C-c' to exit remember), an interactive
  741. process is used to select the target location.
  742. When the prefix is 0 (i.e. when remember is exited with `C-0 C-c C-c'),
  743. the entry is filed to the same location as the previous note.
  744. When the prefix is 2 (i.e. when remember is exited with `C-2 C-c C-c'),
  745. the entry is filed as a subentry of the entry where the clock is
  746. currently running.
  747. When `C-u' has been used as prefix argument, the note is stored and emacs
  748. moves point to the new location of the note, so that editing can be
  749. continued there (similar to inserting \"%&\" into the template).
  750. Before storing the note, the function ensures that the text has an
  751. org-mode-style headline, i.e. a first line that starts with
  752. a \"*\". If not, a headline is constructed from the current date and
  753. some additional data.
  754. If the variable `org-adapt-indentation' is non-nil, the entire text is
  755. also indented so that it starts in the same column as the headline
  756. \(i.e. after the stars).
  757. See also the variable `org-reverse-note-order'."
  758. (when (and (equal current-prefix-arg 2)
  759. (not (marker-buffer org-clock-marker)))
  760. (error "No running clock"))
  761. (when (org-bound-and-true-p org-jump-to-target-location)
  762. (let* ((end (min (point-max) (1+ (point))))
  763. (beg (point)))
  764. (if (= end beg) (setq beg (1- beg)))
  765. (put-text-property beg end 'org-position-cursor t)))
  766. (goto-char (point-min))
  767. (while (looking-at "^[ \t]*\n\\|^##.*\n")
  768. (replace-match ""))
  769. (when org-remember-delete-empty-lines-at-end
  770. (goto-char (point-max))
  771. (beginning-of-line 1)
  772. (while (and (looking-at "[ \t]*$\\|##.*") (> (point) 1))
  773. (delete-region (1- (point)) (point-max))
  774. (beginning-of-line 1)))
  775. (catch 'quit
  776. (if org-note-abort (throw 'quit t))
  777. (let* ((visitp (org-bound-and-true-p org-jump-to-target-location))
  778. (backup-file
  779. (and buffer-file-name
  780. (equal (file-name-directory buffer-file-name)
  781. (file-name-as-directory
  782. (expand-file-name org-remember-backup-directory)))
  783. (string-match "^remember-[0-9]\\{4\\}"
  784. (file-name-nondirectory buffer-file-name))
  785. buffer-file-name))
  786. (dummy
  787. (unless (string-match "\\S-" (buffer-string))
  788. (message "Nothing to remember")
  789. (and backup-file
  790. (ignore-errors
  791. (delete-file backup-file)
  792. (delete-file (concat backup-file "~"))))
  793. (set-buffer-modified-p nil)
  794. (throw 'quit t)))
  795. (reference-date org-remember-reference-date)
  796. (previousp (and (member current-prefix-arg '((16) 0))
  797. org-remember-previous-location))
  798. (clockp (equal current-prefix-arg 2))
  799. (clocksp (equal current-prefix-arg 3))
  800. (fastp (org-xor (equal current-prefix-arg 1)
  801. org-remember-store-without-prompt))
  802. (file (cond
  803. (fastp org-default-notes-file)
  804. ((and (eq org-remember-interactive-interface 'refile)
  805. org-refile-targets)
  806. org-default-notes-file)
  807. ((not previousp)
  808. (org-get-org-file))))
  809. (heading org-remember-default-headline)
  810. (visiting (and file (org-find-base-buffer-visiting file)))
  811. (org-startup-folded nil)
  812. (org-startup-align-all-tables nil)
  813. (org-goto-start-pos 1)
  814. spos exitcmd level reversed txt text-before-node-creation)
  815. (when (equal current-prefix-arg '(4))
  816. (setq visitp t))
  817. (when previousp
  818. (setq file (car org-remember-previous-location)
  819. visiting (and file (org-find-base-buffer-visiting file))
  820. heading (cdr org-remember-previous-location)
  821. fastp t))
  822. (when (or clockp clocksp)
  823. (setq file (buffer-file-name (marker-buffer org-clock-marker))
  824. visiting (and file (org-find-base-buffer-visiting file))
  825. heading org-clock-heading-for-remember
  826. fastp t))
  827. (setq current-prefix-arg nil)
  828. ;; Modify text so that it becomes a nice subtree which can be inserted
  829. ;; into an org tree.
  830. (when org-remember-delete-empty-lines-at-end
  831. (goto-char (point-min))
  832. (if (re-search-forward "[ \t\n]+\\'" nil t)
  833. ;; remove empty lines at end
  834. (replace-match "")))
  835. (goto-char (point-min))
  836. (setq text-before-node-creation (buffer-string))
  837. (unless (looking-at org-outline-regexp)
  838. ;; add a headline
  839. (insert (concat "* " (current-time-string)
  840. " (" (remember-buffer-desc) ")\n"))
  841. (backward-char 1)
  842. (when org-adapt-indentation
  843. (while (re-search-forward "^" nil t)
  844. (insert " "))))
  845. ;; Delete final empty lines
  846. (when org-remember-delete-empty-lines-at-end
  847. (goto-char (point-min))
  848. (if (re-search-forward "\n[ \t]*\n[ \t\n]*\\'" nil t)
  849. (replace-match "\n\n")
  850. (if (re-search-forward "[ \t\n]*\\'")
  851. (replace-match "\n"))))
  852. (goto-char (point-min))
  853. (setq txt (buffer-string))
  854. (org-save-markers-in-region (point-min) (point-max))
  855. (set-buffer-modified-p nil)
  856. (when (and (eq org-remember-interactive-interface 'refile)
  857. (not fastp))
  858. (org-refile nil (or visiting (find-file-noselect file)))
  859. (and visitp (run-with-idle-timer 0.01 nil 'org-remember-visit-immediately))
  860. (save-excursion
  861. (bookmark-jump "org-refile-last-stored")
  862. (bookmark-set "org-remember-last-stored")
  863. (move-marker org-remember-last-stored-marker (point)))
  864. (throw 'quit t))
  865. ;; Find the file
  866. (with-current-buffer (or visiting (find-file-noselect file))
  867. (unless (or (org-mode-p) (member heading '(top bottom)))
  868. (error "Target files for notes must be in Org-mode if not filing to top/bottom"))
  869. (save-excursion
  870. (save-restriction
  871. (widen)
  872. (setq reversed (org-notes-order-reversed-p))
  873. ;; Find the default location
  874. (when heading
  875. (cond
  876. ((not (org-mode-p))
  877. (if (eq heading 'top)
  878. (goto-char (point-min))
  879. (goto-char (point-max))
  880. (or (bolp) (newline)))
  881. (insert text-before-node-creation)
  882. (when remember-save-after-remembering
  883. (save-buffer)
  884. (if (not visiting) (kill-buffer (current-buffer))))
  885. (throw 'quit t))
  886. ((eq heading 'top)
  887. (goto-char (point-min))
  888. (or (looking-at org-outline-regexp)
  889. (re-search-forward org-outline-regexp nil t))
  890. (setq org-goto-start-pos (or (match-beginning 0) (point-min))))
  891. ((eq heading 'bottom)
  892. (goto-char (point-max))
  893. (or (bolp) (newline))
  894. (setq org-goto-start-pos (point)))
  895. ((eq heading 'date-tree)
  896. (org-datetree-find-date-create reference-date)
  897. (setq reversed nil)
  898. (setq org-goto-start-pos (point)))
  899. ((and (stringp heading) (string-match "\\S-" heading))
  900. (goto-char (point-min))
  901. (if (re-search-forward
  902. (format org-complex-heading-regexp-format
  903. (regexp-quote heading))
  904. nil t)
  905. (setq org-goto-start-pos (match-beginning 0))
  906. (when fastp
  907. (goto-char (point-max))
  908. (unless (bolp) (newline))
  909. (insert "* " heading "\n")
  910. (setq org-goto-start-pos (point-at-bol 0)))))
  911. (t (goto-char (point-min)) (setq org-goto-start-pos (point)
  912. heading 'top))))
  913. ;; Ask the User for a location, using the appropriate interface
  914. (cond
  915. ((and fastp (memq heading '(top bottom)))
  916. (setq spos org-goto-start-pos
  917. exitcmd (if (eq heading 'top) 'left nil)))
  918. (fastp (setq spos org-goto-start-pos
  919. exitcmd 'return))
  920. ((eq org-remember-interactive-interface 'outline)
  921. (setq spos (org-get-location (current-buffer)
  922. org-remember-help)
  923. exitcmd (cdr spos)
  924. spos (car spos)))
  925. ((eq org-remember-interactive-interface 'outline-path-completion)
  926. (let ((org-refile-targets '((nil . (:maxlevel . 10))))
  927. (org-refile-use-outline-path t))
  928. (setq spos (org-refile-get-location "Heading: ")
  929. exitcmd 'return
  930. spos (nth 3 spos))))
  931. (t (error "This should not happen")))
  932. (if (not spos) (throw 'quit nil)) ; return nil to show we did
  933. ; not handle this note
  934. (and visitp (run-with-idle-timer 0.01 nil 'org-remember-visit-immediately))
  935. (goto-char spos)
  936. (cond ((org-on-heading-p t)
  937. (org-back-to-heading t)
  938. (setq level (funcall outline-level))
  939. (cond
  940. ((eq exitcmd 'return)
  941. ;; sublevel of current
  942. (setq org-remember-previous-location
  943. (cons (abbreviate-file-name file)
  944. (org-get-heading 'notags)))
  945. (if reversed
  946. (outline-next-heading)
  947. (org-end-of-subtree t)
  948. (if (not (bolp))
  949. (if (looking-at "[ \t]*\n")
  950. (beginning-of-line 2)
  951. (end-of-line 1)
  952. (insert "\n"))))
  953. (org-paste-subtree (if clocksp
  954. level
  955. (org-get-valid-level level 1)) txt)
  956. (and org-auto-align-tags (org-set-tags nil t))
  957. (bookmark-set "org-remember-last-stored")
  958. (move-marker org-remember-last-stored-marker (point)))
  959. ((eq exitcmd 'left)
  960. ;; before current
  961. (org-paste-subtree level txt)
  962. (and org-auto-align-tags (org-set-tags nil t))
  963. (bookmark-set "org-remember-last-stored")
  964. (move-marker org-remember-last-stored-marker (point)))
  965. ((eq exitcmd 'right)
  966. ;; after current
  967. (org-end-of-subtree t)
  968. (org-paste-subtree level txt)
  969. (and org-auto-align-tags (org-set-tags nil t))
  970. (bookmark-set "org-remember-last-stored")
  971. (move-marker org-remember-last-stored-marker (point)))
  972. (t (error "This should not happen"))))
  973. ((eq heading 'bottom)
  974. (org-paste-subtree 1 txt)
  975. (and org-auto-align-tags (org-set-tags nil t))
  976. (bookmark-set "org-remember-last-stored")
  977. (move-marker org-remember-last-stored-marker (point)))
  978. ((and (bobp) (not reversed))
  979. ;; Put it at the end, one level below level 1
  980. (save-restriction
  981. (widen)
  982. (goto-char (point-max))
  983. (if (not (bolp)) (newline))
  984. (org-paste-subtree (org-get-valid-level 1 1) txt)
  985. (and org-auto-align-tags (org-set-tags nil t))
  986. (bookmark-set "org-remember-last-stored")
  987. (move-marker org-remember-last-stored-marker (point))))
  988. ((and (bobp) reversed)
  989. ;; Put it at the start, as level 1
  990. (save-restriction
  991. (widen)
  992. (goto-char (point-min))
  993. (re-search-forward "^\\*+ " nil t)
  994. (beginning-of-line 1)
  995. (org-paste-subtree 1 txt)
  996. (and org-auto-align-tags (org-set-tags nil t))
  997. (bookmark-set "org-remember-last-stored")
  998. (move-marker org-remember-last-stored-marker (point))))
  999. (t
  1000. ;; Put it right there, with automatic level determined by
  1001. ;; org-paste-subtree or from prefix arg
  1002. (org-paste-subtree
  1003. (if (numberp current-prefix-arg) current-prefix-arg)
  1004. txt)
  1005. (and org-auto-align-tags (org-set-tags nil t))
  1006. (bookmark-set "org-remember-last-stored")
  1007. (move-marker org-remember-last-stored-marker (point))))
  1008. (when remember-save-after-remembering
  1009. (save-buffer)
  1010. (if (and (not visiting)
  1011. (not (equal (marker-buffer org-clock-marker)
  1012. (current-buffer))))
  1013. (kill-buffer (current-buffer))))
  1014. (when org-remember-auto-remove-backup-files
  1015. (when backup-file
  1016. (ignore-errors
  1017. (delete-file backup-file)
  1018. (delete-file (concat backup-file "~"))))
  1019. (when org-remember-backup-directory
  1020. (let ((n (length
  1021. (directory-files
  1022. org-remember-backup-directory nil
  1023. "^remember-.*[0-9]$"))))
  1024. (when (and org-remember-warn-about-backups
  1025. (> n 0))
  1026. (message
  1027. "%d backup files (unfinished remember calls) in %s"
  1028. n org-remember-backup-directory))))))))))
  1029. t) ;; return t to indicate that we took care of this note.
  1030. (defun org-do-remember (&optional initial)
  1031. "Call remember."
  1032. (remember initial))
  1033. (defun org-require-remember ()
  1034. "Make sure remember is loaded, or install our own emergency version of it."
  1035. (condition-case nil
  1036. (require 'remember)
  1037. (error
  1038. ;; Lets install our own micro version of remember
  1039. (defvar remember-register ?R)
  1040. (defvar remember-mode-hook nil)
  1041. (defvar remember-handler-functions nil)
  1042. (defvar remember-buffer "*Remember*")
  1043. (defvar remember-save-after-remembering t)
  1044. (defvar remember-annotation-functions '(buffer-file-name))
  1045. (defun remember-finalize ()
  1046. (run-hook-with-args-until-success 'remember-handler-functions)
  1047. (when (equal remember-buffer (buffer-name))
  1048. (kill-buffer (current-buffer))
  1049. (jump-to-register remember-register)))
  1050. (defun remember-mode ()
  1051. (fundamental-mode)
  1052. (setq mode-name "Remember")
  1053. (run-hooks 'remember-mode-hook))
  1054. (defun remember (&optional initial)
  1055. (window-configuration-to-register remember-register)
  1056. (let* ((annotation (run-hook-with-args-until-success
  1057. 'remember-annotation-functions)))
  1058. (switch-to-buffer-other-window (get-buffer-create remember-buffer))
  1059. (remember-mode)))
  1060. (defun remember-buffer-desc ()
  1061. (buffer-substring (point-min) (save-excursion (goto-char (point-min))
  1062. (point-at-eol)))))))
  1063. (provide 'org-remember)
  1064. ;; arch-tag: 497f30d0-4bc3-4097-8622-2d27ac5f2698
  1065. ;;; org-remember.el ends here