(string-compare-from-top): Don't use `aref'.
[elisp/mu-cite.git] / mu-bbdb.el
index d8c5844..738ae96 100644 (file)
@@ -1,9 +1,10 @@
-;;; mu-bbdb.el --- `attribution' function for mu-cite with BBDB.
+;;; mu-bbdb.el --- registration feature of mu-cite using BBDB
 
-;; Copyright (C) 1996,1997 Shuhei KOBAYASHI
+;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
 
-;; Author: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
-;; Version: $Id: mu-bbdb.el,v 3.3 1996/12/10 11:57:23 shuhei-k Exp $
+;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
+;; Maintainer: Katsumi Yamaoka <yamaoka@jpl.org>
+;; Keywords: BBDB, citation, mail, news
 
 ;; This file is part of MU (Message Utilities).
 
 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
-;;; Commentary:
-
-;;  - How to use
-;;    1. bytecompile this file and copy it to the apropriate directory.
-;;    2. put the following lines to your ~/.emacs:
-;;             (add-hook 'mu-cite-load-hook
-;;                       (function
-;;                        (lambda ()
-;;                          (require 'mu-bbdb)
-;;                          )))
-
-\f
 ;;; Code:
 
 (require 'mu-cite)
-(if (module-installed-p 'bbdb)
-    (require 'bbdb))
+(require 'bbdb)
 
-(defvar mu-bbdb-load-hook nil
-  "*List of functions called after mu-bbdb is loaded.")
+(defvar mu-bbdb-history nil)
 
-;;; @@ prefix and registration using BBDB
-;;;
 
-(defun mu-cite/get-bbdb-prefix-method ()
-  (or (mu-cite/get-bbdb-attr (mu-cite/get-value 'address))
-      ">")
-  )
+;;; @ BBDB interface
+;;;
 
-(defun mu-cite/get-bbdb-attr (addr)
+(defun mu-bbdb-get-attr (addr)
   "Extract attribute information from BBDB."
   (let ((record (bbdb-search-simple nil addr)))
-    (and record
-         (bbdb-record-getprop record 'attribution))
-    ))
+    (if record
+       (bbdb-record-getprop record 'attribution))))
 
-(defun mu-cite/set-bbdb-attr (attr addr)
+(defun mu-bbdb-set-attr (attr addr)
   "Add attribute information to BBDB."
   (let* ((bbdb-notice-hook nil)
-         (record (bbdb-annotate-message-sender
-                  addr t
-                 (bbdb-invoke-hook-for-value
-                  bbdb/mail-auto-create-p)
+        (record (bbdb-annotate-message-sender
+                 addr t
+                 (bbdb-invoke-hook-for-value
+                  bbdb/mail-auto-create-p)
                  t)))
     (if record
-        (progn
-          (bbdb-record-putprop record 'attribution attr)
-          (bbdb-change-record record nil))
-      )))
-
-(defun mu-cite/get-bbdb-prefix-register-method ()
-  (let ((addr (mu-cite/get-value 'address)))
-    (or (mu-cite/get-bbdb-attr addr)
-       (let ((return
+       (progn
+         (bbdb-record-putprop record 'attribution attr)
+         (bbdb-change-record record nil)))))
+
+
+;;; @ methods
+;;;
+
+;;;###autoload
+(defun mu-bbdb-get-prefix-method ()
+  "A mu-cite method to return a prefix from BBDB or \">\".
+If an `attribution' value is found in BBDB, the value is returned.
+Otherwise \">\" is returned.
+
+Notice that please use (mu-cite-get-value 'bbdb-prefix)
+instead of call the function directly."
+  (or (mu-bbdb-get-attr (mu-cite-get-value 'address))
+      ">"))
+
+;;;###autoload
+(defun mu-bbdb-get-prefix-register-method ()
+  "A mu-cite method to return a prefix from BBDB or register it.
+If an `attribution' value is found in BBDB, the value is returned.
+Otherwise the function requests a prefix from a user.  The prefix will
+be registered to BBDB if the user wants it.
+
+Notice that please use (mu-cite-get-value 'bbdb-prefix-register)
+instead of call the function directly."
+  (let ((addr (mu-cite-get-value 'address)))
+    (or (mu-bbdb-get-attr addr)
+       (let ((return
               (read-string "Citation name? "
-                           (or (mu-cite/get-value 'x-attribution)
-                               (mu-cite/get-value 'full-name))
-                           'mu-cite/minibuffer-history)
-              ))
+                           (or (mu-cite-get-value 'x-attribution)
+                               (mu-cite-get-value 'full-name))
+                           'mu-bbdb-history)))
          (if (and (not (string-equal return ""))
-                   (y-or-n-p (format "Register \"%s\"? " return)))
-             (mu-cite/set-bbdb-attr return addr)
-           )
+                  (y-or-n-p (format "Register \"%s\"? " return)))
+             (mu-bbdb-set-attr return addr))
          return))))
 
-(defun mu-cite/get-bbdb-prefix-register-verbose-method ()
-  (let* ((addr (mu-cite/get-value 'address))
-         (attr (mu-cite/get-bbdb-attr addr))
+;;;###autoload
+(defun mu-bbdb-get-prefix-register-verbose-method ()
+  "A mu-cite method to return a prefix using BBDB.
+
+In this method, a user must specify a prefix unconditionally.  If an
+`attribution' value is found in BBDB, the value is used as a initial
+value to input the prefix.  The prefix will be registered to BBDB if
+the user wants it.
+
+Notice that please use (mu-cite-get-value 'bbdb-prefix-register-verbose)
+instead of call the function directly."
+  (let* ((addr (mu-cite-get-value 'address))
+        (attr (mu-bbdb-get-attr addr))
         (return (read-string "Citation name? "
                              (or attr
-                                 (mu-cite/get-value 'x-attribution)
-                                 (mu-cite/get-value 'full-name))
-                             'mu-cite/minibuffer-history))
-        )
+                                 (mu-cite-get-value 'x-attribution)
+                                 (mu-cite-get-value 'full-name))
+                             'mu-bbdb-history)))
     (if (and (not (string-equal return ""))
-             (not (string-equal return attr))
-            (y-or-n-p (format "Register \"%s\"? " return))
-            )
-       (mu-cite/set-bbdb-attr return addr)
-      )
+            (not (string-equal return attr))
+            (y-or-n-p (format "Register \"%s\"? " return)))
+       (mu-bbdb-set-attr return addr))
     return))
 
-(or (assoc 'bbdb-prefix mu-cite/default-methods-alist)
-    (setq mu-cite/default-methods-alist
-          (append mu-cite/default-methods-alist
-                  (list
-                   (cons 'bbdb-prefix
-                         (function mu-cite/get-bbdb-prefix-method))
-                   (cons 'bbdb-prefix-register
-                         (function mu-cite/get-bbdb-prefix-register-method))
-                   (cons 'bbdb-prefix-register-verbose
-                         (function
-                          mu-cite/get-bbdb-prefix-register-verbose-method))
-                   ))))
-
-\f
+
 ;;; @ end
 ;;;