On this page:
  • More Emacs fun: Composing mail to everyone with notes
  • Emacs BBDB magic: Greeting people with nicknames

More Emacs fun: Composing mail to everyone with notes

(defun sacha/compose-mail-to-everyone (&optional subject)
  (mapc (lambda (rec)
          (setq rec (car rec))
          (when (bbdb-record-net rec)
            (bbdb-send-mail rec subject)
            (save-excursion
              (message-goto-signature)
              (forward-line -2)
              (insert "\n---- NOTES ---\n" (bbdb-record-notes rec) "\n"))))
        bbdb-records))

(defun sacha/gnus-delete-notes ()
  (goto-char (point-min))
  (when (re-search-forward "^--- NOTES ---" nil t)
    (goto-char (match-beginning 0))
    (message-kill-to-signature)))
(add-hook 'message-send-hook 'sacha/gnus-delete-notes)

On Technorati: , , , , ,

Emacs BBDB magic: Greeting people with nicknames

I use Gnus to read my mail within the Emacs text editor. One of the
advantages of using a mail client that’s infinitely programmable is
that you can add all sorts of little tweaks to it. Gnus can be
integrated with Emacs’ Big Brother Database (BBDB), a semi-structured
text database in which I store all sorts of weird notes. This little
hack takes the nick field of the database and automatically inserts a
greeting. If someone signs himself as Mikong, I should call him that
instead of Joseph Michael. Similarly, I sign my messages as Sacha, not
Sandra Jean. This little tidbit makes it easier to remember to call
people by their nicknames.

(defun sacha/gnus-add-nick-to-message ()
  "Inserts \"Hello, NICK!\" in messages based on the recipient's nick field."
  (interactive)
  (save-excursion
    (let ((bbdb-get-addresses-headers (list (assoc 'recipients bbdb-get-addresses-headers)))
          nicks)
      (setq nicks
            (delq nil
                  (mapcar (lambda (rec) (bbdb-record-getprop rec 'nick))
                          (bbdb-update-records
                           (bbdb-get-addresses nil gnus-ignored-from-addresses 'gnus-fetch-field)
                           nil
                           nil))))
      (goto-char (point-min))
      (when (and nicks
                 (re-search-forward "--text follows this line--" nil t))
        (forward-line 1)
        (insert "Hello, "
                (mapconcat 'identity nicks ", ")
                "!\n\n")))))

(defadvice gnus-post-news (after sacha activate)
  (sacha/gnus-add-nick-to-message))

On Technorati: , , ,

Random Japanese sentence: 虎を大きな猫というなら、同じように猫を小さな虎といってもよい。 You may as well call a cat a small tiger as call a tiger a big cat.