1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
;;; mu-register.el --- registration feature of mu-cite
;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001
;; Free Software Foundation, Inc.
;; Author: MINOURA Makoto <minoura@netlaputa.or.jp>
;; MORIOKA Tomohiko <tomo@m17n.org>
;;; Created: 1995-12-27 by MINOURA Makoto
;; Maintainer: Katsumi Yamaoka <yamaoka@jpl.org>
;; Keywords: registration, citation, mail, news
;; This file is part of MU (Message Utilities).
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
(require 'mu-cite)
(eval-when-compile (require 'static))
;;; @ variables
;;;
(defcustom mu-registration-file (expand-file-name "~/.mu-cite.el")
"The name of the user environment file for mu-cite."
:type 'file
:group 'mu-cite)
(defcustom mu-registration-file-modes 384
"Mode bits of `mu-registration-file', as an integer."
:type 'integer
:group 'mu-cite)
(defcustom mu-registration-file-coding-system-for-write
(static-if (boundp 'MULE)
'*iso-2022-jp*
'iso-2022-7bit)
"Coding-system used when writing a registration file. If you set this
to nil, the value of `mu-registration-file-coding-system' will be used
for writing a file."
:group 'mu-cite)
(defcustom mu-cite-allow-null-string-registration nil
"If non-nil, null-string citation-name can be registered."
:type 'boolean
:group 'mu-cite)
(defvar mu-registration-symbol 'mu-citation-name-alist
"*Name of the variable to register citation prefix strings.")
(defvar mu-registration-file-coding-system-for-read nil
"*Coding-system used when reading a registration file. Normally, you
have no need to set this option. If you have many friends in various
countries and the file contains their names in various languages, you
may avoid mis-decoding them by setting this option to `iso-2022-7bit'
or the other universal coding-system. Note that when you change this
value, you should save the file manually using the same coding-system
in advance.")
(defvar mu-registration-file-coding-system nil
"Internal variable used to keep a default coding-system for writing
a current registration file. The value will be renewed whenever a
registration file is read.")
(defvar mu-register-history nil)
;;; @ load / save registration file
;;;
(defun mu-cite-load-registration-file ()
(if (file-readable-p mu-registration-file)
(with-temp-buffer
(set-buffer-multibyte t)
(if mu-registration-file-coding-system-for-read
(insert-file-contents-as-coding-system
mu-registration-file-coding-system-for-read
mu-registration-file)
(insert-file-contents mu-registration-file))
(setq mu-registration-file-coding-system
(static-cond
((boundp 'buffer-file-coding-system)
(symbol-value 'buffer-file-coding-system))
((boundp 'file-coding-system)
(symbol-value 'file-coding-system))
(t
nil)))
(let ((exp (read (current-buffer))))
(or (eq (car (cdr exp)) mu-registration-symbol)
(setcar (cdr exp) mu-registration-symbol))
(eval exp))))
(or (boundp mu-registration-symbol)
(set mu-registration-symbol nil)))
(defun mu-cite-save-registration-file ()
(with-temp-buffer
(set-buffer-multibyte t)
(let ((name (file-name-nondirectory mu-registration-file))
(coding-system (or mu-registration-file-coding-system-for-write
mu-registration-file-coding-system)))
(insert (format "\
;;; %s -*- mode: emacs-lisp; coding: %s -*-
;; This file is generated automatically by MU-CITE v%s.
"
name coding-system mu-cite-version))
(insert "(setq "
(symbol-name mu-registration-symbol)
"\n '(")
(insert (mapconcat
(function
(lambda (elem)
(format "(%s . %s)"
(prin1-to-string
(mu-cite-remove-text-properties (car elem)))
(prin1-to-string
(mu-cite-remove-text-properties (cdr elem))))))
(symbol-value mu-registration-symbol) "\n\t"))
(insert "))\n\n")
(insert ";;; " name " ends here\n")
(write-region-as-coding-system coding-system
(point-min) (point-max)
mu-registration-file nil 'nomsg)
(condition-case nil
(set-file-modes mu-registration-file mu-registration-file-modes)
(error nil)))))
;;; @ database accessors
;;;
;; get citation-name from the database
(defun mu-register-get-citation-name (from)
(cdr (assoc from (symbol-value mu-registration-symbol))))
;; register citation-name to the database
(defun mu-register-add-citation-name (name from)
(set-alist mu-registration-symbol from name)
(mu-cite-save-registration-file))
;;; @ methods
;;;
;;;###autoload
(defun mu-cite-get-prefix-method ()
(or (mu-register-get-citation-name (mu-cite-get-value 'address))
">"))
;;;###autoload
(defun mu-cite-get-prefix-register-method ()
(let ((addr (mu-cite-get-value 'address)))
(or (mu-register-get-citation-name addr)
(let* ((minibuffer-allow-text-properties nil)
(return
(mu-cite-remove-text-properties
(read-string "Citation name? "
(or (mu-cite-get-value 'x-attribution)
(mu-cite-get-value 'x-cite-me)
(mu-cite-get-value 'full-name))
'mu-register-history))))
(if (and (or mu-cite-allow-null-string-registration
(not (string-equal return "")))
(y-or-n-p (format "Register \"%s\"? " return)))
(mu-register-add-citation-name return addr))
return))))
;;;###autoload
(defun mu-cite-get-prefix-register-verbose-method ()
(let* ((addr (mu-cite-get-value 'address))
(return1 (mu-register-get-citation-name addr))
(minibuffer-allow-text-properties nil)
(return (mu-cite-remove-text-properties
(read-string "Citation name? "
(or return1
(mu-cite-get-value 'x-attribution)
(mu-cite-get-value 'x-cite-me)
(mu-cite-get-value 'full-name))
'mu-register-history))))
(if (and (or mu-cite-allow-null-string-registration
(not (string-equal return "")))
(not (string-equal return return1))
(y-or-n-p (format "Register \"%s\"? " return)))
(mu-register-add-citation-name return addr))
return))
;;; @ end
;;;
(provide 'mu-register)
(mu-cite-load-registration-file)
;;; mu-register.el ends here
|