annotate lisp/tm/signature.el @ 147:e186c2b7192d xemacs-20-2

Added tag r20-2p1 for changeset 2af401a6ecca
author cvs
date Mon, 13 Aug 2007 09:34:48 +0200
parents c0c698873ce1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; signature.el --- a signature utility for GNU Emacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1994,1995,1996 Free Software Foundation, Inc.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6 ;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7 ;; Artur Pioro <artur@flugor.if.uj.edu.pl>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 ;; KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9 ;; Maintainer: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10 ;; Created: 1994/7/11
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;; Version:
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
12 ;; $Id: signature.el,v 1.2 1996/12/28 21:03:13 steve Exp $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; Keywords: mail, news, signature
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 ;; This file is part of tm (Tools for MIME).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 ;; along with this program; see the file COPYING. If not, write to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 (require 'std11)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 ;;; @ valiables
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40 (defvar signature-insert-at-eof nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 "*If non-nil, insert signature at the end of file.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 (defvar signature-delete-blank-lines-at-eof nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 "*If non-nil, signature-insert-at-eof deletes blank lines at the end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45 of file.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 (defvar signature-load-hook nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 "*List of functions called after signature.el is loaded.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 (defvar signature-file-name "~/.signature"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 "*Name of file containing the user's signature.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 (defvar signature-file-alist nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (defvar signature-file-prefix nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 "*String containing optional prefix for the signature file names")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 (defvar signature-insert-hook nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 "*List of functions called before inserting a signature.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 (defvar signature-use-bbdb nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 "*If non-nil, Register sigtype to BBDB.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 ;;; Example:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 ;;; (setq signature-file-alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68 ;;; '((("Newsgroups" . "zxr") . "~/.signature-sun")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 ;;; (("To" . "uramimi") . "~/.signature-sun")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 ;;; (("Newsgroups" . "jokes") . "~/.signature-jokes")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 ;;; (("To" . "tea") . "~/.signature-jokes")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 ;;; (("To" . ("sim" "oku")) . "~/.signature-formal")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 ;;; ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 (autoload 'signature/get-sigtype-from-bbdb "tm-bbdb")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 (defun signature/get-sigtype-interactively (&optional default)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 (read-file-name "Insert your signature: "
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 (or default (concat signature-file-name "-"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 (or default signature-file-name)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 nil))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 (defun signature/get-signature-file-name ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 (narrow-to-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 (if (re-search-forward
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 (concat "^" (regexp-quote mail-header-separator) "$")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 (match-beginning 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 (point-max)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 (catch 'found
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 (let ((alist signature-file-alist) cell field value)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 (while alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 (setq cell (car alist)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98 field (std11-field-body (car (car cell)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 value (cdr (car cell)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 (cond ((functionp value)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 (let ((name (apply value field (cdr cell))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 (if name
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 (throw 'found
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 (concat signature-file-prefix name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106 ((stringp field)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107 (cond ((consp value)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 (while value
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 (if (string-match (car value) field)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 (throw 'found
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 (concat
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 signature-file-prefix (cdr cell)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 (setq value (cdr value))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 ((stringp value)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 (if (string-match value field)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 (throw 'found
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 (concat
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 signature-file-prefix (cdr cell)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 )))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121 (setq alist (cdr alist))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 signature-file-name))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 (defun insert-signature (&optional arg)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126 "Insert the file named by signature-file-name.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 It is inserted at the end of file if signature-insert-at-eof is non-nil,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 and otherwise at the current point. A prefix argument enables user to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 specify a file named <signature-file-name>-DISTRIBUTION interactively."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 (interactive "P")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (let ((signature-file-name
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 (expand-file-name
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 (or (and signature-use-bbdb
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134 (signature/get-sigtype-from-bbdb arg))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 (and arg
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 (signature/get-sigtype-interactively))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 (signature/get-signature-file-name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 (or (file-readable-p signature-file-name)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 (error "Cannot open signature file: %s" signature-file-name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 (if signature-insert-at-eof
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143 (goto-char (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 (or (bolp) (insert "\n"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 (if signature-delete-blank-lines-at-eof (delete-blank-lines))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 (run-hooks 'signature-insert-hook)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 (insert-file-contents signature-file-name)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 (force-mode-line-update)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 signature-file-name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 (provide 'signature)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 (run-hooks 'signature-load-hook)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 ;;; signature.el ends here