Stop files with same basename messing up finder's package--builtins
[emacs.git] / lisp / erc / erc-replace.el
blob5eb3338b73ebd90f68af41b8792e8cf1725ac0b4
1 ;; erc-replace.el -- wash and massage messages inserted into the buffer
3 ;; Copyright (C) 2001-2002, 2004, 2006-2014 Free Software Foundation,
4 ;; Inc.
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/>.
25 ;;; Commentary:
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)
34 ;;; Code:
36 (require 'erc)
38 (defgroup erc-replace nil
39 "Replace text from incoming messages"
40 :group 'erc)
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
50 replacement 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))))
62 (defun erc-replace-insert ()
63 "Function to run from `erc-insert-modify-hook'.
64 It 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))))
77 (eval to))))))
78 erc-replace-alist))
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)))
88 (provide 'erc-replace)
90 ;;; erc-replace.el ends here
92 ;; Local Variables:
93 ;; indent-tabs-mode: t
94 ;; tab-width: 8
95 ;; End: