Comments were modified.
[elisp/mu-cite.git] / mu-register.el
1 ;;;
2 ;;; mu-register.el --- `register' function for mu-cite.
3 ;;;
4 ;;; Copyright (C) 1995 MINOURA Makoto
5 ;;;
6 ;;; Author: MINOURA Makoto <minoura@leo.bekkoame.or.jp>
7 ;;;         modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Created: 1995/12/27 by MINOURA Makoto <minoura@leo.bekkoame.or.jp>
9 ;;; Version:
10 ;;;     $Id: mu-register.el,v 1.4 1996-01-15 19:32:00 morioka Exp $
11 ;;;
12 ;;; This file is part of tl (Tiny Library).
13 ;;;
14 ;;; This program is free software; you can redistribute it and/or
15 ;;; modify it under the terms of the GNU General Public License as
16 ;;; published by the Free Software Foundation; either version 2, or
17 ;;; (at your option) any later version.
18 ;;;
19 ;;; This program 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 GNU
22 ;;; General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with This program.  If not, write to the Free Software
26 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27
28 ;;; Commentary:
29 ;;;
30 ;;; - How to install.
31 ;;;   1. bytecompile this file and copy it to the apropriate directory.
32 ;;;   2. put the following lines to your .emacs.
33 ;;;     (add-hook 'mu-cite-load-hook
34 ;;;                (function
35 ;;;                 (lambda ()
36 ;;;                   (require 'mu-register))))
37 ;;;   3. you can use the keyword `registered' in your
38 ;;;    mu-cite/top-form and mu-cite/prefix-form, for example:
39 ;;;     (setq mu-cite/prefix-format (list 'registered "> "))
40 ;;;
41 ;;; - ChangeLog.
42 ;;;   Wed Dec 27 14:28:17 1995  MINOURA Makoto <minoura@leo.bekkoame.or.jp>
43 ;;;
44 ;;;     * Written.
45 ;;;
46 \f
47 ;;; Code:
48
49 ;;; @ variables
50 ;;;
51
52 (defvar mu-register/registration-file
53   (expand-file-name "~/.mu-register")
54   "*The name of the user environment file for mu-register.")
55
56 (defvar mu-register/citation-name-alist nil)
57 (load mu-register/registration-file t t t)
58
59 (defvar mu-register/minibuffer-history nil)
60
61
62 ;;; @ functions
63 ;;;
64
65 ;; get citation-name from the database
66 (defsubst mu-register/get-citation-name (from)
67   (cdr (assoc from mu-register/citation-name-alist)))
68
69 ;; register citation-name to the database
70 (defun mu-register/add-citation-name (name from)
71   (let* ((elt (assoc from mu-register/citation-name-alist)))
72     (if elt
73         (setq mu-register/citation-name-alist
74               (delq elt mu-register/citation-name-alist)))
75     (setq elt (cons from name))
76     (setq mu-register/citation-name-alist
77           (cons elt
78                 mu-register/citation-name-alist))
79     (mu-register/save-to-file)
80     ))
81
82 ;; main function
83 (defun mu-register/citation-name ()
84   (let* ((from
85           (rfc822/address-string
86            (car (rfc822/parse-address
87                  (rfc822/lexical-analyze
88                   (mu-cite/get-value 'from))))))
89          (fullname (mu-cite/get-value 'full-name))
90          (return1
91           (mu-register/get-citation-name from))
92          (return))
93     (if (null return1)
94         (setq return1 fullname))
95     (setq return
96           (read-string "Citation name? "
97                        return1
98                        'mu-register/minibuffer-history))
99     (if (not (string-equal return return1))
100         (let ((ans)
101               (cursor-in-echo-area t))
102           (while (null ans)
103             (message (format "Register \"%s\" (y/n)? " return))
104             (setq ans (read-event))
105             (if (not (or (eq ans ?y)
106                          (eq ans ?n)))
107                 (setq ans nil)))
108           (message "")
109           (if (eq ans ?y)
110               (mu-register/add-citation-name return from))))
111     return))
112
113 ;; save to file
114 (defun mu-register/save-to-file ()
115   (let* ((filename mu-register/registration-file)
116          (buffer (get-buffer-create " *mu-register*")))
117     (save-excursion
118       (set-buffer buffer)
119       (setq buffer-file-name filename)
120       (erase-buffer)
121       (insert ";; generated automatically by mu-register.\n")
122       (insert "(setq mu-register/citation-name-alist\n\
123  (quote\n\
124   ")
125       (insert (prin1-to-string mu-register/citation-name-alist))
126       (insert "))\n")
127       (save-buffer))
128     (kill-buffer buffer)))
129 \f
130
131 ;;; @ Installation
132 ;;;
133
134 (require 'mu-cite)
135 (set-alist 'mu-cite/default-methods-alist
136            'registered 
137            (function mu-register/citation-name))
138
139
140 ;;; @ end
141 ;;;
142
143 (provide 'mu-register)
144
145 ;;; mu-register.el ends here