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