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.
36 (defcustom mu-registration-file (expand-file-name "~/.mu-cite.el")
37 "The name of the user environment file for mu-cite."
41 (defcustom mu-registration-file-modes 384
42 "Mode bits of `mu-registration-file', as an integer."
46 (defcustom mu-registration-file-coding-system-for-read nil
47 "Coding system used when reading a registration file."
50 (defcustom mu-cite-allow-null-string-registration nil
51 "If non-nil, null-string citation-name is registered."
55 (defvar mu-registration-symbol 'mu-citation-name-alist
56 "*Name of the variable to register citation prefix strings.")
58 (defvar mu-registration-file-coding-system nil
59 "Coding system used when writing a current registration file.")
61 (defvar mu-citation-name-alist nil)
63 (defvar mu-register-history nil)
65 (eval-when-compile (require 'static))
67 (static-when (featurep 'xemacs)
68 (define-obsolete-variable-alias
69 'mu-cite/registration-file 'mu-registration-file)
71 (define-obsolete-variable-alias
72 'mu-cite/allow-null-string-registration
73 'mu-cite-allow-null-string-registration)
75 (define-obsolete-variable-alias
76 'mu-cite/registration-symbol 'mu-registration-symbol)
80 ;;; @ load / save registration file
83 (defun mu-cite-load-registration-file ()
84 (if (file-readable-p mu-registration-file)
86 (insert-file-contents-as-coding-system
87 mu-registration-file-coding-system-for-read
89 (setq mu-registration-file-coding-system
90 buffer-file-coding-system)
91 (let ((exp (read (current-buffer))))
92 (or (eq (car (cdr exp)) mu-registration-symbol)
93 (setcar (cdr exp) mu-registration-symbol))
96 (defun mu-cite-save-registration-file ()
98 (insert ";;; " (file-name-nondirectory mu-registration-file) "\n")
99 (insert ";;; This file is generated automatically by mu-cite "
100 mu-cite-version "\n\n")
102 (symbol-name mu-registration-symbol)
105 (function prin1-to-string)
106 mu-citation-name-alist "\n "))
109 (file-name-nondirectory mu-registration-file)
111 (write-region-as-coding-system mu-registration-file-coding-system
112 (point-min)(point-max)
113 mu-registration-file nil 'nomsg)
115 (set-file-modes mu-registration-file mu-registration-file-modes)
119 ;;; @ database accessors
122 ;; get citation-name from the database
123 (defun mu-register-get-citation-name (from)
124 (cdr (assoc from mu-citation-name-alist)))
126 ;; register citation-name to the database
127 (defun mu-register-add-citation-name (name from)
128 (setq mu-citation-name-alist
129 (put-alist from name mu-citation-name-alist))
130 (mu-cite-save-registration-file))
137 (defun mu-cite-get-prefix-method ()
138 (or (mu-register-get-citation-name (mu-cite-get-value 'address))
142 (defun mu-cite-get-prefix-register-method ()
143 (let ((addr (mu-cite-get-value 'address)))
144 (or (mu-register-get-citation-name addr)
146 (read-string "Citation name? "
147 (or (mu-cite-get-value 'x-attribution)
148 (mu-cite-get-value 'full-name))
149 'mu-register-history)))
150 (when (and (or mu-cite-allow-null-string-registration
151 (not (string-equal return "")))
152 (y-or-n-p (format "Register \"%s\"? " return)))
153 (mu-register-add-citation-name return addr))
157 (defun mu-cite-get-prefix-register-verbose-method ()
158 (let* ((addr (mu-cite-get-value 'address))
159 (return1 (mu-register-get-citation-name addr))
160 (return (read-string "Citation name? "
162 (mu-cite-get-value 'x-attribution)
163 (mu-cite-get-value 'full-name))
164 'mu-register-history)))
165 (when (and (or mu-cite-allow-null-string-registration
166 (not (string-equal return "")))
167 (not (string-equal return return1))
168 (y-or-n-p (format "Register \"%s\"? " return)))
169 (mu-register-add-citation-name return addr))
176 (provide 'mu-register)
178 (mu-cite-load-registration-file)
180 ;;; mu-register.el ends here