1 ;;; signature.el --- a signature utility for GNU Emacs
3 ;; Copyright (C) 1994,1995,1996,1997,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
8 ;; Maintainer: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
10 ;; Keywords: mail, news, signature
12 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program; see the file COPYING. If not, write to
26 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
37 (defvar signature-insert-at-eof nil
38 "*If non-nil, insert signature at the end of file.")
40 (defvar signature-delete-blank-lines-at-eof nil
41 "*If non-nil, signature-insert-at-eof deletes blank lines at the end
44 (defvar signature-load-hook nil
45 "*List of functions called after signature.el is loaded.")
47 (defvar signature-separator "-- \n"
48 "*String to separate contents and signature.
49 It is inserted when signature is inserted at end of file.")
51 (defvar signature-file-name "~/.signature"
52 "*Name of file containing the user's signature.")
54 (defvar signature-file-alist nil
56 (((FIELD . PATTERN) . FILENAME)
58 PATTERN is a string or list of string. If PATTERN matches the contents of
59 FIELD, the contents of FILENAME is inserted.")
61 (defvar signature-file-prefix nil
62 "*String containing optional prefix for the signature file names")
64 (defvar signature-insert-hook nil
65 "*List of functions called before inserting a signature.")
67 (defvar signature-use-bbdb nil
68 "*If non-nil, Register sigtype to BBDB.")
70 (autoload 'signature/get-sigtype-from-bbdb "mime-bbdb")
72 (defun signature/get-sigtype-interactively (&optional default)
73 (read-file-name "Insert your signature: "
74 (or default (concat signature-file-name "-"))
75 (or default signature-file-name)
78 (defun signature/get-signature-file-name ()
82 (goto-char (point-min))
83 (if (re-search-forward
84 (concat "^" (regexp-quote mail-header-separator) "$")
90 (let ((alist signature-file-alist) cell field value)
92 (setq cell (car alist)
93 field (std11-field-body (car (car cell)))
94 value (cdr (car cell)))
95 (cond ((functionp value)
96 (let ((name (apply value field (cdr cell))))
99 (concat signature-file-prefix name))
104 (if (string-match (car value) field)
107 signature-file-prefix (cdr cell)))
108 (setq value (cdr value))
111 (if (string-match value field)
114 signature-file-prefix (cdr cell)))
116 (setq alist (cdr alist))
118 signature-file-name))))
120 (defun insert-signature (&optional arg)
121 "Insert the file named by signature-file-name.
122 It is inserted at the end of file if signature-insert-at-eof is non-nil,
123 and otherwise at the current point. A prefix argument enables user to
124 specify a file named <signature-file-name>-DISTRIBUTION interactively."
126 (let ((signature-file-name
128 (or (and signature-use-bbdb
129 (signature/get-sigtype-from-bbdb arg))
131 (signature/get-sigtype-interactively))
132 (signature/get-signature-file-name))
134 (or (file-readable-p signature-file-name)
135 (error "Cannot open signature file: %s" signature-file-name))
136 (if signature-insert-at-eof
138 (goto-char (point-max))
139 (or (bolp) (insert "\n"))
140 (if signature-delete-blank-lines-at-eof (delete-blank-lines))
142 (run-hooks 'signature-insert-hook)
143 (if (= (point)(point-max))
144 (insert signature-separator)
146 (insert-file-contents signature-file-name)
147 (force-mode-line-update)
148 signature-file-name))
156 (run-hooks 'signature-load-hook)
158 ;;; signature.el ends here