org-remember.el 44 KB

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