Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / lisp / erc / erc-replace.el
CommitLineData
597993cf
MB
1;; erc-replace.el -- wash and massage messages inserted into the buffer
2
acaf905b 3;; Copyright (C) 2001-2002, 2004, 2006-2012 Free Software Foundation, Inc.
597993cf
MB
4
5;; Author: Andreas Fuchs <asf@void.at>
6;; Maintainer: Mario Lang (mlang@delysid.org)
7;; Keywords: IRC, client, Internet
597993cf
MB
8
9;; This file is part of GNU Emacs.
10
4ee57b2a 11;; GNU Emacs is free software: you can redistribute it and/or modify
597993cf 12;; it under the terms of the GNU General Public License as published by
4ee57b2a
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
597993cf
MB
15
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.
20
21;; You should have received a copy of the GNU General Public License
4ee57b2a 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
597993cf
MB
23
24;;; Commentary:
25
26;; This module allows you to systematically replace text in incoming
27;; messages. Load erc-replace, and customize `erc-replace-alist'.
28;; Then add to your ~/.emacs:
29
30;; (require 'erc-replace)
31;; (erc-replace-mode 1)
32
33;;; Code:
34
35(require 'erc)
36
37(defgroup erc-replace nil
38 "Replace text from incoming messages"
39 :group 'erc)
40
41(defcustom erc-replace-alist nil
42 "Alist describing text to be replaced in incoming messages.
43This is useful for filters.
44
45The alist has elements of the form (FROM . TO). FROM can be a regular
46expression or a variable, or any sexp, TO can be a string or a
47function to call, or any sexp. If a function, it will be called with
48one argument, the string to be replaced, and it should return a
49replacement string."
50 :group 'erc-replace
51 :type '(repeat (cons :tag "Search & Replace"
52 (choice :tag "From"
53 regexp
54 variable
55 sexp)
56 (choice :tag "To"
57 string
58 function
59 sexp))))
60
61(defun erc-replace-insert ()
62 "Function to run from `erc-insert-modify-hook'.
63It replaces text according to `erc-replace-alist'."
64 (mapcar (lambda (elt)
65 (goto-char (point-min))
66 (let ((from (car elt))
67 (to (cdr elt)))
68 (unless (stringp from)
69 (setq from (eval from)))
70 (while (re-search-forward from nil t)
71 (cond ((stringp to)
72 (replace-match to))
73 ((and (symbolp to) (fboundp to))
74 (replace-match (funcall to (match-string 0))))
75 (t
76 (eval to))))))
77 erc-replace-alist))
78
79;;;###autoload (autoload 'erc-replace-mode "erc-replace")
80(define-erc-module replace nil
81 "This mode replaces incoming text according to `erc-replace-alist'."
82 ((add-hook 'erc-insert-modify-hook
83 'erc-replace-insert))
84 ((remove-hook 'erc-insert-modify-hook
85 'erc-replace-insert)))
86
87(provide 'erc-replace)
88
597993cf 89;;; erc-replace.el ends here
5e56b3fb
MO
90;;
91;; Local Variables:
92;; indent-tabs-mode: t
93;; tab-width: 8
94;; End:
95