]> code.delx.au - gnu-emacs-elpa/blob - packages/notes-mode/notes-mode.el
Merge commit '0e327f72bdffc5bc4a1fbc34a8da1b7066e819b3'
[gnu-emacs-elpa] / packages / notes-mode / notes-mode.el
1 ;;; notes-mode.el --- Indexing system for on-line note-taking
2
3 ;; Copyright (C) 1994-2007,2012 Free Software Foundation, Inc.
4
5 ;; Author: <johnh@isi.edu>.
6 ;; Version: 1.30
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
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
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23
24 ;;; Commentary:
25 ;;
26
27 ;;; Code:
28
29 (require 'notes-variables)
30 (require 'notes-aux)
31
32 (defvar notes-mode-hooks nil
33 "Hooks to run when entering notes-mode.")
34 (defvar notes-load-mode-hooks nil
35 "Hooks to run when entering notes-mode is loaded.")
36
37 (defconst notes-beginning-of-defun-regexp "^\\* .*\n\\-"
38 "Regexp matching the beginning of notes section.")
39
40 (defvar notes-default-tab-binding (global-key-binding "\t")
41 "Saved tab binding for notes-complete-subject.")
42 (defvar notes-default-return-binding (global-key-binding "\r")
43 "Saved return binding for notes-electric-return.")
44
45
46 (defun notes-beginning-of-defun ()
47 "Go to the beginning of a notes ``section''."
48 (interactive)
49 (let
50 ((old-point (point)))
51 (beginning-of-line)
52 ;; handle starting on a title
53 (if (and (looking-at notes-beginning-of-defun-regexp)
54 (/= (point) old-point))
55 nil
56 (goto-char old-point)
57 (if (looking-at "^-") ;; handle starting on the underline under a title
58 (forward-char 1))
59 (re-search-backward notes-beginning-of-defun-regexp nil 'to-limit))))
60
61 (defun notes-end-of-defun ()
62 "Go to the end of a notes ``section''."
63 (interactive)
64 (let ((regexp notes-beginning-of-defun-regexp))
65 (if (looking-at regexp)
66 (goto-char (match-end 0)))
67 ;; Find next section and leave cursor at section beginning
68 (if (re-search-forward regexp nil 'to-limit)
69 (re-search-backward regexp 0 t)
70 ;;(goto-char restore-point)
71 )))
72
73 (defun notes-follow-link (which)
74 "Go to the WHICH link for this topic.
75 WHICH is either \"next\" or \"prev\".
76 If there are no links for the current note,
77 we go to the last note based upon the index file."
78 (let
79 (beginning-of-note
80 end-of-note
81 (start-buffer (current-buffer))
82 ;; We have to handle links in the same buffer,
83 ;; so the following code figure out where we go
84 ;; and returns it out of the save-excursion.
85 ;; If we end up in another buffer, we let the save-excursion
86 ;; leave the original buffer unchanged. If we end up in
87 ;; the same buffer, we need to go wherever we end up.
88 ;; Can anyone suggest a better way?
89 (end-buffer-and-point
90 (save-excursion
91 (notes-end-of-defun)
92 (setq end-of-note (point))
93 (notes-beginning-of-defun)
94 (setq beginning-of-note (point))
95 (if (and (= beginning-of-note 1) (not (looking-at notes-beginning-of-defun-regexp)))
96 (progn
97 ;; When "above" the first note, search to end of first
98 ;; real note (otherwise end-of-note is just the start
99 ;; of the first real note and there are no links).
100 (notes-end-of-defun)
101 (notes-end-of-defun)
102 (setq end-of-note (point))
103 (goto-char beginning-of-note)))
104 (if (re-search-forward (concat "^"
105 (if (eq which 'next) "next" "prev")
106 ":[ ]+<") end-of-note t)
107 (progn ; link exists, just take it
108 (beginning-of-line)
109 (notes-w3-follow-link (point))
110 (cons (current-buffer) (point)))
111 ;; No link; go through the index file.
112 (if (notes-goto-index-entry which)
113 (let ((index-buffer (current-buffer)))
114 (notes-index-follow-link (point))
115 (bury-buffer index-buffer))
116 (error "No known notes in that direction.")
117 (bury-buffer (current-buffer)))
118 (cons (current-buffer) (point))))))
119 ;; Check for going to the same buffer (and the save-excursion
120 ;; undoing our work).
121 (if (eq start-buffer (car end-buffer-and-point))
122 (goto-char (cdr end-buffer-and-point)))))
123
124
125 (defun notes-follow-next-link ()
126 "Go to the next link for this topic."
127 (interactive)
128 (notes-follow-link 'next))
129
130 (defun notes-follow-prev-link ()
131 "Go to the previous link for this topic."
132 (interactive)
133 (notes-follow-link 'prev))
134
135 (defvar notes-complete-subject-abbrevs-alist
136 '(("SP2010" "USC/Classes/CS551/SP2010")
137 ("FA2011" "USC/Classes/CS551/FA2011"))
138 "Alist of simple substitution of subjects.
139 If subject completion is requested, then subject that matches
140 the left-side of an alist value is replaced by the right-side value.")
141
142 (defun notes-complete-subject-abbrevs (key)
143 "Handle abbreviations on notes SUBJECTS.
144 Currently this is just a hack."
145 (let ((value (assoc key notes-complete-subject-abbrevs-alist)))
146 (if value
147 (car (cdr value))
148 key)))
149
150
151 (defun notes-complete-subject ()
152 "Complete the notes subject under point."
153 (interactive)
154 (let
155 ((subject (save-excursion
156 (beginning-of-line)
157 (notes-extract-subject t)))
158 old-completion-ignore-case
159 full-subject)
160 (if (not (and notes-mode-complete-subjects subject))
161 (call-interactively notes-default-tab-binding)
162 ;; Complete the title.
163 (if (null notes-subject-table)
164 (save-excursion ;; FIXME: Why??
165 (find-file-noselect (expand-file-name "index" notes-dir))))
166 ;; Do completion.
167 ;; Run completer if it's loaded,
168 ;; otherwise do our own thing.
169 (setq completion-ignore-case t)
170 (cond
171 ((fboundp 'completer-complete-goto)
172 (completer-complete-goto "^ \t\n\"" " " notes-subject-table nil))
173 ;; NEEDSWORK: should try other completers, too.
174 (t ;; Do our own completion.
175 (setq full-subject (try-completion subject notes-subject-table)
176 subject (completing-read "Subject: "
177 notes-subject-table nil nil
178 (if (stringp full-subject)
179 full-subject
180 subject)))
181 (delete-region (line-beginning-position) (line-end-position))
182 (insert "* " (notes-complete-subject-abbrevs subject))))
183 (setq completion-ignore-case old-completion-ignore-case))))
184
185 (defun notes-fix-prevnext-this-entry ()
186 "Fix up the prev link for the current entry, if necessary.
187 Currently this code only handles brand new entries."
188 ;; Contributed from Takashi Nishimoto <g96p0935@mse.waseda.ac.jp>.
189 ;; Thanks!
190 (interactive)
191 (let ((subject (notes-extract-subject nil t))
192 (this-url (notes-current-url))
193 last-url)
194 (with-current-buffer (find-file-noselect
195 (expand-file-name "index" notes-dir))
196 (goto-char (point-min))
197 (if (re-search-forward
198 (concat "^" (regexp-quote subject) ":.* \\([0-9]+\\)$")
199 (point-max) t)
200 (save-window-excursion
201 (cond ((and (notes-w3-url
202 (notes-file-to-url (match-string 1) subject))
203 (re-search-forward "^next: " nil t)
204 (looking-at "<none>"))
205 (let
206 (pre-modified (buffer-modified-p))
207 (delete-char 6)
208 (insert this-url)
209 (setq last-url (notes-current-url))
210 (if (and (null pre-modified)
211 (>= notes-electric-prevnext 2))
212 (save-buffer))))))))
213 (if last-url
214 (progn
215 (notes-beginning-of-defun)
216 (forward-line 2)
217 (if (not (looking-at "prev: "))
218 (insert "prev: " last-url "\n" "next: <none>\n\n")
219 (forward-line 3))))))
220
221 (defun notes-electric-return (arg)
222 "* Return, underlining if we're on a subject."
223 (interactive "*P")
224 (if (let ((cur-point (point)))
225 (save-excursion
226 (beginning-of-line)
227 (and (not (eq cur-point (point))) ;; normal return if at b-o-ln
228 (notes-extract-subject t))))
229 (progn (notes-underline-line)
230 (if notes-electric-prevnext
231 (notes-fix-prevnext-this-entry)))
232 (call-interactively notes-default-return-binding)))
233
234 (defun notes-current-url ()
235 "Return the notes-URL of the current entry around the current point."
236 (let ((subject (notes-extract-subject nil t))
237 (date (file-name-nondirectory buffer-file-name)))
238 (concat "<file:///"
239 (abbreviate-file-name buffer-file-name)
240 (if subject (concat "#* " subject) "")
241 ">")))
242
243 (defun notes-current-url-as-kill ()
244 "* Put the notes-URL of the current entry into the kill ring."
245 (interactive)
246 (kill-new (notes-current-url)))
247
248 (defun notes-goto-index-entry (&optional direction)
249 "* Jump to the index entry corresponding to our current note entry.
250 If we're not in an entry, we leave you in the index file.
251 If the current date doesn't exist, error in DIRECTION.
252 Returns nil if on errors (no index; no date in DIRECTION),
253 otherwise the point of the hit."
254 (interactive)
255 (let ((start-buffer (current-buffer))
256 (subject (notes-extract-subject)) ; get subject if on it
257 (date (if (null (buffer-file-name)) nil
258 (file-name-nondirectory (buffer-file-name)))))
259 ;; Try and get the subject, either forward...
260 (if (not subject)
261 (save-excursion
262 (notes-beginning-of-defun)
263 (setq subject (notes-extract-subject))))
264 ;; ...or backwards.
265 (if (not subject)
266 (save-excursion
267 (notes-end-of-defun)
268 (setq subject (notes-extract-subject))))
269 ;; Form and jump to the url for the index-entry.
270 (if (and (notes-w3-url (concat notes-url-prefix
271 "index"
272 (if subject (concat "#" subject) ""))
273 nil t)
274 ;; Go to the current date, if any.
275 (notes-index-goto-date date direction))
276 t
277 nil)))
278
279 (defun notes-extract-subject (&optional relaxed search)
280 "Extract the subject under the point in the current buffer.
281 If RELAXED, then accept non-underlined subjects.
282 If SEARCH we'll search back in the buffer for the nearest
283 subject title.
284
285 Returns nil if we're not on as subject."
286 (save-match-data
287 (cond
288 ;; directly on a note
289 ((or (looking-at notes-beginning-of-defun-regexp)
290 (and relaxed
291 (looking-at "^\\* ")))
292 (save-excursion
293 (let
294 ((start (+ (point) 2))
295 (end (progn (end-of-line) (point))))
296 (buffer-substring start end))))
297 (search
298 (save-excursion
299 (notes-beginning-of-defun)
300 (notes-extract-subject relaxed nil)))
301 (t
302 nil))))
303
304
305 ;;;###autoload
306 (defun notes-underline-line ()
307 "* Create a row of dashes as long as this line, or adjust the current underline."
308 (interactive)
309 ;; check to see if it's already underlined
310 (if (save-excursion
311 (forward-line 1)
312 (looking-at "^[ \t]*--*$"))
313 (notes-old-underline-line)
314 (progn
315 (notes-new-underline-line)
316 (insert "\n\n"))))
317
318 (defun notes-new-underline-line ()
319 "Underline a line with a row of dashes. Move point after the dashes.
320 \\[notes-new-underline-line] reproduces leading spaces."
321 (interactive)
322 (let*
323 ((bol (progn (beginning-of-line)
324 (point)))
325 (bospaces (progn (skip-chars-forward " \t")
326 (point)))
327 (nospaces (- bospaces bol))
328 (eol (progn (end-of-line)
329 (untabify bol (point))
330 (point))))
331 (insert "\n" (buffer-substring bol bospaces))
332 (insert-char ?- (- eol bospaces))))
333
334 (defun notes-old-underline-line ()
335 "Replace the following line with a row of dashes. Leave the point unchanged."
336 (save-excursion
337 (save-excursion
338 (forward-line 1)
339 (delete-region (line-beginning-position) (1+ (line-end-position))))
340 (notes-new-underline-line)))
341
342 (defun notes-mode-initialize-note-from-cache ()
343 "Build a new note from the cache. Return valid cache contents or nil."
344 (save-excursion
345 (let*
346 ((new-buffer (current-buffer))
347 (cache-file (expand-file-name "mknew.cache" notes-dir))
348 (buf (find-file cache-file))
349 magic-line
350 prev-file
351 this-file
352 cache-contents
353 m
354 (result
355 (if (and buf
356 (>= (count-lines (point-min) (point-max)) 3))
357 (progn
358 ;; If you know a more elegant way to extact the first
359 ;; three lines of a file, please let me know.
360 (goto-char (point-min))
361 (setq m (point))
362 (forward-line 1)
363 (setq magic-line (buffer-substring m (- (point) 1)))
364 (setq m (point))
365 (forward-line 1)
366 (setq prev-file (buffer-substring m (- (point) 1)))
367 (setq m (point))
368 (forward-line 1)
369 (setq this-file (buffer-substring m (- (point) 1)))
370 (setq cache-contents (buffer-substring (point) (point-max)))
371 (bury-buffer buf)
372 ;; is cache valid?
373 (if
374 (and
375 (string-equal magic-line "mknew.cache 830494922")
376 (file-newer-than-file-p cache-file prev-file)
377 (string-equal (file-name-nondirectory this-file)
378 (file-name-nondirectory (buffer-file-name
379 new-buffer))))
380 cache-contents
381 nil))
382 nil)))
383 ;; Kill the buffer to avoid "buf changed, reload?" warnings.
384 (if buf
385 (kill-buffer buf))
386 result)))
387
388 (defun notes-mode-initialize-note ()
389 "Fill in an empty new note.
390 Create any directories as necessary.
391 Use the mknew cache if possible."
392 (interactive)
393 (let
394 ((dir (directory-file-name (file-name-directory (buffer-file-name)))))
395 (if (file-exists-p dir)
396 t
397 (make-directory dir t)
398 (message "New intermediate directory created.")))
399 (if notes-mode-initialization-program
400 (let
401 ((cache-contents (notes-mode-initialize-note-from-cache)))
402 (if cache-contents
403 (insert cache-contents)
404 (shell-command-on-region
405 (point-min)
406 (point-max)
407 (concat (expand-file-name notes-mode-initialization-program
408 notes-bin-dir)
409 " '"
410 ;; FIXME: Use shell-quote-argument.
411 (buffer-file-name) "'") 't)))))
412
413 \f
414 ;;;
415 ;;; encryption
416 ;; requires "PEM - PGP Enhanced Messaging for GNU Emacs"
417 ;; from Roy Frederick Busdiecker, III (Rick)
418 ;; or mailcrypt 3.4.x or >=3.5.x
419 ;;
420
421 (defvar notes-encryption-library
422 'mailcrypt
423 ; (cond
424 ; ((fboundp 'mc-encrypt-region) 'mailcrypt)
425 ; ((fboundp 'npgp:encrypt-region) 'npgp)
426 ; (t nil))
427 "PGP library to use.")
428
429 (defvar notes-encryption-sub-library
430 'gpg
431 "Variant of mailcrypt to use (`pgp', `pgp50', or `gpg').")
432
433 (defvar notes-encryption-npgp-userid nil
434 "PGP key for the current user.")
435
436 (defvar notes-encryption-npgp-key-id nil
437 "Keyid of PGP key for the current user.
438 Useful if your \\[user-full-name] doesn't match a unique key.
439 Should have a leading 0x.")
440
441 (defun notes-encryption-npgp-userid ()
442 "Return notes-encryption-userid, initializing it if necessary."
443 (require 'pam)
444 (if (and notes-encryption-userid
445 npgp:*pass-phrases*)
446 notes-encryption-userid
447 (setq notes-encryption-userid
448 (list
449 (if notes-encryption-key-id
450 (npgp:get-key-by-key-id notes-encryption-key-id)
451 (pam:read-name-key (user-full-name)))))))
452
453 (defun notes-encryption-mailcrypt-keyid ()
454 "Do the right thing."
455 (require 'mailcrypt)
456 (cond
457 ((eq notes-encryption-sub-library 'pgp)
458 (cdr (mc-pgp-lookup-key mc-pgp-user-id)))
459 ((eq notes-encryption-sub-library 'pgp50)
460 (cdr (mc-pgp50-lookup-key mc-pgp50-user-id)))
461 ((eq notes-encryption-sub-library 'gpg)
462 (cdr (mc-gpg-lookup-key mc-gpg-user-id)))
463 (t (error "notes-encryption-decrypt-region: no pgp sub-library."))))
464
465 (defun notes-encryption-load-mailcrypt ()
466 (require 'mailcrypt)
467 ;; ick ick ick this code needs to be cleaned up
468 (cond
469 ((null (eq notes-encryption-library 'mailcrypt))
470 t)
471 ((eq notes-encryption-sub-library 'pgp)
472 (load-library "mc-pgp"))
473 ((eq notes-encryption-sub-library 'pgp50)
474 (load-library "mc-pgp5"))
475 ((eq notes-encryption-sub-library 'gpg)
476 (load-library "mc-gpg"))
477 (t (error "notes-encryption-load-mailcrypt: no pgp sub-library."))))
478
479 (defun notes-encryption-decrypt-region (start end)
480 (cond
481 ((eq notes-encryption-library 'npgp)
482 (require 'pam)
483 (require 'npgp)
484 (npgp:decrypt-region start end))
485 ((eq notes-encryption-library 'mailcrypt)
486 (notes-encryption-load-mailcrypt)
487 (cond
488 ((eq notes-encryption-sub-library 'pgp)
489 (mc-pgp-decrypt-region start end))
490 ((eq notes-encryption-sub-library 'pgp50)
491 (mc-pgp50-decrypt-region start end))
492 ((eq notes-encryption-sub-library 'gpg)
493 (mc-gpg-decrypt-region start end))
494 (t (error "notes-encryption-decrypt-region: no pgp sub-library."))))
495 (t (error "notes-encryption-decrypt-region: no pgp library."))))
496
497 (defun notes-encryption-encrypt-region (start end)
498 (cond
499 ((eq notes-encryption-library 'npgp)
500 (npgp:encrypt-region (notes-encryption-npgp-userid) start end))
501 ((eq notes-encryption-library 'mailcrypt)
502 (notes-encryption-load-mailcrypt)
503 (let ((old-sign mc-pgp-always-sign)
504 old-comment recipients)
505 (setq mc-pgp-always-sign 'never
506 recipients (list (notes-encryption-mailcrypt-keyid)))
507 (cond
508 ((eq notes-encryption-sub-library 'pgp)
509 (setq old-comment mc-pgp-comment
510 mc-pgp-comment "")
511 (mc-pgp-encrypt-region recipients start end
512 (notes-encryption-mailcrypt-keyid) nil)
513 (setq mc-pgp-comment old-comment))
514 ((eq notes-encryption-sub-library 'pgp50)
515 (setq old-comment mc-pgp50-comment
516 mc-pgp50-comment "")
517 (mc-pgp50-encrypt-region recipients start end
518 (notes-encryption-mailcrypt-keyid) nil)
519 (setq mc-pgp50-comment old-comment))
520 ((eq notes-encryption-sub-library 'gpg)
521 (setq old-comment mc-gpg-comment
522 mc-gpg-comment "")
523 (mc-gpg-encrypt-region recipients start end
524 (notes-encryption-mailcrypt-keyid) nil)
525 (setq mc-gpg-comment old-comment))
526 (t (error "notes-encryption-decrypt-region: no gpg sub-library.")))
527 (setq mc-pgp-always-sign old-sign)))
528 (t (error "notes-encryption-decrypt-region: no pgp library."))))
529
530 (defun notes-encrypt-note (prefix)
531 "Encrypt the current note for the current user. With PREFIX, start from point."
532 (interactive "P")
533 (save-excursion
534 (let (start end)
535 ;; Unless a prefix arg, start at beginning-of-note.
536 (if prefix
537 nil
538 (if (not (looking-at notes-beginning-of-defun-regexp))
539 (notes-beginning-of-defun))
540 ;; skip over the header
541 (while (and (or (looking-at notes-beginning-of-defun-regexp)
542 (looking-at "^-+$")
543 (looking-at "^\\(prev\\|next\\): ")
544 (looking-at "^[ \t]*$"))
545 (< (point) (point-max)))
546 (forward-line 1)))
547 (setq start (point))
548 ;; sanity check
549 (if (re-search-forward "^-----BEGIN PGP MESSAGE"
550 (progn
551 (save-excursion
552 (notes-end-of-defun)
553 (point))) t)
554 (error "Note is already encrypted."))
555 ;; find the end
556 (notes-end-of-defun)
557 (while (or (looking-at notes-beginning-of-defun-regexp)
558 (looking-at "^[ \t]*$"))
559 (forward-line -1))
560 (forward-line 1)
561 (setq end (point))
562 (notes-encryption-encrypt-region start end))))
563
564 (defun notes-decrypt-note ()
565 "Decrypt the current note for the current user."
566 (interactive)
567 (save-excursion
568 (if (not (looking-at notes-beginning-of-defun-regexp))
569 (notes-beginning-of-defun))
570 (if (null (re-search-forward "^-----BEGIN PGP"
571 (progn
572 (save-excursion
573 (notes-end-of-defun)
574 (point))) t))
575 (error "Note is not encrypted."))
576 (beginning-of-line)
577 (let ((start (point)))
578 (if (null (re-search-forward "^-----END PGP"
579 (progn
580 (save-excursion
581 (notes-end-of-defun)
582 (point))) t))
583 (error "Could not find end of encrypted note."))
584 (forward-line)
585 (beginning-of-line)
586 (notes-encryption-decrypt-region start (point)))))
587
588 \f
589 ;;;
590 ;;; notes or notes-index?
591 ;;;
592 (defun notes-summarize-subject (regexp-subject &optional subject)
593 "* Collect all of a subject."
594 (interactive "P")
595 (require 'notes-index-mode)
596 (if (null subject)
597 (cond
598 ((eq major-mode 'notes-mode)
599 (setq subject (notes-extract-subject nil t)))
600 ((eq major-mode 'notes-index-mode)
601 (setq subject (notes-index-extract-subject)))))
602 (if (null subject)
603 (error "notes-summarize-subject: no subject specified or inferable."))
604 (let
605 ((buf (get-buffer-create (concat "*notes on " subject "*"))))
606 (pop-to-buffer buf)
607 (erase-buffer)
608 (apply 'call-process (expand-file-name "catsubject" notes-bin-dir)
609 nil buf t
610 (if regexp-subject
611 (list "-m" subject)
612 (list subject)))
613 (notes-mode)))
614
615 \f
616 ;;;
617 ;;; notes-rename-subject
618 ;;;
619 (defun notes-rename-subject ()
620 "* Rename the current subject.
621 Assumes working next/prev linkage between the entries."
622 (interactive)
623 (let ((subject (notes-extract-subject)))
624 (condition-case nil
625 (progn
626 (end-of-line)
627 (beginning-of-defun)
628 (if (not (looking-at "* "))
629 (error "confused"))
630 (forward-char 2)
631 (error "not yet done")
632 )
633 (error nil))))
634
635 \f
636 ;;;
637 ;;; notes-mode
638 ;;;
639
640 (defvar notes-mode-map
641 (let ((map (make-sparse-keymap)))
642 ;; Random key-bindings.
643 (define-key map "\M-\C-a" 'notes-beginning-of-defun)
644 (define-key map "\M-\C-e" 'notes-end-of-defun)
645 (define-key map "\C-c\C-d" 'notes-decrypt-note)
646 (define-key map "\C-c\C-e" 'notes-encrypt-note)
647 (define-key map "\C-c\r" 'notes-w3-follow-link)
648 (define-key map "\C-c\C-p" 'notes-follow-prev-link)
649 (define-key map "\C-c\C-n" 'notes-follow-next-link)
650 (define-key map "\C-c\C-i" 'notes-goto-index-entry)
651 (define-key map "\C-c\C-k" 'notes-current-url-as-kill)
652 (define-key map "\C-c\C-s" 'notes-summarize-subject)
653 (define-key map "\C-c-" 'notes-underline-line)
654 ;; FIXME: Use completion-at-point-functions instead.
655 (define-key map "\t" 'notes-complete-subject)
656 ;; FIXME: Use post-self-insert-hook instead.
657 (define-key map "\r" 'notes-electric-return)
658 (define-key map "\n" 'notes-electric-return) ; a more common synonym
659 (notes-platform-bind-mouse map 'S-mouse-2 'notes-w3-follow-link-mouse)
660 map))
661
662 ;;;###autoload
663 (define-derived-mode notes-mode indented-text-mode "Notes"
664 "Enable notes-mode for a buffer.
665
666 Inside a notes buffer one can click on URLs and follow them to
667 other notes files.
668
669 See the file notes-variables.el for all customization options.
670 To change options, (require 'notes-variables) in your .emacs
671 and then change things.
672
673 Subjects in notes mode are lines beginning with an asterisk
674 and underlined with dashes. Subjects can be completed
675 with \\[notes-complete-subject] and are automatically underlined.
676
677 You may wish to add this code to your .emacs file:
678 (add-to-list 'auto-mode-alist
679 (cons \"/9[0-9][0-9][0-9][0-9][0-9].?\\\\'\" 'notes-mode))
680 (define-key global-map [?\\C-c ?n] 'notes-index-todays-link)
681 to automatically enter notes mode.
682
683 I have two suggestions for how to organize your notes files.
684 First, I collect my notes into a separate file per day. (If you have
685 fewer notes, you may find once-per-week or month more suitable.)
686 Second, at the beginning of each file I have a subject \"* Today\".
687 Since every file has this subject, I can use its prev and next links
688 to easily move around the collection of files.
689
690 The key-bindings of this mode are:
691 \\{notes-mode-map}"
692 (notes-platform-init)
693
694 ;; Now set up the mode.
695 (auto-fill-mode 1)
696
697 ;; Imenu stuff.
698 (set (make-local-variable 'imenu-prev-index-position-function)
699 'notes-beginning-of-defun)
700 (set (make-local-variable 'imenu-extract-index-name-function)
701 'notes-extract-subject)
702
703 (set (make-local-variable 'font-lock-defaults)
704 `(notes-font-lock-keywords
705 t nil nil beginning-of-line))
706
707 ;; Finally, try to fill in an empty note.
708 (if (zerop (buffer-size))
709 (notes-mode-initialize-note))
710
711 ;; Enable outline-minor-mode (forcebly, in case someone already
712 ;; has it in their text-mode hook). Bug found by
713 ;; Nils Ackermann <nils@nieback.de>.
714 (if notes-use-outline-mode
715 (outline-minor-mode 1)))
716
717
718
719 \f
720 ;;;
721
722 (run-hooks 'notes-mode-load-hooks)
723 (provide 'notes-mode)
724 ;;; notes-mode.el ends here