File: signature.el

package info (click to toggle)
xemacs20 20.4-13
  • links: PTS
  • area: main
  • in suites: slink
  • size: 67,324 kB
  • ctags: 57,643
  • sloc: lisp: 586,197; ansic: 184,662; sh: 4,296; asm: 3,179; makefile: 2,021; perl: 1,059; csh: 96; sed: 22
file content (160 lines) | stat: -rw-r--r-- 5,120 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
;;; signature.el --- a signature utility for GNU Emacs

;; Copyright (C) 1994,1995,1996 Free Software Foundation, Inc.

;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
;;         OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
;;         Artur Pioro <artur@flugor.if.uj.edu.pl>
;;         KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
;; Maintainer: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
;; Created: 1994/7/11
;; Version:
;;	$Id: signature.el,v 7.13 1996/08/30 04:34:56 morioka Exp $
;; Keywords: mail, news, signature

;; This file is part of tm (Tools for MIME).

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Code:

(require 'std11)


;;; @ valiables
;;;

(defvar signature-insert-at-eof nil
  "*If non-nil, insert signature at the end of file.")

(defvar signature-delete-blank-lines-at-eof nil
  "*If non-nil, signature-insert-at-eof deletes blank lines at the end
of file.")

(defvar signature-load-hook nil
  "*List of functions called after signature.el is loaded.")

(defvar signature-file-name "~/.signature"
  "*Name of file containing the user's signature.")

(defvar signature-file-alist nil)

(defvar signature-file-prefix nil
  "*String containing optional prefix for the signature file names")

(defvar signature-insert-hook nil
  "*List of functions called before inserting a signature.")

(defvar signature-use-bbdb nil
  "*If non-nil, Register sigtype to BBDB.")

;;;
;;; Example:
;;;
;;; (setq signature-file-alist
;;;       '((("Newsgroups" . "zxr")   . "~/.signature-sun")
;;;         (("To" . "uramimi")       . "~/.signature-sun")
;;;         (("Newsgroups" . "jokes") . "~/.signature-jokes")
;;;         (("To" . "tea")           . "~/.signature-jokes")
;;;         (("To" . ("sim" "oku"))   . "~/.signature-formal")
;;;         ))

(autoload 'signature/get-sigtype-from-bbdb "tm-bbdb")

(defun signature/get-sigtype-interactively (&optional default)
  (read-file-name "Insert your signature: "
                  (or default (concat signature-file-name "-"))
                  (or default signature-file-name)
                  nil))

(defun signature/get-signature-file-name ()
  (save-excursion
    (save-restriction
      (narrow-to-region
       (goto-char (point-min))
       (if (re-search-forward
            (concat "^" (regexp-quote mail-header-separator) "$")
            nil t)
           (match-beginning 0)
         (point-max)
         ))
      (catch 'found
        (let ((alist signature-file-alist) cell field value)
          (while alist
            (setq cell  (car alist)
                  field (std11-field-body (car (car cell)))
                  value (cdr (car cell)))
            (cond ((functionp value)
		   (let ((name (apply value field (cdr cell))))
		     (if name
			 (throw 'found
				(concat signature-file-prefix name))
		       )))
		  ((stringp field)
		   (cond ((consp value)
			  (while value
			    (if (string-match (car value) field)
				(throw 'found
				       (concat
					signature-file-prefix (cdr cell)))
			      (setq value (cdr value))
			      )))
			 ((stringp value)
			  (if (string-match value field)
			      (throw 'found
				     (concat
				      signature-file-prefix (cdr cell)))
			    )))))
            (setq alist (cdr alist))
            ))
        signature-file-name))))

(defun insert-signature (&optional arg)
  "Insert the file named by signature-file-name.
It is inserted at the end of file if signature-insert-at-eof is non-nil,
and otherwise at the current point.  A prefix argument enables user to
specify a file named <signature-file-name>-DISTRIBUTION interactively."
  (interactive "P")
  (let ((signature-file-name
         (expand-file-name
          (or (and signature-use-bbdb
                   (signature/get-sigtype-from-bbdb arg))
              (and arg
                   (signature/get-sigtype-interactively))
              (signature/get-signature-file-name))
          )))
    (or (file-readable-p signature-file-name)
        (error "Cannot open signature file: %s" signature-file-name))
    (if signature-insert-at-eof
        (progn
          (goto-char (point-max))
          (or (bolp) (insert "\n"))
          (if signature-delete-blank-lines-at-eof (delete-blank-lines))
          ))
    (run-hooks 'signature-insert-hook)
    (insert-file-contents signature-file-name)
    (force-mode-line-update)
    signature-file-name))


;;; @ end
;;;

(provide 'signature)

(run-hooks 'signature-load-hook)

;;; signature.el ends here