1 ;;; mu-register.el --- registration feature of mu-cite
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 ;; 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., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, 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-write
49 (static-if (boundp 'MULE)
52 "Coding-system used when writing a registration file. If you set this
53 to nil, the value of `mu-registration-file-coding-system' will be used
57 (defcustom mu-cite-allow-null-string-registration nil
58 "If non-nil, null-string citation-name can be registered."
62 (defvar mu-registration-symbol 'mu-citation-name-alist
63 "*Name of the variable to register citation prefix strings.")
65 (defvar mu-registration-file-coding-system-for-read nil
66 "*Coding-system used when reading a registration file. Normally, you
67 have no need to set this option. If you have many friends in various
68 countries and the file contains their names in various languages, you
69 may avoid mis-decoding them by setting this option to `iso-2022-7bit'
70 or the other universal coding-system. Note that when you change this
71 value, you should save the file manually using the same coding-system
74 (defvar mu-registration-file-coding-system nil
75 "Internal variable used to keep a default coding-system for writing
76 a current registration file. The value will be renewed whenever a
77 registration file is read.")
79 (defvar mu-register-history nil)
82 ;;; @ load / save registration file
85 (defun mu-cite-load-registration-file ()
86 (if (file-readable-p mu-registration-file)
88 (set-buffer-multibyte t)
89 (if mu-registration-file-coding-system-for-read
90 (insert-file-contents-as-coding-system
91 mu-registration-file-coding-system-for-read
93 (insert-file-contents mu-registration-file))
94 (setq mu-registration-file-coding-system
96 ((boundp 'buffer-file-coding-system)
97 (symbol-value 'buffer-file-coding-system))
98 ((boundp 'file-coding-system)
99 (symbol-value 'file-coding-system))
102 (let ((exp (read (current-buffer))))
103 (or (eq (car (cdr exp)) mu-registration-symbol)
104 (setcar (cdr exp) mu-registration-symbol))
106 (or (boundp mu-registration-symbol)
107 (set mu-registration-symbol nil)))
109 (defun mu-cite-save-registration-file ()
111 (set-buffer-multibyte t)
112 (let ((name (file-name-nondirectory mu-registration-file))
113 (coding-system (or mu-registration-file-coding-system-for-write
114 mu-registration-file-coding-system)))
116 ;;; %s -*- mode: emacs-lisp; coding: %s -*-
117 ;; This file is generated automatically by MU-CITE v%s.
120 name coding-system mu-cite-version))
122 (symbol-name mu-registration-symbol)
129 (mu-cite-remove-text-properties (car elem)))
131 (mu-cite-remove-text-properties (cdr elem))))))
132 (symbol-value mu-registration-symbol) "\n\t"))
134 (insert ";;; " name " ends here\n")
135 (write-region-as-coding-system coding-system
136 (point-min) (point-max)
137 mu-registration-file nil 'nomsg)
139 (set-file-modes mu-registration-file mu-registration-file-modes)
143 ;;; @ database accessors
146 ;; get citation-name from the database
147 (defun mu-register-get-citation-name (from)
148 (cdr (assoc from (symbol-value mu-registration-symbol))))
150 ;; register citation-name to the database
151 (defun mu-register-add-citation-name (name from)
152 (set-alist mu-registration-symbol from name)
153 (mu-cite-save-registration-file))
160 (defun mu-cite-get-prefix-method ()
161 (or (mu-register-get-citation-name (mu-cite-get-value 'address))
165 (defun mu-cite-get-prefix-register-method ()
166 (let ((addr (mu-cite-get-value 'address)))
167 (or (mu-register-get-citation-name addr)
168 (let* ((minibuffer-allow-text-properties nil)
170 (mu-cite-remove-text-properties
171 (read-string "Citation name? "
172 (or (mu-cite-get-value 'x-attribution)
173 (mu-cite-get-value 'x-cite-me)
174 (mu-cite-get-value 'full-name))
175 'mu-register-history))))
177 (if (and (or mu-cite-allow-null-string-registration
178 (not (string-equal return "")))
179 (y-or-n-p (format "Register \"%s\"? " return)))
180 (mu-register-add-citation-name return addr))
184 (defun mu-cite-get-prefix-register-verbose-method ()
185 (let* ((addr (mu-cite-get-value 'address))
186 (return1 (mu-register-get-citation-name addr))
187 (minibuffer-allow-text-properties nil)
188 (return (mu-cite-remove-text-properties
189 (read-string "Citation name? "
191 (mu-cite-get-value 'x-attribution)
192 (mu-cite-get-value 'x-cite-me)
193 (mu-cite-get-value 'full-name))
194 'mu-register-history))))
195 (if (and (or mu-cite-allow-null-string-registration
196 (not (string-equal return "")))
197 (not (string-equal return return1))
198 (y-or-n-p (format "Register \"%s\"? " return)))
199 (mu-register-add-citation-name return addr))
206 (provide 'mu-register)
208 (mu-cite-load-registration-file)
210 ;;; mu-register.el ends here