[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Random signatures
From: |
Miles Bader |
Subject: |
Re: Random signatures |
Date: |
Thu, 27 May 2004 06:23:04 +0900 |
Max Quordlepleen <maxq@nonags.com> writes:
> Last night I went googling for "random signature" in gnu.emacs.gnus,
> looking for a ready-made few lines I could steal and drop into my
> .gnus.
;; I use the following, which reads from a signature file containing
;; sigs separated by blank lines (which seems much more convenient than
;; having a separate file per signature). It chooses randomly by entry
;; number, not line or byte number, because the latter two methods tend
;; to over-emphasize longer entries:
(random t)
(defvar sig-file-num-entries)
(defvar random-sig-file "~/.random-sigs")
(defun signature ()
(with-current-buffer (find-file-noselect random-sig-file)
(unless (local-variable-p 'sig-file-num-entries)
(set (make-local-variable 'sig-file-num-entries) 0)
(goto-char (point-min))
(while (not (eobp))
(when (looking-at "^$")
(setq sig-file-num-entries (1+ sig-file-num-entries)))
(forward-line 1))
(unless (bobp)
(setq sig-file-num-entries (1+ sig-file-num-entries))))
(let ((entry (random sig-file-num-entries)))
(goto-char (point-min))
(while (and (not (eobp)) (not (zerop entry)))
(forward-line 1)
(when (looking-at "^$")
(setq entry (1- entry)))))
(when (looking-at "^$")
(forward-line 1))
(let ((start (point)))
(forward-line 1)
(while (and (not (eobp)) (not (looking-at "^$")))
(forward-line 1))
(buffer-substring-no-properties start (point)))))
(setq mail-signature 'signature message-signature 'signature)
;; Also just for completeness I have the following so I can choose another
;; signature when what got inserted seems inappropriate:
(defun change-signature ()
(interactive)
(save-excursion
(goto-char (point-max))
(if (not (search-backward "\n-- \n" nil t))
(insert "-- \n")
(forward-line 2)
(delete-region (point) (point-max)))
(insert (signature))))
;; -Miles
--
We have met the enemy, and he is us. -- Pogo