zenirc-bold.el

Lars Magne Ingebrigtsen <[email protected]> Sat, 12 Apr 2003 20:36:46 +0200
Newsgroups gmane.emacs.zenirc.devel
Message-ID <[email protected]>
I just slapped together the following, because I was tired of seeing
people saying ^Bsomething in bold^B.

Enjoy (or not).

;;; zenirc-bold.el --- boldify messages in zenirc

;; Copyright (C) 2003 Lars Magne Ingebrigtsen

;; Author: Lars Magne Ingebrigtsen <[email protected]>
;; Keywords: extensions

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.

;;; Commentary:

;;; Code:

(require 'cl)
(require 'zenirc)

(defvar zenirc-face-alist 
  '(("\C-b" zenirc-bold)
    ("\C-_" zenirc-underline)
    ("\C-v" zenirc-inverse))
  "Alist of strings and face properties.")

(defface zenirc-bold '((t (:bold t)))
  "Face used for displaying strong emphasized text (*word*).")

(defface zenirc-underline '((t (:underline t)))
  "Face used for displaying underlined emphasized text (_word_).")

(defface zenirc-inverse '((t (:underline t :bold t)))
  "Face used for displaying underlined emphasized text (_word_).")

(defun zenirc-boldify (&rest discard)
  (dolist (spec zenirc-face-alist)
    (let ((text (regexp-quote (car spec)))
	  (face (cadr spec)))
      (goto-char (point-min))
      (while (re-search-forward (concat text "\\(.*\\)" text) nil t)
	(put-text-property (match-beginning 1) (match-end 1) 
			   'face face)
	(delete-region (match-end 1) (match-end 0))
	(delete-region (match-beginning 0) (match-beginning 1))))))

(zenirc-add-hook 'zenirc-message-hook 'zenirc-boldify)

(provide 'zenirc-bold)

;;; zenirc-bold.el ends here


-- 
(domestic pets only, the antidote for overdose, milk.)
   [email protected] * Lars Magne Ingebrigtsen