- Don't require `cl' when compile time.
[elisp/mu-cite.git] / mu-cite.el
index fbbff6e..7c95678 100644 (file)
@@ -3,8 +3,7 @@
 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
 
 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
-;;         MINOURA Makoto <minoura@netlaputa.or.jp>
-;;         Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
+;;         Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
 ;; Maintainer: Katsumi Yamaoka <yamaoka@jpl.org>
 ;; Keywords: mail, news, citation
 
 
 ;;; Code:
 
-(eval-when-compile (require 'cl))
-
 ;; Pickup some macros, e.g. `with-temp-buffer', for old Emacsen.
 (require 'poe)
-
-;; Pickup `char-category' for XEmacs.
-(require 'emu)
-
-(require 'custom)
+(require 'pcustom)
 (require 'std11)
 (require 'alist)
 
+(autoload 'mu-cite-get-prefix-method "mu-register")
+(autoload 'mu-cite-get-prefix-register-method "mu-register")
+(autoload 'mu-cite-get-prefix-register-verbose-method "mu-register")
 
-;;; @ version
-;;;
-
-(defconst mu-cite-version "8.0")
+(autoload 'mu-bbdb-get-prefix-method "mu-bbdb")
+(autoload 'mu-bbdb-get-prefix-register-method "mu-bbdb")
+(autoload 'mu-bbdb-get-prefix-register-verbose-method "mu-bbdb")
 
 
-;;; @ obsoletes
+;;; @ version
 ;;;
 
-;; This part will be abolished in the future.
-
-;; variables
-(eval-when-compile (require 'static))
-
-(defvar mu-cite/registration-file)
-(defvar mu-cite-registration-file)
-(defmacro mu-cite-registration-file ()
-  (if (fboundp 'defvaralias)
-      'mu-cite-registration-file
-    '(if (boundp 'mu-cite/registration-file)
-        (prog1
-            (if (yes-or-no-p
-                 (format "Obsolete variable `%s' found, use anyway? "
-                         'mu-cite/registration-file))
-                mu-cite/registration-file
-              mu-cite-registration-file)
-          (message "You should use `%s' instead of `%s'."
-                   'mu-cite-registration-file 'mu-cite/registration-file)
-          (sleep-for 1))
-       mu-cite-registration-file)))
-
-(eval-and-compile
-  (defconst mu-cite-obsolete-variable-alist
-    '((mu-cite/allow-null-string-registration
-       mu-cite-allow-null-string-registration)
-      (mu-cite/citation-name-alist     mu-cite-citation-name-alist)
-      (mu-cite/cited-prefix-regexp     mu-cite-cited-prefix-regexp)
-      (mu-cite/default-methods-alist   mu-cite-default-methods-alist)
-      (mu-cite/instantiation-hook      mu-cite-instantiation-hook)
-      (mu-cite/minibuffer-history      mu-cite-minibuffer-history)
-      (mu-cite/ml-count-field-list     mu-cite-ml-count-field-list)
-      (mu-cite/post-cite-hook          mu-cite-post-cite-hook)
-      (mu-cite/pre-cite-hook           mu-cite-pre-cite-hook)
-      (mu-cite/prefix-format           mu-cite-prefix-format)
-      (mu-cite/registration-file       mu-cite-registration-file)
-      (mu-cite/top-format              mu-cite-top-format)))
-
-  (mapcar
-   (function
-    (lambda (elem)
-      (apply (function make-obsolete-variable) elem)
-      (when (boundp (car elem))
-       (apply (function message)
-              "WARNING: `%s' is an obsolete variable, use `%s' instead."
-              elem))
-      (static-if (fboundp 'defvaralias) ; It may exists in XEmacs.
-         (apply (function defvaralias) elem)
-       (when (boundp (car elem))
-         (eval (list 'defvar (cadr elem) (car elem)))))))
-   mu-cite-obsolete-variable-alist)
-  )
-
-;; functions
-(eval-and-compile
-  (defconst mu-cite-obsolete-function-alist
-    '((mu-cite/add-citation-name       mu-cite-add-citation-name)
-      (mu-cite/cite-original           mu-cite-original)
-      (mu-cite/eval-format             mu-cite-eval-format)
-      (mu-cite/get-citation-name       mu-cite-get-citation-name)
-      (mu-cite/get-field-value         mu-cite-get-field-value)
-      (mu-cite/get-ml-count-method     mu-cite-get-ml-count-method)
-      (mu-cite/get-prefix-method       mu-cite-get-prefix-method)
-      (mu-cite/get-prefix-register-method
-       mu-cite-get-prefix-register-method)
-      (mu-cite/get-prefix-register-verbose-method
-       mu-cite-get-prefix-register-verbose-method)
-      (mu-cite/get-value               mu-cite-get-value)
-      (mu-cite/load-registration-file  mu-cite-load-registration-file)
-      (mu-cite/make-methods            mu-cite-make-methods)
-      (mu-cite/save-registration-file  mu-cite-save-registration-file)))
-
-  (mapcar
-   (function (lambda (elem)
-              (apply (function define-obsolete-function-alias) elem)))
-   mu-cite-obsolete-function-alist)
-  )
+(defconst mu-cite-version "8.0")
 
 
 ;;; @ set up
                   (if id
                       (format ">>>>> In %s \n" id)
                     "")))))
+       (cons 'x-attribution
+             (function
+              (lambda ()
+                (mu-cite-get-field-value "X-Attribution"))))
+       ;; mu-register
        (cons 'prefix (function mu-cite-get-prefix-method))
        (cons 'prefix-register
              (function mu-cite-get-prefix-register-method))
        (cons 'prefix-register-verbose
              (function mu-cite-get-prefix-register-verbose-method))
-       (cons 'x-attribution
-             (function
-              (lambda ()
-                (mu-cite-get-field-value "X-Attribution"))))
+       ;; mu-bbdb
+       (cons 'bbdb-prefix
+             (function mu-bbdb-get-prefix-method))
+       (cons 'bbdb-prefix-register
+             (function mu-bbdb-get-prefix-register-method))
+       (cons 'bbdb-prefix-register-verbose
+             (function mu-bbdb-get-prefix-register-verbose-method))
        ))
 
 
@@ -296,119 +223,15 @@ Use this hook to add your own methods to `mu-cite-default-methods-alist'."
   "Alist major-mode vs. function to get field-body of header.")
 
 (defun mu-cite-get-field-value (name)
+  "Return the value of the header field NAME.
+If the field is not found in the header, a method function which is
+registered in variable `mu-cite-get-field-value-method-alist' is called."
   (or (std11-field-body name)
       (let ((method (assq major-mode mu-cite-get-field-value-method-alist)))
        (when method
          (funcall (cdr method) name)))))
 
 
-;;; @ prefix registration
-;;;
-
-(defcustom mu-cite-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-cite-allow-null-string-registration nil
-  "If non-nil, null-string citation-name is registered."
-  :type 'boolean
-  :group 'mu-cite)
-
-(defcustom mu-cite-registration-file-coding-system-for-read nil
-  "Coding system for reading registration file."
-  :group 'mu-cite)
-
-(defcustom mu-cite-registration-file-coding-system-for-write nil
-  "Coding system for writing registration file."
-  :group 'mu-cite)
-
-(defcustom mu-cite-registration-file-modes 384
-  "Mode bits of `mu-cite-registration-file', as an integer."
-  :type 'integer
-  :group 'mu-cite)
-
-(defvar mu-cite-registration-symbol 'mu-cite-citation-name-alist)
-
-(defvar mu-cite-citation-name-alist nil)
-(unless (eq 'mu-cite-citation-name-alist mu-cite-registration-symbol)
-  (setq mu-cite-citation-name-alist
-       (symbol-value mu-cite-registration-symbol)))
-(defvar mu-cite-minibuffer-history nil)
-
-;; get citation-name from the database
-(defun mu-cite-get-citation-name (from)
-  (cdr (assoc from mu-cite-citation-name-alist)))
-
-;; register citation-name to the database
-(defun mu-cite-add-citation-name (name from)
-  (setq mu-cite-citation-name-alist
-       (put-alist from name mu-cite-citation-name-alist))
-  (mu-cite-save-registration-file))
-
-;; load/save registration file
-;;(defun mu-cite-load-registration-file ()
-;;  (let ((file mu-cite-registration-file))
-;;    (when (file-readable-p file)
-;;      (let ((alist (with-temp-buffer
-;;                  (eval
-;;                   (` (let ((, mu-cite-registration-symbol))
-;;                        (insert-file-contents-as-coding-system
-;;                         mu-cite-registration-file-coding-system-for-read
-;;                         file)
-;;                        (condition-case nil
-;;                            (progn
-;;                              (eval-current-buffer)
-;;                              (, mu-cite-registration-symbol))
-;;                          (error nil))))))))
-;;     (when alist
-;;       (setq mu-cite-citation-name-alist alist))))))
-(defun mu-cite-load-registration-file ()
-  (let ((file (mu-cite-registration-file)))
-    (when (file-readable-p file)
-      (let ((alist (with-temp-buffer
-                    (eval
-                     (` (let ((, mu-cite-registration-symbol)
-                              mu-cite/citation-name-alist)
-                          (insert-file-contents-as-coding-system
-                           mu-cite-registration-file-coding-system-for-read
-                           file)
-                          (condition-case nil
-                              (progn
-                                (eval-current-buffer)
-                                (or mu-cite/citation-name-alist
-                                    (, mu-cite-registration-symbol)))
-                            (error nil))))))))
-       (when alist
-         (setq mu-cite-citation-name-alist alist))))))
-(add-hook 'mu-cite-load-hook (function mu-cite-load-registration-file))
-
-(defun mu-cite-save-registration-file ()
-  ;;(let ((file mu-cite-registration-file))
-  (let ((file (mu-cite-registration-file)))
-    (with-temp-buffer
-      (setq buffer-file-name file)
-      (insert ";;; " (file-name-nondirectory file) "\n")
-      (insert ";;; This file is generated automatically by mu-cite "
-             mu-cite-version "\n\n")
-      (insert "(setq "
-             (symbol-name mu-cite-registration-symbol)
-             "\n      '(")
-      (insert (mapconcat
-              (function prin1-to-string)
-              mu-cite-citation-name-alist "\n        "))
-      (insert "\n        ))\n\n")
-      (insert ";;; "
-             (file-name-nondirectory file)
-             " ends here.\n")
-      (write-region 1 1 file nil 'nomsg)
-      (condition-case nil
-         (set-file-modes file mu-cite-registration-file-modes)
-       (error nil))
-      (save-buffer-as-coding-system
-       mu-cite-registration-file-coding-system-for-write))))
-
-
 ;;; @ item methods
 ;;;
 
@@ -428,55 +251,24 @@ Use this hook to add your own methods to `mu-cite-default-methods-alist'."
   :group 'mu-cite)
 
 (defun mu-cite-get-ml-count-method ()
+  "A mu-cite method to return a ML-count.
+This function searches a field about ML-count, which is specified by
+variable `mu-cite-ml-count-field-list', in a header.
+If the field is found, the function returns a number part of the
+field.
+
+Notice that please use (mu-cite-get-value 'ml-count)
+instead of call the function directly."
   (let ((field-list mu-cite-ml-count-field-list))
     (catch 'tag
       (while field-list
        (let* ((field (car field-list))
               (ml-count (mu-cite-get-field-value field)))
-         (when (and ml-count (string-match "[0-9]+" ml-count))
-           (throw 'tag
-                  (substring ml-count
-                             (match-beginning 0)(match-end 0))))
+         (if (and ml-count (string-match "[0-9]+" ml-count))
+             (throw 'tag (match-string 0 ml-count)))
          (setq field-list (cdr field-list)))))))
 
 
-;;; @@ prefix and registration
-;;;
-
-(defun mu-cite-get-prefix-method ()
-  (or (mu-cite-get-citation-name (mu-cite-get-value 'address))
-      ">"))
-
-(defun mu-cite-get-prefix-register-method ()
-  (let ((addr (mu-cite-get-value 'address)))
-    (or (mu-cite-get-citation-name addr)
-       (let ((return
-              (read-string "Citation name? "
-                           (or (mu-cite-get-value 'x-attribution)
-                               (mu-cite-get-value 'full-name))
-                           'mu-cite-minibuffer-history)))
-         (when (and (or mu-cite-allow-null-string-registration
-                        (not (string-equal return "")))
-                    (y-or-n-p (format "Register \"%s\"? " return)))
-           (mu-cite-add-citation-name return addr))
-         return))))
-
-(defun mu-cite-get-prefix-register-verbose-method ()
-  (let* ((addr (mu-cite-get-value 'address))
-        (return1 (mu-cite-get-citation-name addr))
-        (return (read-string "Citation name? "
-                             (or return1
-                                 (mu-cite-get-value 'x-attribution)
-                                 (mu-cite-get-value 'full-name))
-                             'mu-cite-minibuffer-history)))
-    (when (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-cite-add-citation-name return addr))
-    return))
-
-
 ;;; @ fundamentals
 ;;;
 
@@ -488,6 +280,7 @@ Use this hook to add your own methods to `mu-cite-default-methods-alist'."
   (run-hooks 'mu-cite-instantiation-hook))
 
 (defun mu-cite-get-value (item)
+  "Return current value of ITEM."
   (let ((ret (cdr (assoc item mu-cite-methods-alist))))
     (if (functionp ret)
        (prog1
@@ -506,6 +299,7 @@ Use this hook to add your own methods to `mu-cite-default-methods-alist'."
 ;;; @ main function
 ;;;
 
+;;;###autoload
 (defun mu-cite-original ()
   "Citing filter function.
 This is callable from the various mail and news readers' reply
@@ -547,6 +341,31 @@ function according to the agreed upon standard."
   :type 'string
   :group 'mu-cite)
 
+(defun-maybe-cond char-category (character)
+  "Return string of category mnemonics for CHAR in TABLE.
+CHAR can be any multilingual character
+TABLE defaults to the current buffer's category table."
+  ((and (subr-fboundp 'char-category-set)
+       (subr-fboundp 'category-set-mnemonics))
+   (category-set-mnemonics (char-category-set character))
+   )
+  ((fboundp 'char-category-list)
+   (mapconcat (lambda (chr)
+               (char-to-string (int-char chr)))
+             (char-category-list character)
+             "")
+   )
+  ((boundp 'NEMACS)
+   (if (< (char-int character) 128)
+       "al"
+     "j")
+   )
+  (t
+   (if (< (char-int character) 128)
+       "al"
+     "l")
+   ))
+
 (defun detect-paragraph-cited-prefix ()
   (save-excursion
     (goto-char (point-min))
@@ -593,7 +412,9 @@ function according to the agreed upon standard."
             (buffer-substring (point-min)(point)))
            (t "")))))
 
+;;;###autoload
 (defun fill-cited-region (beg end)
+  "Fill each of the paragraphs in the region as a cited text."
   (interactive "*r")
   (save-excursion
     (save-restriction
@@ -617,7 +438,9 @@ function according to the agreed upon standard."
        (goto-char (point-min))
        (fill-region (point-min) (point-max))))))
 
+;;;###autoload
 (defun compress-cited-prefix ()
+  "Compress nested cited prefixes."
   (interactive)
   (save-excursion
     (goto-char (point-min))
@@ -678,12 +501,44 @@ function according to the agreed upon standard."
 
 ;; This part will be abolished in the future.
 
-(static-unless (fboundp 'defvaralias)
-  (mapcar
-   (function
-    (lambda (elem)
-      (eval (list 'defvar (car elem) (cadr elem)))))
-   mu-cite-obsolete-variable-alist))
+(define-obsolete-function-alias
+  'mu-cite/cite-original 'mu-cite-original)
+(define-obsolete-function-alias
+  'mu-cite/get-field-value 'mu-cite-get-field-value)
+(define-obsolete-function-alias
+  'mu-cite/get-value 'mu-cite-get-value)
+
+(eval-when-compile (require 'static))
+
+(static-when (featurep 'xemacs)
+  (define-obsolete-variable-alias
+    'mu-cite/default-methods-alist
+    'mu-cite-default-methods-alist)
+  (define-obsolete-variable-alias
+    'mu-cite/cited-prefix-regexp
+    'mu-cite-cited-prefix-regexp)
+  (define-obsolete-variable-alias
+    'mu-cite/prefix-format
+    'mu-cite-prefix-format)
+  (define-obsolete-variable-alias
+    'mu-cite/top-format
+    'mu-cite-top-format)
+  (define-obsolete-variable-alias
+    'mu-cite/instantiation-hook
+    'mu-cite-instantiation-hook)
+  (define-obsolete-variable-alias
+    'mu-cite/pre-cite-hook
+    'mu-cite-pre-cite-hook)
+  (define-obsolete-variable-alias
+    'mu-cite/post-cite-hook
+    'mu-cite-post-cite-hook)
+  (define-obsolete-variable-alias
+    'mu-cite/get-field-value-method-alist
+    'mu-cite-get-field-value-method-alist)
+  (define-obsolete-variable-alias
+    'mu-cite/ml-count-field-list
+    'mu-cite-ml-count-field-list)
+  )
 
 
 ;;; @ end