Fix bug #2496 with column counting in presence of display tables.
[emacs.git] / lisp / erc / erc-replace.el
blob4d3ba1e230d4e08e83a2d356ce577a6f11bae12e
1 ;; erc-replace.el -- wash and massage messages inserted into the buffer
3 ;; Copyright (C) 2001-2002, 2004, 2006-2011 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 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
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:
30 ;; (require 'erc-replace)
31 ;; (erc-replace-mode 1)
33 ;;; Code:
35 (require 'erc)
37 (defgroup erc-replace nil
38 "Replace text from incoming messages"
39 :group 'erc)
41 (defcustom erc-replace-alist nil
42 "Alist describing text to be replaced in incoming messages.
43 This is useful for filters.
45 The alist has elements of the form (FROM . TO). FROM can be a regular
46 expression or a variable, or any sexp, TO can be a string or a
47 function to call, or any sexp. If a function, it will be called with
48 one argument, the string to be replaced, and it should return a
49 replacement 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))))
61 (defun erc-replace-insert ()
62 "Function to run from `erc-insert-modify-hook'.
63 It 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))))
76 (eval to))))))
77 erc-replace-alist))
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)))
87 (provide 'erc-replace)
89 ;;; erc-replace.el ends here
91 ;; Local Variables:
92 ;; indent-tabs-mode: t
93 ;; tab-width: 8
94 ;; End: