I'm still sending out my email with mailmsg.py, which I posted here a
long time ago; but I haven't been using it to read and compose mail
lately.

I've been using this bit of elisp in my .emacs to compose new
messages; I hit F3 to start a new message (perhaps it should go to the
end of the buffer first, perhaps not), insert text to be quoted with
C-x i, quote it with C-x c.  I just added the .signature stuff and
changed the way C-x c worked.

The ~/~t stuff is still kind of a pain in the butt.

; mostly c&p from macro.el
; I think apply-macro-to-region-lines should be written in terms of this
; function.
(defun apply-to-region-lines (top bottom function)
  "Run a function at the beginning of every complete line within region."
  (interactive "r")
  (let ((end-marker (progn (goto-char bottom) 
                           (beginning-of-line)
                           (point-marker))))
    (goto-char top)
    (if (not (bolp)) (forward-line 1))
    (let ((next-line-marker (point-marker)))
      (while (< next-line-marker end-marker)
        (goto-char next-line-marker)
        (save-excursion (forward-line 1) (set-marker next-line-marker (point)))
        (save-excursion (funcall function)))
      (set-marker next-line-marker nil))
    (set-marker end-marker nil)))

(defun quote-region ()
  "Quote the region, even if not activated, as an email message."
  (interactive)
  (save-excursion
    (exchange-point-and-mark)
    (let ((top (min (point) (mark))) (bottom (max (point) (mark))))
      (apply-to-region-lines top bottom (lambda () (insert "> "))))))
(define-key global-map "\C-xc" #'quote-region)


(defun random-file (dir)
  (let ((files (directory-files dir 
                                t ; full-name
                                nil ; match-regexp
                                nil ; nosort
                                t ; files-only
                                )))
    (if (null files) (error "No files in %s" dir)
      (nth (random (length files)) files))))

(defcustom *signature-dir* "/home/kragen/.signatures"
  "Directory where insert-signature gets signature files from."
  :type 'directory)

(defun insert-signature ()
  (interactive)
  (let ((sigfile (random-file *signature-dir*)))
    (insert-file sigfile)
    ; This next line moves point to the end of the inserted file, but
    ; leaves the region as the .signature.  This is done because it
    ; seemed desirable to have (insert-signature) work more or less
    ; like (insert (generate-signature)), except for leaving the signature
    ; marked.
    (exchange-point-and-mark t)
    (message "%s inserted." sigfile)))

(defun quote-tildes (start end)
  "Replace ~ with ~t in region."
  (interactive "r")
  (save-excursion 
    (save-restriction
      (narrow-to-region start end)
      (beginning-of-buffer)
      (while (search-forward "~" nil t) (replace-match "~t" nil t)))))

; maybe I should use tempo.el for this?
(defun start-message ()
  "Start a new mailmsg.py message at the end of the buffer."
  (interactive)
  (end-of-buffer)
  (insert "~m\n")
  (save-excursion 
    (insert-signature)
    (quote-tildes (mark t) (point))
    (insert "~e\n"))
  (insert "From: [EMAIL PROTECTED] (Kragen Sitaker)\n")
  (insert "To: ")
  (save-excursion (insert "\nSubject: \n\n\n"))
  (recenter))
(define-key global-map [f3] #'start-message)

-- 
<[EMAIL PROTECTED]>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


Reply via email to