X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=signature.el;h=b111892d8d44aec0687872ababa59ac36f712215;hb=3fe76b044cf6350e4fddadbc8e3c12af0a97866b;hp=e577f907ad1697f607ae7d4ed755bb26897bef1d;hpb=d76805c485e461fecda9a4a7ea7d6e237fe13436;p=elisp%2Ftm.git diff --git a/signature.el b/signature.el index e577f90..b111892 100644 --- a/signature.el +++ b/signature.el @@ -1,128 +1,160 @@ -;;; -;;; signature.el --- signature utility for GNU Emacs -;;; -;;; Copyright (C) 1995 Free Software Foundation, Inc. -;;; Copyright (C) 1994,1995 MORIOKA Tomohiko -;;; Copyright (C) 1994 OKABE Yasuo -;;; -;;; Author: MORIOKA Tomohiko -;;; OKABE Yasuo (1994/08/01) -;;; Version: -;;; $Id: signature.el,v 4.0 1995/10/26 09:25:23 morioka Exp $ -;;; Keywords: mail, news, signature -;;; -;;; This file is part of tm (Tools for MIME). -;;; +;;; signature.el --- a signature utility for GNU Emacs + +;; Copyright (C) 1994,1995,1996 Free Software Foundation, Inc. + +;; Author: MORIOKA Tomohiko +;; OKABE Yasuo +;; Artur Pioro +;; KOBAYASHI Shuhei +;; Maintainer: Shuhei KOBAYASHI +;; 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) -(require 'tl-822) + +;;; @ valiables +;;; (defvar signature-insert-at-eof nil - "*Insert signature at the end of file if non-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") -;;; )) +;;; '((("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 () - (catch 'tag - (let ((r signature-file-alist) cell b f) - (save-excursion - (save-restriction - (narrow-to-region - (point-min) - (progn - (goto-char (point-min)) - (if (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$") - nil t) - (match-beginning 0) - (point-max) - ))) - (while r - (setq cell (car r)) - (setq b (car cell)) - (if (setq f (rfc822/get-field-body (car b))) - (cond ((listp (cdr b)) - (let ((r (cdr b))) - (while r - (if (string-match (car r) f) - (throw 'tag (cdr cell)) - ) - (setq r (cdr r)) - )) - ) - ((stringp (cdr b)) - (if (string-match (cdr b) f) - (throw 'tag (cdr cell)) - )) - )) - (setq r (cdr r)) - )) - signature-file-name)))) - -(defun signature/insert-signature-at-point (&optional arg) - "Insert the file named by signature-file-name at the current point." - (interactive "P") - (let ((signature - (expand-file-name - (if arg - (read-file-name "Insert your signature: " - (concat signature-file-name "-") - signature-file-name - nil) - (signature/get-signature-file-name))))) - (insert-file-contents signature) - (set-buffer-modified-p (buffer-modified-p)) ; force mode line update - signature)) - -(defun signature/insert-signature-at-eof (&optional arg) - "Insert the file named by signature-file-name at the end of file." - (interactive "P") - (let ((signature - (expand-file-name - (if arg - (read-file-name "Insert your signature: " - (concat signature-file-name "-") - signature-file-name - nil) - (signature/get-signature-file-name))))) - (save-excursion - (if (file-readable-p signature) - (progn - (goto-char (point-max)) - (if (not (bolp)) - (insert "\n")) - (delete-blank-lines) - (insert-file-contents signature) - (set-buffer-modified-p (buffer-modified-p)) - ; force mode line update - ))) - signature)) + (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 in non-nil, and otherwise at -the current point. A prefix argument enables user to specify a file -named -DISTRIBUTION interactively." + "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 -DISTRIBUTION interactively." (interactive "P") - (if signature-insert-at-eof - (call-interactively 'signature/insert-signature-at-eof) - (call-interactively 'signature/insert-signature-at-point))) + (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