[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Automatic signature files



I realize that I risk getting flamed by the anti-signature file folks,
but here is a hack that will automatically append a signature file after
you hit the <END> key when mailing, replying etc.  It uses 3 global
variables that should be set in your zmail profile:

(login-setq *always-append-signature* nil)
(login-setq *ASK-ABOUT-SIGNATURE* t)
(login-setq *signature-file* "OZ:>larry>signature.text")

As an alternative, typing <super-s> inserts the sig file at the bottom
of the buffer, allowing you to continue editting the message after you
insert the file.

Larry Baum
Advanced Technology Center              
Boeing Computer Services     uucp:       uw-beaver!bcsaic!lbaum
(206) 865-3365               internet:   lbaum@atc.boeing.com       


-------------------------< cut here >-------------------------

;;; -*- Mode:LISP; Package:ZWEI; Base: 10 -*-

(defvar *signature-file*)
(defvar *always-append-signature* nil)
(defvar *ask-about-signature* nil)

(defcom-for-zmail com-insert-signature
		  "Add your signature file to the bottom of the message."
		  ()
  (com-set-pop-mark)
  (com-goto-end)
  (insert-file *signature-file*)
  (let ((*numeric-arg* 2))
    (com-move-to-previous-point))
  (zwei:com-set-pop-mark)
  dis-all)

(command-store 'COM-INSERT-SIGNATURE #\s-s *REPLY-COMTAB*)

(defun insert-file (pathname)
  (point-pdl-push (point) *window* nil nil)
  (move-mark (point))
  (setq *current-command-type* 'yank)
  (condition-case (.error.)
       (condition-bind ((si:binary-file-read-as-character-file-error
			  #'si:binary-file-read-as-character-file-error-query-handler)
			(si:escape-loading-stream-decoding-error
			  #'si:escape-loading-stream-decoding-error-query-handler))
	 (si:with-open-character-file (file-stream pathname :direction :input)
	   (let ((interval-stream (open-interval-stream (point) (point) t))
		 (old-point (copy-bp (point) :normal)))
	     (with-node-write-locked ((bp-node-to-lock old-point))
	       (with-custom-undo-save (old-point old-point
						 (make-insert-record old-point
								     (copy-bp old-point ':moves)))
		 (unwind-protect-case ()
		     (block insert
		       (stream-copy-until-eof file-stream interval-stream line-leader-size)
		       (loop with end-bp = (send interval-stream :read-bp)
			     with end-line = (bp-line end-bp)
			     for line = (bp-line old-point) then (line-next line)
			     do (setq line (mung-line line))
			     until (eq line end-line)
			     finally (move-point end-bp))
		       (maybe-display-directory :read pathname))
		   (:abort
		     (delete-interval old-point (send interval-stream :read-bp) t))))))))
     (fs:file-operation-failure
       (barf "~A" .error.))
     (si:binary-file-read-as-character-file-error
       (abort-current-command))))

(advise COM-SEND-MESSAGE :before append-signature nil
  (if (or *always-append-signature*
	  (and *ask-about-signature* (y-or-n-p "Append signature file? ")))
      (com-insert-signature)))