tm 7.10.
[elisp/semi.git] / signature.el
1 ;;;
2 ;;; signature.el --- signature utility for GNU Emacs
3 ;;;
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1994,1995 MORIOKA Tomohiko
6 ;;; Copyright (C) 1994 OKABE Yasuo
7 ;;;
8 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;;         OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp> (1994/08/01)
10 ;;; Version:
11 ;;;     $Id: signature.el,v 2.0 1995/10/05 11:24:45 morioka Exp $
12 ;;; Keywords: mail, news, signature
13 ;;;
14 ;;; This file is part of tm (Tools for MIME).
15 ;;;
16
17 (require 'tl-822)
18
19 (defvar signature-insert-at-eof nil
20   "*Insert signature at the end of file if non-nil.")
21
22 (defvar signature-file-name "~/.signature"
23   "*Name of file containing the user's signature.")
24
25 (defvar signature-file-alist nil)
26
27 ;;;
28 ;;; Example:
29 ;;;
30 ;;; (setq signature-file-alist
31 ;;;       '((("Newsgroups" . "zxr")   . "~/.signature-sun")
32 ;;;         (("To" . "uramimi")       . "~/.signature-sun")
33 ;;;         (("Newsgroups" . "jokes") . "~/.signature-jokes")
34 ;;;         (("To" . "tea")           . "~/.signature-jokes")
35 ;;;         (("To" . ("sim" "oku"))   . "~/.signature-formal")
36 ;;;         ))
37
38 (defun signature/get-signature-file-name ()
39   (catch 'tag
40     (let ((r signature-file-alist) cell b f)
41       (while r
42         (setq cell (car r))
43         (setq b (car cell))
44         (if (setq f (rfc822/get-field-body (car b)))
45             (cond ((listp (cdr b))
46                    (let ((r (cdr b)))
47                      (while r
48                        (if (string-match (car r) f)
49                            (throw 'tag (cdr cell))
50                          )
51                        (setq r (cdr r))
52                        ))
53                    )
54                   ((stringp (cdr b))
55                    (if (string-match (cdr b) f)
56                        (throw 'tag (cdr cell))
57                      ))
58                   ))
59         (setq r (cdr r))
60         ))
61     signature-file-name))
62
63 (defun signature/insert-signature-at-point (&optional arg)
64   "Insert the file named by signature-file-name at the current point."
65   (interactive "P")
66   (let ((signature
67          (expand-file-name
68           (if arg
69               (read-file-name "Insert your signature: "
70                               (concat signature-file-name "-")
71                               signature-file-name
72                               nil)
73             (signature/get-signature-file-name)))))
74     (insert-file-contents signature)
75     (set-buffer-modified-p (buffer-modified-p)))) ; force mode line update
76
77 (defun signature/insert-signature-at-eof (&optional arg)
78   "Insert the file named by signature-file-name at the end of file."
79   (interactive "P")
80   (let ((signature
81          (expand-file-name
82           (if arg
83               (read-file-name "Insert your signature: "
84                               (concat signature-file-name "-")
85                               signature-file-name
86                               nil)
87             (signature/get-signature-file-name)))))
88     (save-excursion
89       (if (file-readable-p signature)
90           (progn
91             (goto-char (point-max))
92             (if (not (bolp))
93                 (insert "\n"))
94             (delete-blank-lines)
95             (insert-file-contents signature)
96             (set-buffer-modified-p (buffer-modified-p))
97                                         ; force mode line update
98             )))))
99
100 (defun insert-signature (&optional arg)
101   "Insert the file named by signature-file-name.  It is inserted at the
102 end of file if signature-insert-at-eof in non-nil, and otherwise at
103 the current point.  A prefix argument enables user to specify a file
104 named <signature-file-name>-DISTRIBUTION interactively."
105   (interactive "P")
106   (if signature-insert-at-eof
107         (call-interactively 'signature/insert-signature-at-eof)
108     (call-interactively 'signature/insert-signature-at-point)))
109
110
111 ;;; @ end
112 ;;;
113
114 (provide 'signature)