Add arch tagline
[bpt/emacs.git] / lisp / textmodes / remember-diary.el
1 ;;; remember-diary --- extracting diary information from buffers
2
3 ;; Copyright (C) 1999, 2000, 2001, 2004, 2007 Free Software Foundation, Inc.
4
5 ;; Author: Sacha Chua <sacha@free.net.ph>
6 ;; Created: 24 Mar 2004
7 ;; Keywords: data memory todo pim diary
8 ;; URL: http://gna.org/projects/remember-el/
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;; This module recognizes entries of the form
30 ;;
31 ;; DIARY: ....
32 ;;
33 ;; and puts them in your ~/.diary (or remember-diary-file) together
34 ;; with an annotation. Planner-style dates (yyyy.mm.dd) are converted
35 ;; to yyyy-mm-dd so that diary can understand them.
36 ;;
37 ;; For example:
38 ;;
39 ;; DIARY: 2003.08.12 Sacha's birthday
40 ;;
41 ;; is stored as
42 ;;
43 ;; 2003.08.12 Sacha's birthday [[/home/sacha/notebook/emacs/emacs-wiki/remember-diary.el]]
44 ;;
45 ;; To use, add the following to your .emacs:
46 ;;
47 ;; (require 'remember-diary)
48 ;; ;; This should be before other entries that may return t
49 ;; (add-to-list 'remember-handler-functions 'remember-diary-extract-entries)
50 ;;
51
52 (require 'remember)
53 (require 'diary-lib)
54
55 ;;; Code:
56 (defcustom remember-diary-file diary-file
57 "*File for extracted diary entries."
58 :type 'file
59 :group 'remember)
60
61 (defun remember-diary-convert-entry (entry)
62 "Translate MSG to an entry readable by diary."
63 (save-match-data
64 (when remember-annotation
65 (setq entry (concat entry " " remember-annotation)))
66 (if (string-match "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" entry)
67 (replace-match
68 (if european-calendar-style
69 (concat (match-string 3 entry) "/"
70 (match-string 2 entry) "/"
71 (match-string 1 entry))
72 (concat (match-string 2 entry) "/"
73 (match-string 3 entry) "/"
74 (match-string 1 entry)))
75 t t entry)
76 entry)))
77
78 ;;;###autoload
79 (defun remember-diary-extract-entries ()
80 "Extract diary entries from the region."
81 (save-excursion
82 (goto-char (point-min))
83 (let (list)
84 (while (re-search-forward "^DIARY:\\s-*\\(.+\\)" nil t)
85 (add-to-list 'list (remember-diary-convert-entry (match-string 1))))
86 (when list
87 (make-diary-entry (mapconcat 'identity list "\n")
88 nil remember-diary-file))
89 nil))) ;; Continue processing
90
91 (provide 'remember-diary)
92
93 ;; arch-tag: bda8a3f8-9a9b-46aa-8493-d71d7f1e445d
94 ;;; remember-diary.el ends here