tm 7.52.1. tm7_52_1 tm7_52_2 tm7_54 tm7_56 tm7_57 tm7_59 tm7_60 tm7_61 tm7_62 tm7_63 tm7_64 tm7_65
authormorioka <morioka>
Mon, 9 Mar 1998 17:35:59 +0000 (17:35 +0000)
committermorioka <morioka>
Mon, 9 Mar 1998 17:35:59 +0000 (17:35 +0000)
signature.el

index 129f28c..d72825e 100644 (file)
@@ -5,13 +5,16 @@
 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
 ;;; Copyright (C) 1994 OKABE Yasuo
 ;;; Copyright (C) 1996 Artur Pioro
+;;; Copyright (C) 1996 KOBAYASHI Shuhei
 ;;;
 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;;;         OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
 ;;;         Artur Pioro <artur@flugor.if.uj.edu.pl>
+;;;         KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
+;;; Maintainer: KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
 ;;; Created: 1994/7/11
 ;;; Version:
-;;;    $Id: signature.el,v 7.7 1996/03/14 13:39:57 morioka Exp $
+;;;    $Id: signature.el,v 7.9 1996/04/19 18:12:43 morioka Exp $
 ;;; Keywords: mail, news, signature
 ;;;
 ;;; This file is part of tm (Tools for MIME).
 
 (require 'tl-822)
 
+;;; @ valiables
+;;;
+
 (defvar signature-insert-at-eof nil
-  "*Insert signature at the end of file if non-nil. [signature.el]")
+  "*Insert signature at the end of file if non-nil.")
 
 (defvar signature-delete-blank-lines-at-eof nil
-  "*Signature-insert-at-eof deletes blank lines at the end of file
-if non-nil. [signature.el]")
+  "*If non-nil, signature-insert-at-eof deletes blank lines at the end
+of file.")
+
+(defvar signature-load-hook nil
+  "*List of functions called after signature.el is loaded.")
 
 (defvar signature-file-name "~/.signature"
-  "*Name of file containing the user's signature. [signature.el]")
+  "*Name of file containing the user's signature.")
 
 (defvar signature-file-alist nil)
 
 (defvar signature-file-prefix nil
   "*String containing optional prefix for the signature file names")
 
+(defvar signature-insert-hook nil
+  "*List of functions called before inserting a signature.")
+
+(defvar signature-use-bbdb nil
+  "*If non-nil, Register sigtype to BBDB.")
+
 ;;;
 ;;; Example:
 ;;;
 ;;; (setq signature-file-alist
-;;;      '((("To" . signature-check-in-bbdb) . nil)
-;;;        (("Newsgroups" . "zxr")   . "~/.signature-sun")
-;;;        (("To" . "uramimi")       . "~/.signature-sun")
-;;;        (("Newsgroups" . "jokes") . "~/.signature-jokes")
-;;;        (("To" . "tea")           . "~/.signature-jokes")
-;;;        (("To" . ("sim" "oku"))   . "~/.signature-formal")
-;;;        ))
+;;;       '((("Newsgroups" . "zxr")   . "~/.signature-sun")
+;;;         (("To" . "uramimi")       . "~/.signature-sun")
+;;;         (("Newsgroups" . "jokes") . "~/.signature-jokes")
+;;;         (("To" . "tea")           . "~/.signature-jokes")
+;;;         (("To" . ("sim" "oku"))   . "~/.signature-formal")
+;;;         ))
+
+(autoload 'signature/get-sigtype-from-bbdb "tm-bbdb")
 
-(autoload 'signature-check-in-bbdb "tm-bbdb")
+(defun signature/get-sigtype-interactively (&optional default)
+  (read-file-name "Insert your signature: "
+                  (or default (concat signature-file-name "-"))
+                  (or default signature-file-name)
+                  nil))
 
 (defun signature/get-signature-file-name ()
-  (catch 'tag
-    (let ((r signature-file-alist) cell b f)
-      (save-excursion
-       (save-restriction
-         (narrow-to-region
-          (point-min)
-          (progn
-            (goto-char (point-min))
-            (if (re-search-forward
-                 (concat "^" (regexp-quote mail-header-separator) "$")
-                 nil t)
-                (match-beginning 0)
-              (point-max)
-              )))
-         (while r
-           (setq cell (car r))
-           (setq b (car cell))
-           (if (setq f (rfc822/get-field-body (car b)))
-               (cond ((listp (cdr b))
-                      (let ((r (cdr b)))
-                        (while r
-                          (if (string-match (car r) f)
-                              (throw 'tag
-                                     (concat
-                                      signature-file-prefix (cdr cell)))
-                            )
-                          (setq r (cdr r))
-                          ))
-                      )
-                     ((stringp (cdr b))
-                      (if (string-match (cdr b) f)
-                          (throw 'tag
-                                 (concat
-                                  signature-file-prefix (cdr cell)))
-                        ))
-                     ((functionp (cdr b))
-                      (let ((name (apply (cdr b) f (cdr cell))))
-                        (if name
-                            (throw 'tag
-                                   (concat signature-file-prefix name))
-                          )))
-                     ))
-           (setq r (cdr r))
-           ))
-       signature-file-name))))
-
-(defun signature/insert-signature-at-point (&optional arg)
-  "Insert the file named by signature-file-name at the current point."
-  (interactive "P")
-  (let ((signature
-        (expand-file-name
-         (if arg
-             (read-file-name "Insert your signature: "
-                             (concat signature-file-name "-")
-                             signature-file-name
-                             nil)
-           (signature/get-signature-file-name)))))
-    (insert-file-contents signature)
-    (set-buffer-modified-p (buffer-modified-p)) ; force mode line update
-    signature))
+  (save-excursion
+    (save-restriction
+      (narrow-to-region
+       (goto-char (point-min))
+       (if (re-search-forward
+            (concat "^" (regexp-quote mail-header-separator) "$")
+            nil t)
+           (match-beginning 0)
+         (point-max)
+         ))
+      (catch 'found
+        (let ((alist signature-file-alist) cell field value)
+          (while alist
+            (setq cell  (car alist)
+                  field (rfc822/get-field-body (car (car cell)))
+                  value (cdr (car cell)))
+            (cond ((functionp value)
+                  (let ((name (apply value field (cdr cell))))
+                    (if name
+                        (throw 'found
+                               (concat signature-file-prefix name))
+                      )))
+                 ((stringp field)
+                  (cond ((consp value)
+                         (while value
+                           (if (string-match (car value) field)
+                               (throw 'found
+                                      (concat
+                                       signature-file-prefix (cdr cell)))
+                             (setq value (cdr value))
+                             )))
+                        ((stringp value)
+                         (if (string-match value field)
+                             (throw 'found
+                                    (concat
+                                     signature-file-prefix (cdr cell)))
+                           )))))
+            (setq alist (cdr alist))
+            ))
+        signature-file-name))))
 
-(defun signature/insert-signature-at-eof (&optional arg)
-  "Insert the file named by signature-file-name at the end of file."
+(defun insert-signature (&optional arg)
+  "Insert the file named by signature-file-name.
+It is inserted at the end of file if signature-insert-at-eof in non-nil,
+and otherwise at the current point.  A prefix argument enables user to
+specify a file named <signature-file-name>-DISTRIBUTION interactively."
   (interactive "P")
   (let ((signature
-        (expand-file-name
-         (if arg
-             (read-file-name "Insert your signature: "
-                             (concat signature-file-name "-")
-                             signature-file-name
-                             nil)
-           (signature/get-signature-file-name)))))
-    (if (file-readable-p signature)
-       (progn
-         (goto-char (point-max))
-         (if (not (bolp))
-             (insert "\n"))
-         (if signature-delete-blank-lines-at-eof (delete-blank-lines))
-         (insert-file-contents signature)
-         (set-buffer-modified-p (buffer-modified-p))
-                                       ; force mode line update
-         ))
+         (expand-file-name
+          (or (and signature-use-bbdb
+                   (signature/get-sigtype-from-bbdb arg))
+              (and arg
+                   (signature/get-sigtype-interactively))
+              (signature/get-signature-file-name))
+          )))
+    (or (file-readable-p signature)
+        (error "Cannot open signature file: %s" signature))
+    (if signature-insert-at-eof
+        (progn
+          (goto-char (point-max))
+          (or (bolp) (insert "\n"))
+          (or signature-delete-blank-lines-at-eof (delete-blank-lines))
+          ))
+    (run-hooks 'signature-insert-hook)
+    (insert-file-contents signature)
+    (force-mode-line-update)
     signature))
 
-(defun insert-signature (&optional arg)
-  "Insert the file named by signature-file-name.  It is inserted at the
-end of file if signature-insert-at-eof in non-nil, and otherwise at
-the current point.  A prefix argument enables user to specify a file
-named <signature-file-name>-DISTRIBUTION interactively."
-  (interactive "P")
-  (if signature-insert-at-eof
-       (call-interactively 'signature/insert-signature-at-eof)
-    (call-interactively 'signature/insert-signature-at-point)))
-
 
 ;;; @ end
 ;;;
 
 (provide 'signature)
 
+(run-hooks 'signature-load-hook)
+
 ;;; signature.el ends here