1 ;; erc-replace.el -- wash and massage messages inserted into the buffer
3 ;; Copyright (C) 2001-2002, 2004, 2006-2014 Free Software Foundation,
6 ;; Author: Andreas Fuchs <asf@void.at>
7 ;; Maintainer: emacs-devel@gnu.org
8 ;; Keywords: IRC, client, Internet
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 3 of the License, or
15 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
27 ;; This module allows you to systematically replace text in incoming
28 ;; messages. Load erc-replace, and customize `erc-replace-alist'.
29 ;; Then add to your init file:
31 ;; (require 'erc-replace)
32 ;; (erc-replace-mode 1)
38 (defgroup erc-replace nil
39 "Replace text from incoming messages"
42 (defcustom erc-replace-alist nil
43 "Alist describing text to be replaced in incoming messages.
44 This is useful for filters.
46 The alist has elements of the form (FROM . TO). FROM can be a regular
47 expression or a variable, or any sexp, TO can be a string or a
48 function to call, or any sexp. If a function, it will be called with
49 one argument, the string to be replaced, and it should return a
52 :type
'(repeat (cons :tag
"Search & Replace"
62 (defun erc-replace-insert ()
63 "Function to run from `erc-insert-modify-hook'.
64 It replaces text according to `erc-replace-alist'."
66 (goto-char (point-min))
67 (let ((from (car elt
))
69 (unless (stringp from
)
70 (setq from
(eval from
)))
71 (while (re-search-forward from nil t
)
74 ((and (symbolp to
) (fboundp to
))
75 (replace-match (funcall to
(match-string 0))))
80 ;;;###autoload (autoload 'erc-replace-mode "erc-replace")
81 (define-erc-module replace nil
82 "This mode replaces incoming text according to `erc-replace-alist'."
83 ((add-hook 'erc-insert-modify-hook
85 ((remove-hook 'erc-insert-modify-hook
86 'erc-replace-insert
)))
88 (provide 'erc-replace
)
90 ;;; erc-replace.el ends here
93 ;; indent-tabs-mode: t