1 ;; erc-replace.el -- wash and massage messages inserted into the buffer
3 ;; Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
5 ;; Author: Andreas Fuchs <asf@void.at>
6 ;; Maintainer: Mario Lang (mlang@delysid.org)
7 ;; Keywords: IRC, client, Internet
8 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcReplace
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This module allows you to systematically replace text in incoming
30 ;; messages. Load erc-replace, and customize `erc-replace-alist'.
31 ;; Then add to your ~/.emacs:
33 ;; (require 'erc-replace)
34 ;; (erc-replace-mode 1)
40 (defconst erc-replace-version "$Revision: 1.8.2.1 $"
41 "Revision of the ERC replace module.")
43 (defgroup erc-replace nil
44 "Replace text from incoming messages"
47 (defcustom erc-replace-alist nil
48 "Alist describing text to be replaced in incoming messages.
49 This is useful for filters.
51 The alist has elements of the form (FROM . TO). FROM can be a regular
52 expression or a variable, or any sexp, TO can be a string or a
53 function to call, or any sexp. If a function, it will be called with
54 one argument, the string to be replaced, and it should return a
57 :type '(repeat (cons :tag "Search & Replace"
67 (defun erc-replace-insert ()
68 "Function to run from `erc-insert-modify-hook'.
69 It replaces text according to `erc-replace-alist'."
71 (goto-char (point-min))
72 (let ((from (car elt))
74 (unless (stringp from)
75 (setq from (eval from)))
76 (while (re-search-forward from nil t)
79 ((and (symbolp to) (fboundp to))
80 (replace-match (funcall to (match-string 0))))
85 ;;;###autoload (autoload 'erc-replace-mode "erc-replace")
86 (define-erc-module replace nil
87 "This mode replaces incoming text according to `erc-replace-alist'."
88 ((add-hook 'erc-insert-modify-hook
90 ((remove-hook 'erc-insert-modify-hook
91 'erc-replace-insert)))
93 (provide 'erc-replace)
95 ;; arch-tag: dd904a59-d8a6-47f8-ac3a-76b698289a18
96 ;;; erc-replace.el ends here