Mark Fowler <[EMAIL PROTECTED]> writes:

> I like my .emacs file.  It sets nice fonts and colours, and sets the
> editing mode and wrapping mode of choice ;-)
> 
> I'm sure it can do more...
> 
>  1) Where do I find handy things to put into my .emacs file on the web?
>  2) Got any nice bits of your .emacs file to share?
> 
> Note that (shock, horror) I can't program lisp properly (duh, I program
> perl) so that I may sound stupid when it comes to these things.
> 
> Later.
> 
> Mark.
> 
> P.S. All other editor comments >/dev/null or to sender as I think we've
> had quite enough holy wars on this list this month.

Scary stuff to use within GNUS to set arbitrary message headers based
on the newsgroup you were in when you hit 'r', 'f', or 'a'

(require 'message)

(defadvice message-setup (around my-message-setup
                                                                 (headers &optional 
replybuffer actions)
                                                                 activate compile)
  "Mess with the headers according to a couple of my-: variables.
my-:message-compulsory-headers -- compusory values for headers
my-:message-suggested-headers  -- suggested values for headers
my-:message-compulsory-news-headers
my-:message-compulsory-mail-headers"

  (set (make-local-variable 'gnus-select-method)
       gnus-current-select-method)
  (let* ((type-var
                  (intern
                   (concat "my-:message-compulsory-"
                                   (if (assq 'To headers) "mail" "news")
                                   "-headers")))
                 
                 (h
                  (append
                   (or (my-get-newsgroup-prop
                                gnus-newsgroup-name
                                'my-:message-compulsory-headers)
                           my-:message-compulsory-headers)
                   (or (my-get-newsgroup-prop
                                gnus-newsgroup-name
                                'my-:message-suggested-headers)
                           my-:message-suggested-headers)
                   (or (my-get-newsgroup-prop
                                gnus-newsgroup-name
                                type-var)
                           (eval type-var))))
                 )
    (while h
      (if (assq (caar h) headers)
                  (setcdr (assq (caar h) headers) (cdr (car h)))
          (setq headers (cons (car h) headers)))
      (pop h)
      )
        ad-do-it
    )
  )

(defun my-get-newsgroup-prop (group property)
  "(my-get-newsgroup-prop GROUP PROPERTY): Get the GROUP's PROPERTY."
  (let ((prefixes (list 'my-newsgroup-defaults))
                (start 0) 
                ans)
        (setq group (if (symbolp group)
                                        (symbol-name group)
                                  group))
        (while (setq end (string-match "[\\.:]" group start))
          (setq prefixes
                        (cons (intern (substring group 0 end))
                                  prefixes)
                        start (+ 1 (match-end 0))
                        ))
        (setq prefixes (cons (intern group) prefixes))
        (while (and (not ans)
                                prefixes)
      (setq ans (get (car prefixes) property)
                        prefixes (cdr prefixes))
          )
    (if (equal "" ans) nil ans)))


Use it by doing something like:

(put 'my-newsgroup-defaults 'my-:message-suggested-headers
     '((From          . "Piers Cawley <[EMAIL PROTECTED]>")))

(put 'London.pm 'my-:message-suggested-headers
     '((From          . "Piers Cawley <[EMAIL PROTECTED]>")
       (X-Buffy-Quote . "Is it bigger than a bread bin?")
       (X-There-Was-This-One-Time . "At band camp...")))

Et viola...

-- 
Piers

Reply via email to