2 ;;; signature.el --- a signature utility for GNU Emacs
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
6 ;;; Copyright (C) 1994 OKABE Yasuo
7 ;;; Copyright (C) 1996 Artur Pioro
8 ;;; Copyright (C) 1996 KOBAYASHI Shuhei
10 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
11 ;;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
12 ;;; Artur Pioro <artur@flugor.if.uj.edu.pl>
13 ;;; KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
14 ;;; Maintainer: KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
15 ;;; Created: 1994/7/11
17 ;;; $Id: signature.el,v 7.11 1996/07/10 13:45:06 shuhei-k Exp $
18 ;;; Keywords: mail, news, signature
20 ;;; This file is part of tm (Tools for MIME).
22 ;;; This program is free software; you can redistribute it and/or
23 ;;; modify it under the terms of the GNU General Public License as
24 ;;; published by the Free Software Foundation; either version 2, or
25 ;;; (at your option) any later version.
27 ;;; This program is distributed in the hope that it will be useful,
28 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
29 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 ;;; General Public License for more details.
32 ;;; You should have received a copy of the GNU General Public License
33 ;;; along with This program. If not, write to the Free Software
34 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
43 (defvar signature-insert-at-eof nil
44 "*If non-nil, insert signature at the end of file.")
46 (defvar signature-delete-blank-lines-at-eof nil
47 "*If non-nil, signature-insert-at-eof deletes blank lines at the end
50 (defvar signature-load-hook nil
51 "*List of functions called after signature.el is loaded.")
53 (defvar signature-file-name "~/.signature"
54 "*Name of file containing the user's signature.")
56 (defvar signature-file-alist nil)
58 (defvar signature-file-prefix nil
59 "*String containing optional prefix for the signature file names")
61 (defvar signature-insert-hook nil
62 "*List of functions called before inserting a signature.")
64 (defvar signature-use-bbdb nil
65 "*If non-nil, Register sigtype to BBDB.")
70 ;;; (setq signature-file-alist
71 ;;; '((("Newsgroups" . "zxr") . "~/.signature-sun")
72 ;;; (("To" . "uramimi") . "~/.signature-sun")
73 ;;; (("Newsgroups" . "jokes") . "~/.signature-jokes")
74 ;;; (("To" . "tea") . "~/.signature-jokes")
75 ;;; (("To" . ("sim" "oku")) . "~/.signature-formal")
78 (autoload 'signature/get-sigtype-from-bbdb "tm-bbdb")
80 (defun signature/get-sigtype-interactively (&optional default)
81 (read-file-name "Insert your signature: "
82 (or default (concat signature-file-name "-"))
83 (or default signature-file-name)
86 (defun signature/get-signature-file-name ()
90 (goto-char (point-min))
91 (if (re-search-forward
92 (concat "^" (regexp-quote mail-header-separator) "$")
98 (let ((alist signature-file-alist) cell field value)
100 (setq cell (car alist)
101 field (rfc822/get-field-body (car (car cell)))
102 value (cdr (car cell)))
103 (cond ((functionp value)
104 (let ((name (apply value field (cdr cell))))
107 (concat signature-file-prefix name))
112 (if (string-match (car value) field)
115 signature-file-prefix (cdr cell)))
116 (setq value (cdr value))
119 (if (string-match value field)
122 signature-file-prefix (cdr cell)))
124 (setq alist (cdr alist))
126 signature-file-name))))
128 (defun insert-signature (&optional arg)
129 "Insert the file named by signature-file-name.
130 It is inserted at the end of file if signature-insert-at-eof is non-nil,
131 and otherwise at the current point. A prefix argument enables user to
132 specify a file named <signature-file-name>-DISTRIBUTION interactively."
134 (let ((signature-file-name
136 (or (and signature-use-bbdb
137 (signature/get-sigtype-from-bbdb arg))
139 (signature/get-sigtype-interactively))
140 (signature/get-signature-file-name))
142 (or (file-readable-p signature-file-name)
143 (error "Cannot open signature file: %s" signature-file-name))
144 (if signature-insert-at-eof
146 (goto-char (point-max))
147 (or (bolp) (insert "\n"))
148 (if signature-delete-blank-lines-at-eof (delete-blank-lines))
150 (run-hooks 'signature-insert-hook)
151 (insert-file-contents signature-file-name)
152 (force-mode-line-update)
153 signature-file-name))
161 (run-hooks 'signature-load-hook)
163 ;;; signature.el ends here