1 ;;; mu-register.el --- registration feature of mu-cite
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MINOURA Makoto <minoura@netlaputa.or.jp>
6 ;; MORIOKA Tomohiko <tomo@m17n.org>
7 ;;; Created: 1995-12-27 by MINOURA Makoto
8 ;; Maintainer: Katsumi Yamaoka <yamaoka@jpl.org>
9 ;; Keywords: registration, citation, mail, news
11 ;; This file is part of MU (Message Utilities).
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License 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,
26 ;; Boston, MA 02111-1307, USA.
32 (eval-when-compile (require 'static))
38 (defcustom mu-registration-file (expand-file-name "~/.mu-cite.el")
39 "The name of the user environment file for mu-cite."
43 (defcustom mu-registration-file-modes 384
44 "Mode bits of `mu-registration-file', as an integer."
48 (defcustom mu-registration-file-coding-system-for-read nil
49 "Coding system used when reading a registration file."
52 (defcustom mu-cite-allow-null-string-registration nil
53 "If non-nil, null-string citation-name can be registered."
57 (defvar mu-registration-symbol 'mu-citation-name-alist
58 "*Name of the variable to register citation prefix strings.")
60 (defvar mu-registration-file-coding-system nil
61 "Coding system used when writing a current registration file.")
63 (defvar mu-register-history nil)
66 ;;; @ load / save registration file
69 (defun mu-cite-load-registration-file ()
70 (if (file-readable-p mu-registration-file)
72 (if mu-registration-file-coding-system-for-read
73 (insert-file-contents-as-coding-system
74 mu-registration-file-coding-system-for-read
76 (insert-file-contents mu-registration-file))
77 (setq mu-registration-file-coding-system
79 ((boundp 'buffer-file-coding-system)
80 (symbol-value 'buffer-file-coding-system))
81 ((boundp 'file-coding-system)
82 (symbol-value 'file-coding-system))
85 (let ((exp (read (current-buffer))))
86 (or (eq (car (cdr exp)) mu-registration-symbol)
87 (setcar (cdr exp) mu-registration-symbol))
89 (or (boundp mu-registration-symbol)
90 (set mu-registration-symbol nil)))
92 (defun mu-cite-save-registration-file ()
94 (insert ";;; " (file-name-nondirectory mu-registration-file) "\n")
95 (insert ";;; This file is generated automatically by mu-cite "
96 mu-cite-version "\n\n")
98 (symbol-name mu-registration-symbol)
105 (mu-cite-remove-text-properties (car elem)))
107 (mu-cite-remove-text-properties (cdr elem))))))
108 (symbol-value mu-registration-symbol) "\n "))
111 (file-name-nondirectory mu-registration-file)
113 (write-region-as-coding-system mu-registration-file-coding-system
114 (point-min)(point-max)
115 mu-registration-file nil 'nomsg)
117 (set-file-modes mu-registration-file mu-registration-file-modes)
121 ;;; @ database accessors
124 ;; get citation-name from the database
125 (defun mu-register-get-citation-name (from)
126 (cdr (assoc from (symbol-value mu-registration-symbol))))
128 ;; register citation-name to the database
129 (defun mu-register-add-citation-name (name from)
130 (set-alist mu-registration-symbol from name)
131 (mu-cite-save-registration-file))
138 (defun mu-cite-get-prefix-method ()
139 (or (mu-register-get-citation-name (mu-cite-get-value 'address))
143 (defun mu-cite-get-prefix-register-method ()
144 (let ((addr (mu-cite-get-value 'address)))
145 (or (mu-register-get-citation-name addr)
146 (let* ((minibuffer-allow-text-properties nil)
148 (mu-cite-remove-text-properties
149 (read-string "Citation name? "
150 (or (mu-cite-get-value 'x-attribution)
151 (mu-cite-get-value 'x-cite-me)
152 (mu-cite-get-value 'full-name))
153 'mu-register-history))))
155 (if (and (or mu-cite-allow-null-string-registration
156 (not (string-equal return "")))
157 (y-or-n-p (format "Register \"%s\"? " return)))
158 (mu-register-add-citation-name return addr))
162 (defun mu-cite-get-prefix-register-verbose-method ()
163 (let* ((addr (mu-cite-get-value 'address))
164 (return1 (mu-register-get-citation-name addr))
165 (minibuffer-allow-text-properties nil)
166 (return (mu-cite-remove-text-properties
167 (read-string "Citation name? "
169 (mu-cite-get-value 'x-attribution)
170 (mu-cite-get-value 'x-cite-me)
171 (mu-cite-get-value 'full-name))
172 'mu-register-history))))
173 (if (and (or mu-cite-allow-null-string-registration
174 (not (string-equal return "")))
175 (not (string-equal return return1))
176 (y-or-n-p (format "Register \"%s\"? " return)))
177 (mu-register-add-citation-name return addr))
184 (provide 'mu-register)
186 (mu-cite-load-registration-file)
188 ;;; mu-register.el ends here