org-remember.el 44 KB

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