tm4.7.0.
[elisp/semi.git] / signature.el
1 ;;;
2 ;;; $Id: signature.el,v 1.6 1994/08/03 04:42:40 morioka Exp $
3 ;;; Modified by Yasuo OKABE 1994/08/01
4 ;;; 
5
6 (provide 'signature)
7
8 (require 'tl-header)
9
10 (defvar signature-insert-at-eof nil
11   "*Insert signature at the end of file if non-nil.")
12
13 (defvar signature-file-name "~/.signature"
14   "*Name of file containing the user's signature.")
15
16 (defvar signature-file-alist nil)
17
18 ;;;
19 ;;; Example:
20 ;;;
21 ;;; (setq signature-file-alist
22 ;;;       '((("Newsgroups" . "zxr")   . "~/.signature-sun")
23 ;;;         (("To" . "uramimi")       . "~/.signature-sun")
24 ;;;         (("Newsgroups" . "jokes") . "~/.signature-jokes")
25 ;;;         (("To" . "tea")           . "~/.signature-jokes")
26 ;;;         (("To" . ("sim" "oku"))   . "~/.signature-formal")
27 ;;;         ))
28
29 (defun signature/get-signature-file-name ()
30   (catch 'tag
31     (let ((r signature-file-alist) cell b f)
32       (while r
33         (setq cell (car r))
34         (setq b (car cell))
35         (if (setq f (message/get-field-body (car b)))
36             (cond ((listp (cdr b))
37                    (let ((r (cdr b)))
38                      (while r
39                        (if (string-match (car r) f)
40                            (throw 'tag (cdr cell))
41                          )
42                        (setq r (cdr r))
43                        ))
44                    )
45                   ((stringp (cdr b))
46                    (if (string-match (cdr b) f)
47                        (throw 'tag (cdr cell))
48                      ))
49                   ))
50         (setq r (cdr r))
51         ))
52     signature-file-name))
53
54 (defun signature/insert-signature-at-point (&optional arg)
55   "Insert the file named by signature-file-name at the current point."
56   (interactive "P")
57   (let ((signature
58          (expand-file-name
59           (if arg
60               (read-file-name "Insert your signature: "
61                               (concat signature-file-name "-")
62                               signature-file-name
63                               nil)
64             (signature/get-signature-file-name)))))
65     (insert-file-contents signature)
66     (set-buffer-modified-p (buffer-modified-p)))) ; force mode line update
67
68 (defun signature/insert-signature-at-eof (&optional arg)
69   "Insert the file named by signature-file-name at the end of file."
70   (interactive "P")
71   (let ((signature
72          (expand-file-name
73           (if arg
74               (read-file-name "Insert your signature: "
75                               (concat signature-file-name "-")
76                               signature-file-name
77                               nil)
78             (signature/get-signature-file-name)))))
79     (save-excursion
80       (if (file-readable-p signature)
81           (progn
82             (goto-char (point-max))
83             (if (not (bolp))
84                 (insert "\n"))
85             (delete-blank-lines)
86             (insert-file-contents signature)
87             (set-buffer-modified-p (buffer-modified-p)) ; force mode line update
88             )))))
89
90 (defun insert-signature (&optional arg)
91   "Insert the file named by signature-file-name.  It is inserted at the
92 end of file if signature-insert-at-eof in non-nil, and otherwise at
93 the current point.  A prefix argument enables user to specify a file
94 named <signature-file-name>-DISTRIBUTION interactively."
95   (interactive "P")
96   (if signature-insert-at-eof
97         (call-interactively 'signature/insert-signature-at-eof)
98     (call-interactively 'signature/insert-signature-at-point)))