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