Mercurial > emacs
annotate lisp/textmodes/remember.el @ 93393:902b4a2f5421
(remember-diary-convert-entry): Prefer boundp to with-no-warnings.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 29 Mar 2008 22:20:13 +0000 |
parents | e66b3bd7cef1 |
children | bc6b2ba17b08 |
rev | line source |
---|---|
85772 | 1 ;;; remember --- a mode for quickly jotting down things to remember |
2 | |
87665 | 3 ;; Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, |
4 ;; 2008 Free Software Foundation, Inc. | |
85772 | 5 |
6 ;; Author: John Wiegley <johnw@gnu.org> | |
7 ;; Created: 29 Mar 1999 | |
8 ;; Version: 1.9 | |
9 ;; Keywords: data memory todo pim | |
10 ;; URL: http://gna.org/projects/remember-el/ | |
11 | |
12 ;; This file is part of GNU Emacs. | |
13 | |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
15 ;; it under the terms of the GNU General Public License as published by | |
16 ;; the Free Software Foundation; either version 3, or (at your option) | |
17 ;; any later version. | |
18 | |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
27 ;; Boston, MA 02110-1301, USA. | |
28 | |
29 ;;; Commentary: | |
30 | |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
31 ;; * The idea |
85772 | 32 ;; |
33 ;; Todo lists, schedules, phone databases... everything we use | |
34 ;; databases for is really just a way to extend the power of our | |
35 ;; memory. To be able to remember what our conscious mind may not | |
36 ;; currently have access to. | |
37 ;; | |
38 ;; There are many different databases out there -- and good ones -- | |
39 ;; which this mode is not trying to replace. Rather, it's how that | |
40 ;; data gets there that's the question. Most of the time, we just | |
41 ;; want to say "Remember so-and-so's phone number, or that I have to | |
42 ;; buy dinner for the cats tonight." That's the FACT. How it's | |
43 ;; stored is really the computer's problem. But at this point in | |
44 ;; time, it's most definitely also the user's problem, and sometimes | |
45 ;; so laboriously so that people just let data slip, rather than | |
46 ;; expend the effort to record it. | |
47 ;; | |
48 ;; "Remember" is a mode for remembering data. It uses whatever | |
49 ;; back-end is appropriate to record and correlate the data, but it's | |
50 ;; main intention is to allow you to express as _little_ structure as | |
51 ;; possible up front. If you later want to express more powerful | |
52 ;; relationships between your data, or state assumptions that were at | |
53 ;; first too implicit to be recognized, you can "study" the data later | |
54 ;; and rearrange it. But the initial "just remember this" impulse | |
55 ;; should be as close to simply throwing the data at Emacs as | |
56 ;; possible. | |
57 ;; | |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
58 ;; * Implementation |
85772 | 59 ;; |
60 ;; Hyperbole, as a data presentation tool, always struck me as being | |
61 ;; very powerful, but it seemed to require a lot of "front-end" work | |
62 ;; before that data was really available. The problem with BBDB, or | |
63 ;; keeping up a Bibl-mode file, is that you have to use different | |
64 ;; functions to record the data, and it always takes time to stop what | |
65 ;; you're doing, format the data in the manner expected by that | |
66 ;; particular data interface, and then resume your work. | |
67 ;; | |
68 ;; With "remember", you just hit `M-x remember' (you'd probably want | |
69 ;; to bind this to an easily accessible keystroke, like C-x M-r), slam | |
70 ;; in your text however you like, and then hit C-c C-c. It will file | |
71 ;; the data away for later retrieval, and possibly indexing. | |
72 ;; | |
73 ;; Indexing is to data what "studying" is in the real world. What you | |
74 ;; do when you study (or lucubrate, for some of us) is to realize | |
75 ;; certain relationships implicit in the data, so that you can make | |
76 ;; use of those relationships. Expressing that a certain quote you | |
77 ;; remembered was a religious quote, and that you want the ability to | |
78 ;; pull up all quotes of a religious nature, is what studying does. | |
79 ;; This is a more labor intensive task than the original remembering | |
80 ;; of the data, and it's typical in real life to set aside a special | |
81 ;; period of time for doing this work. | |
82 ;; | |
83 ;; "Remember" works in the same way. When you enter data, either by | |
84 ;; typing it into a buffer, or using the contents of the selected | |
85 ;; region, it will store that data -- unindexed, uninterpreted -- in a | |
86 ;; data pool. It will also try to remember as much context | |
87 ;; information as possible (any text properties that were set, where | |
88 ;; you copied it from, when, how, etc). Later, you can walk through | |
89 ;; your accumulated set of data (both organized, and unorganized) and | |
90 ;; easily begin moving things around, and making annotations that will | |
91 ;; express the full meaning of that data, as far as you know it. | |
92 ;; | |
93 ;; Obviously this latter stage is more user-interface intensive, and | |
94 ;; it would be nice if "remember" could do it as elegantly as | |
95 ;; possible, rather than requiring a billion keystrokes to reorganize | |
96 ;; your hierarchy. Well, as the future arrives, hopefully experience | |
97 ;; and user feedback will help to make this as intuitive a tool as | |
98 ;; possible. | |
99 ;; | |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
100 ;; * Future Goals |
85772 | 101 ;; |
102 ;; This tool hopes to track (and by doing it with as little new code | |
103 ;; as possible): | |
104 ;; | |
105 ;; - The raw data that gets entered | |
106 ;; | |
107 ;; - The relationships between that data (either determined | |
108 ;; implicitly by parsing the input, or explicitly by the user's | |
109 ;; studying the data). | |
110 ;; | |
111 ;; - Revisioning of the data | |
112 ;; | |
113 ;; - Where it came from, and any context information that can be | |
114 ;; programmatically determined. | |
115 ;; | |
116 ;; - Allowing particular views of the initially amorphous data pool | |
117 ;; (ala the Xanadu concept). | |
118 ;; | |
119 ;; - Storage of the data in a manner most appopriate to that data, | |
120 ;; such as keeping address-book type information in BBDB, etc. | |
121 ;; | |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
122 ;; * Using "remember" |
85772 | 123 ;; |
124 ;; As a rough beginning, what I do is to keep my .notes file in | |
125 ;; outline-mode format, with a final entry called "* Raw data". Then, | |
126 ;; at intervals, I can move the data that gets appended there into | |
127 ;; other places. But certainly this should evolve into an intuitive | |
128 ;; mechanism for shuffling data off to its appropriate corner of the | |
129 ;; universe. | |
130 ;; | |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
131 ;; To map the primary remember function to the keystroke F8, do the |
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
132 ;; following. |
85772 | 133 ;; |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
134 ;; (autoload 'remember "remember" nil t) |
85772 | 135 ;; |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
136 ;; (define-key global-map [f8] 'remember) |
85772 | 137 ;; |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
138 ;; * Feedback |
85772 | 139 ;; |
140 ;; If Emacs could become a more intelligent data store, where | |
141 ;; brainstorming would focus on the IDEAS involved -- rather than the | |
142 ;; structuring and format of those ideas, or having to stop your | |
143 ;; current flow of work in order to record them -- it would map much | |
144 ;; more closely to how the mind (well, at least mine) works, and hence | |
145 ;; would eliminate that very manual-ness which computers from the very | |
146 ;; beginning have been championed as being able to reduce. | |
147 ;; | |
148 ;; Have you ever noticed that having a laptop to write on doesn't | |
149 ;; _actually_ increase the amount of quality material that you turn | |
150 ;; out, in the long run? Perhaps its because the time we save | |
151 ;; electronically in one way, we're losing electronically in another; | |
152 ;; the tool should never dominate one's focus. As the mystic | |
153 ;; Faridu'd-Din `Attar wrote: "Be occupied as little as possible with | |
154 ;; things of the outer world but much with things of the inner world; | |
155 ;; then right action will overcome inaction." | |
87054
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
156 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
157 ;; * Diary integration |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
158 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
159 ;; To use, add the following to your .emacs: |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
160 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
161 ;; ;; This should be before other entries that may return t |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
162 ;; (add-to-list 'remember-handler-functions 'remember-diary-extract-entries) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
163 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
164 ;; This module recognizes entries of the form |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
165 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
166 ;; DIARY: .... |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
167 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
168 ;; and puts them in your ~/.diary (or remember-diary-file) together |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
169 ;; with an annotation. Dates in the form YYYY.MM.DD are converted to |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
170 ;; YYYY-MM-DD so that diary can understand them. |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
171 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
172 ;; For example: |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
173 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
174 ;; DIARY: 2003.08.12 Sacha's birthday |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
175 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
176 ;; is stored as |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
177 ;; |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
178 ;; 2003.08.12 Sacha's birthday |
85772 | 179 |
180 ;;; History: | |
181 | |
182 ;;; Code: | |
183 | |
184 (provide 'remember) | |
185 | |
186 (defconst remember-version "1.9" | |
187 "This version of remember.") | |
188 | |
189 (defgroup remember nil | |
190 "A mode to remember information." | |
191 :group 'data) | |
192 | |
193 ;;; User Variables: | |
194 | |
195 (defcustom remember-mode-hook nil | |
196 "Functions run upon entering `remember-mode'." | |
197 :type 'hook | |
85798
5810ee84e0f9
remember.el: Add additional items to some defcustom options
Michael Olson <mwolson@gnu.org>
parents:
85772
diff
changeset
|
198 :options '(flyspell-mode turn-on-auto-fill org-remember-apply-template) |
85772 | 199 :group 'remember) |
200 | |
201 (defcustom remember-in-new-frame nil | |
202 "Non-nil means use a separate frame for capturing remember data." | |
203 :type 'boolean | |
204 :group 'remember) | |
205 | |
206 (defcustom remember-register ?R | |
207 "The register in which the window configuration is stored." | |
208 :type 'character | |
209 :group 'remember) | |
210 | |
211 (defcustom remember-filter-functions nil | |
212 "*Functions run to filter remember data. | |
213 All functions are run in the remember buffer." | |
214 :type 'hook | |
215 :group 'remember) | |
216 | |
217 (defcustom remember-handler-functions '(remember-append-to-file) | |
218 "*Functions run to process remember data. | |
219 Each function is called with the current buffer narrowed to what the | |
220 user wants remembered. | |
221 If any function returns non-nil, the data is assumed to have been | |
222 recorded somewhere by that function. " | |
223 :type 'hook | |
85798
5810ee84e0f9
remember.el: Add additional items to some defcustom options
Michael Olson <mwolson@gnu.org>
parents:
85772
diff
changeset
|
224 :options '(remember-store-in-mailbox |
5810ee84e0f9
remember.el: Add additional items to some defcustom options
Michael Olson <mwolson@gnu.org>
parents:
85772
diff
changeset
|
225 remember-append-to-file |
5810ee84e0f9
remember.el: Add additional items to some defcustom options
Michael Olson <mwolson@gnu.org>
parents:
85772
diff
changeset
|
226 remember-diary-extract-entries |
5810ee84e0f9
remember.el: Add additional items to some defcustom options
Michael Olson <mwolson@gnu.org>
parents:
85772
diff
changeset
|
227 org-remember-handler) |
85772 | 228 :group 'remember) |
229 | |
230 (defcustom remember-all-handler-functions nil | |
231 "If non-nil every function in `remember-handler-functions' is | |
232 called." | |
233 :type 'boolean | |
234 :group 'remember) | |
235 | |
236 ;;; Internal Variables: | |
237 | |
238 (defvar remember-buffer "*Remember*" | |
239 "The name of the remember data entry buffer.") | |
240 | |
241 (defcustom remember-save-after-remembering t | |
242 "*Non-nil means automatically save after remembering." | |
243 :type 'boolean | |
244 :group 'remember) | |
245 | |
246 ;;; User Functions: | |
247 | |
85886
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
248 (defcustom remember-annotation-functions '(buffer-file-name) |
b315ed3fcc4e
Remove mentions of Planner in remember.el.
Michael Olson <mwolson@gnu.org>
parents:
85863
diff
changeset
|
249 "Hook that returns an annotation to be inserted into the remember buffer." |
85772 | 250 :type 'hook |
85798
5810ee84e0f9
remember.el: Add additional items to some defcustom options
Michael Olson <mwolson@gnu.org>
parents:
85772
diff
changeset
|
251 :options '(org-remember-annotation buffer-file-name) |
85772 | 252 :group 'remember) |
253 | |
254 (defvar remember-annotation nil | |
255 "Current annotation.") | |
256 (defvar remember-initial-contents nil | |
257 "Initial contents to place into *Remember* buffer.") | |
85861
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
258 |
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
259 (defcustom remember-before-remember-hook nil |
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
260 "Functions run before switching to the *Remember* buffer." |
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
261 :type 'hook |
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
262 :group 'remember) |
85772 | 263 |
264 (defcustom remember-run-all-annotation-functions-flag nil | |
265 "Non-nil means use all annotations returned by | |
266 `remember-annotation-functions'." | |
267 :type 'boolean | |
268 :group 'remember) | |
269 | |
270 ;;;###autoload | |
271 (defun remember (&optional initial) | |
272 "Remember an arbitrary piece of data. | |
85861
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
273 INITIAL is the text to initially place in the *Remember* buffer, |
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
274 or nil to bring up a blank *Remember* buffer. |
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
275 |
87626
a918e56d9947
Remember: If region is visible, use it as initial text.
Michael Olson <mwolson@gnu.org>
parents:
87054
diff
changeset
|
276 With a prefix or a visible region, use the region as INITIAL." |
85772 | 277 (interactive |
87626
a918e56d9947
Remember: If region is visible, use it as initial text.
Michael Olson <mwolson@gnu.org>
parents:
87054
diff
changeset
|
278 (list (when (or current-prefix-arg |
a918e56d9947
Remember: If region is visible, use it as initial text.
Michael Olson <mwolson@gnu.org>
parents:
87054
diff
changeset
|
279 (and mark-active |
a918e56d9947
Remember: If region is visible, use it as initial text.
Michael Olson <mwolson@gnu.org>
parents:
87054
diff
changeset
|
280 transient-mark-mode)) |
a918e56d9947
Remember: If region is visible, use it as initial text.
Michael Olson <mwolson@gnu.org>
parents:
87054
diff
changeset
|
281 (buffer-substring (region-beginning) (region-end))))) |
85772 | 282 (funcall (if remember-in-new-frame |
283 #'frame-configuration-to-register | |
284 #'window-configuration-to-register) remember-register) | |
285 (let* ((annotation | |
286 (if remember-run-all-annotation-functions-flag | |
287 (mapconcat 'identity | |
288 (delq nil | |
289 (mapcar 'funcall remember-annotation-functions)) | |
290 "\n") | |
291 (run-hook-with-args-until-success | |
292 'remember-annotation-functions))) | |
293 (buf (get-buffer-create remember-buffer))) | |
294 (run-hooks 'remember-before-remember-hook) | |
295 (funcall (if remember-in-new-frame | |
296 #'switch-to-buffer-other-frame | |
297 #'switch-to-buffer-other-window) buf) | |
298 (if remember-in-new-frame | |
299 (set-window-dedicated-p | |
300 (get-buffer-window (current-buffer) (selected-frame)) t)) | |
301 (remember-mode) | |
302 (when (= (point-max) (point-min)) | |
303 (when initial (insert initial)) | |
304 (setq remember-annotation annotation) | |
305 (when remember-initial-contents (insert remember-initial-contents)) | |
306 (when (and (stringp annotation) | |
307 (not (equal annotation ""))) | |
308 (insert "\n\n" annotation)) | |
309 (setq remember-initial-contents nil) | |
310 (goto-char (point-min))) | |
311 (message "Use C-c C-c to remember the data."))) | |
312 | |
313 ;;;###autoload | |
314 (defun remember-other-frame (&optional initial) | |
315 "Call `remember' in another frame." | |
316 (interactive | |
317 (list (when current-prefix-arg | |
318 (buffer-substring (point) (mark))))) | |
319 (let ((remember-in-new-frame t)) | |
320 (remember initial))) | |
321 | |
322 (defsubst remember-time-to-seconds (time) | |
323 "Convert TIME to a floating point number." | |
324 (+ (* (car time) 65536.0) | |
325 (cadr time) | |
326 (/ (or (car (cdr (cdr time))) 0) 1000000.0))) | |
327 | |
328 (defsubst remember-mail-date (&optional rfc822-p) | |
329 "Return a simple date. Nothing fancy." | |
330 (if rfc822-p | |
331 (format-time-string "%a, %e %b %Y %T %z" (current-time)) | |
93171
d2b14ee5ca13
Remember: Write mbox in a way that works better with Mutt.
Michael Olson <mwolson@gnu.org>
parents:
87665
diff
changeset
|
332 (format-time-string "%a %b %e %T %Y" (current-time)))) |
85772 | 333 |
334 (defun remember-buffer-desc () | |
335 "Using the first line of the current buffer, create a short description." | |
336 (buffer-substring (point-min) | |
337 (save-excursion | |
338 (goto-char (point-min)) | |
339 (end-of-line) | |
340 (if (> (- (point) (point-min)) 60) | |
341 (goto-char (+ (point-min) 60))) | |
342 (point)))) | |
343 | |
344 ;; Remembering to UNIX mailboxes | |
345 | |
346 (defcustom remember-mailbox "~/Mail/remember" | |
347 "*The file in which to store remember data as mail." | |
348 :type 'file | |
349 :group 'remember) | |
350 | |
351 (defcustom remember-default-priority "medium" | |
352 "*The default priority for remembered mail messages." | |
353 :type 'string | |
354 :group 'remember) | |
355 | |
356 (defun remember-store-in-mailbox () | |
357 "Store remember data as if it were incoming mail. | |
358 In which case `remember-mailbox' should be the name of the mailbox. | |
359 Each piece of psuedo-mail created will have an `X-Todo-Priority' | |
360 field, for the purpose of appropriate splitting." | |
361 (let ((who (read-string "Who is this item related to? ")) | |
362 (moment | |
363 (format "%.0f" (remember-time-to-seconds (current-time)))) | |
364 (desc (remember-buffer-desc)) | |
365 (text (buffer-string))) | |
366 (with-temp-buffer | |
93171
d2b14ee5ca13
Remember: Write mbox in a way that works better with Mutt.
Michael Olson <mwolson@gnu.org>
parents:
87665
diff
changeset
|
367 (insert (format "From %s %s |
85772 | 368 Date: %s |
369 From: %s | |
370 Message-Id: <remember-%s@%s> | |
371 X-Todo-Priority: %s | |
372 To: %s <%s> | |
373 Subject: %s\n\n" | |
374 (user-login-name) | |
375 (remember-mail-date) | |
376 (remember-mail-date t) | |
377 who | |
378 moment (system-name) | |
379 remember-default-priority | |
380 (user-full-name) user-mail-address | |
381 desc)) | |
382 (let ((here (point))) | |
383 (insert text) | |
384 (unless (bolp) | |
385 (insert "\n")) | |
386 (insert "\n") | |
387 (goto-char here) | |
388 (while (re-search-forward "^\\(From[: ]\\)" nil t) | |
389 (replace-match ">\\1"))) | |
390 (append-to-file (point-min) (point-max) remember-mailbox) | |
391 t))) | |
392 | |
393 ;; Remembering to plain files | |
394 | |
395 (defcustom remember-data-file "~/.notes" | |
396 "*The file in which to store unprocessed data." | |
397 :type 'file | |
398 :group 'remember) | |
399 | |
400 (defcustom remember-leader-text "** " | |
401 "*The text used to begin each remember item." | |
402 :type 'string | |
403 :group 'remember) | |
404 | |
405 (defun remember-append-to-file () | |
406 "Remember, with description DESC, the given TEXT." | |
407 (let ((text (buffer-string)) | |
408 (desc (remember-buffer-desc))) | |
409 (with-temp-buffer | |
410 (insert "\n" remember-leader-text (current-time-string) | |
411 " (" desc ")\n\n" text) | |
412 (if (not (bolp)) | |
413 (insert "\n")) | |
414 (if (find-buffer-visiting remember-data-file) | |
415 (let ((remember-text (buffer-string))) | |
416 (set-buffer (get-file-buffer remember-data-file)) | |
417 (save-excursion | |
418 (goto-char (point-max)) | |
419 (insert remember-text) | |
420 (when remember-save-after-remembering (save-buffer)))) | |
421 (append-to-file (point-min) (point-max) remember-data-file))))) | |
422 | |
423 (defun remember-region (&optional beg end) | |
424 "Remember the data from BEG to END. | |
85861
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
425 It is called from within the *Remember* buffer to save the text |
87626
a918e56d9947
Remember: If region is visible, use it as initial text.
Michael Olson <mwolson@gnu.org>
parents:
87054
diff
changeset
|
426 that was entered. |
85772 | 427 |
85861
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
428 If BEG and END are nil, the entire buffer will be remembered. |
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
429 |
85772 | 430 If you want to remember a region, supply a universal prefix to |
85861
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
431 `remember' instead. For example: C-u M-x remember RET." |
85772 | 432 ;; Sacha: I have no idea where remember.el gets this context information, but |
433 ;; you can just use remember-annotation-functions. | |
434 (interactive) | |
435 (let ((b (or beg (min (point) (or (mark) (point-min))))) | |
436 (e (or end (max (point) (or (mark) (point-max)))))) | |
437 (save-restriction | |
438 (narrow-to-region b e) | |
439 (if remember-all-handler-functions | |
440 (run-hooks 'remember-handler-functions) | |
441 (run-hook-with-args-until-success 'remember-handler-functions)) | |
442 (remember-destroy)))) | |
443 | |
444 ;;;###autoload | |
445 (defun remember-clipboard () | |
446 "Remember the contents of the current clipboard. | |
447 Most useful for remembering things from Netscape or other X Windows | |
448 application." | |
449 (interactive) | |
450 (remember (current-kill 0))) | |
451 | |
85861
70f347d257ec
Remember: Put on a low-cookie diet, and improve docstrings.
Michael Olson <mwolson@gnu.org>
parents:
85806
diff
changeset
|
452 (defun remember-finalize () |
85772 | 453 "Remember the contents of the current buffer." |
454 (interactive) | |
455 (remember-region (point-min) (point-max))) | |
456 | |
85889
683a6a9e56ab
remember.el: Make remember-buffer an alias of remember-finalize
Michael Olson <mwolson@gnu.org>
parents:
85886
diff
changeset
|
457 ;; Org needs this |
85913
047b6a6087c2
Remember: Use define-obsolete-function-alias for `remember-buffer'.
Michael Olson <mwolson@gnu.org>
parents:
85889
diff
changeset
|
458 (define-obsolete-function-alias 'remember-buffer 'remember-finalize) |
85889
683a6a9e56ab
remember.el: Make remember-buffer an alias of remember-finalize
Michael Olson <mwolson@gnu.org>
parents:
85886
diff
changeset
|
459 |
85772 | 460 (defun remember-destroy () |
461 "Destroy the current *Remember* buffer." | |
462 (interactive) | |
463 (when (equal remember-buffer (buffer-name)) | |
464 (kill-buffer (current-buffer)) | |
465 (jump-to-register remember-register))) | |
466 | |
87054
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
467 ;;; Diary integration |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
468 |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
469 (defcustom remember-diary-file nil |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
470 "*File for extracted diary entries. |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
471 If this is nil, then `diary-file' will be used instead." |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
472 :type 'file |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
473 :group 'remember) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
474 |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
475 (defun remember-diary-convert-entry (entry) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
476 "Translate MSG to an entry readable by diary." |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
477 (save-match-data |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
478 (when remember-annotation |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
479 (setq entry (concat entry " " remember-annotation))) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
480 (if (string-match "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" entry) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
481 (replace-match |
93377
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
482 (let ((style (if (boundp 'calendar-date-style) |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
483 calendar-date-style |
93393
902b4a2f5421
(remember-diary-convert-entry): Prefer boundp to with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93377
diff
changeset
|
484 (if (bound-and-true-p european-calendar-style) |
93377
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
485 'european |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
486 'american)))) |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
487 (cond ((eq style 'european) |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
488 (concat (match-string 3 entry) "/" |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
489 (match-string 2 entry) "/" |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
490 (match-string 1 entry))) |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
491 ((eq style 'iso) |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
492 (concat (match-string 1 entry) "-" |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
493 (match-string 2 entry) "-" |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
494 (match-string 3 entry))) |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
495 (t (concat (match-string 2 entry) "/" |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
496 (match-string 3 entry) "/" |
e66b3bd7cef1
(remember-diary-convert-entry): Respect calendar-date-style if bound.
Glenn Morris <rgm@gnu.org>
parents:
93171
diff
changeset
|
497 (match-string 1 entry))))) |
87054
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
498 t t entry) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
499 entry))) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
500 |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
501 (autoload 'make-diary-entry "diary-lib") |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
502 |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
503 ;;;###autoload |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
504 (defun remember-diary-extract-entries () |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
505 "Extract diary entries from the region." |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
506 (save-excursion |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
507 (goto-char (point-min)) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
508 (let (list) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
509 (while (re-search-forward "^DIARY:\\s-*\\(.+\\)" nil t) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
510 (add-to-list 'list (remember-diary-convert-entry (match-string 1)))) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
511 (when list |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
512 (make-diary-entry (mapconcat 'identity list "\n") |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
513 nil (or remember-diary-file diary-file))) |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
514 nil))) ;; Continue processing |
25de6f4a58d8
Merge remember-diary.el into remember.el
Michael Olson <mwolson@gnu.org>
parents:
85913
diff
changeset
|
515 |
85772 | 516 ;;; Internal Functions: |
517 | |
85862
9e1be56af44a
remember.el (remember-mode-map): Define and initialize in one step.
Michael Olson <mwolson@gnu.org>
parents:
85861
diff
changeset
|
518 (defvar remember-mode-map |
9e1be56af44a
remember.el (remember-mode-map): Define and initialize in one step.
Michael Olson <mwolson@gnu.org>
parents:
85861
diff
changeset
|
519 (let ((map (make-sparse-keymap))) |
9e1be56af44a
remember.el (remember-mode-map): Define and initialize in one step.
Michael Olson <mwolson@gnu.org>
parents:
85861
diff
changeset
|
520 (define-key map "\C-x\C-s" 'remember-finalize) |
9e1be56af44a
remember.el (remember-mode-map): Define and initialize in one step.
Michael Olson <mwolson@gnu.org>
parents:
85861
diff
changeset
|
521 (define-key map "\C-c\C-c" 'remember-finalize) |
85863
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
522 (define-key map "\C-c\C-k" 'remember-destroy) |
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
523 |
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
524 map) |
85772 | 525 "Keymap used in Remember mode.") |
526 | |
527 (defun remember-mode () | |
528 "Major mode for output from \\[remember]. | |
85863
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
529 This buffer is used to collect data that you want to remember. |
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
530 |
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
531 Just hit `C-c C-c' when you're done entering, and it will file |
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
532 the data away for latter retrieval, and possible indexing. |
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
533 |
f5b982bf98e0
Remember: Fix mistake in last commit and improve remember-mode docstring.
Michael Olson <mwolson@gnu.org>
parents:
85862
diff
changeset
|
534 \\{remember-mode-map}" |
85772 | 535 (interactive) |
536 (kill-all-local-variables) | |
537 (indented-text-mode) | |
538 (use-local-map remember-mode-map) | |
539 (setq major-mode 'remember-mode | |
540 mode-name "Remember") | |
541 (run-hooks 'remember-mode-hook)) | |
542 | |
85806 | 543 ;; arch-tag: 59312a05-06c7-4da1-b6f7-5ea41c9d5577 |
85772 | 544 ;;; remember.el ends here |