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