|
Revision 4220, 2.9 kB
(checked in by miyoshi, 9 months ago)
|
Sync up with Emacs22.2.
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
(require 'erc) |
|---|
| 38 |
|
|---|
| 39 |
(defgroup erc-replace nil |
|---|
| 40 |
"Replace text from incoming messages" |
|---|
| 41 |
:group 'erc) |
|---|
| 42 |
|
|---|
| 43 |
(defcustom erc-replace-alist nil |
|---|
| 44 |
"Alist describing text to be replaced in incoming messages. |
|---|
| 45 |
This is useful for filters. |
|---|
| 46 |
|
|---|
| 47 |
The alist has elements of the form (FROM . TO). FROM can be a regular |
|---|
| 48 |
expression or a variable, or any sexp, TO can be a string or a |
|---|
| 49 |
function to call, or any sexp. If a function, it will be called with |
|---|
| 50 |
one argument, the string to be replaced, and it should return a |
|---|
| 51 |
replacement string." |
|---|
| 52 |
:group 'erc-replace |
|---|
| 53 |
:type '(repeat (cons :tag "Search & Replace" |
|---|
| 54 |
(choice :tag "From" |
|---|
| 55 |
regexp |
|---|
| 56 |
variable |
|---|
| 57 |
sexp) |
|---|
| 58 |
(choice :tag "To" |
|---|
| 59 |
string |
|---|
| 60 |
function |
|---|
| 61 |
sexp)))) |
|---|
| 62 |
|
|---|
| 63 |
(defun erc-replace-insert () |
|---|
| 64 |
"Function to run from `erc-insert-modify-hook'. |
|---|
| 65 |
It replaces text according to `erc-replace-alist'." |
|---|
| 66 |
(mapcar (lambda (elt) |
|---|
| 67 |
(goto-char (point-min)) |
|---|
| 68 |
(let ((from (car elt)) |
|---|
| 69 |
(to (cdr elt))) |
|---|
| 70 |
(unless (stringp from) |
|---|
| 71 |
(setq from (eval from))) |
|---|
| 72 |
(while (re-search-forward from nil t) |
|---|
| 73 |
(cond ((stringp to) |
|---|
| 74 |
(replace-match to)) |
|---|
| 75 |
((and (symbolp to) (fboundp to)) |
|---|
| 76 |
(replace-match (funcall to (match-string 0)))) |
|---|
| 77 |
(t |
|---|
| 78 |
(eval to)))))) |
|---|
| 79 |
erc-replace-alist)) |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
(define-erc-module replace nil |
|---|
| 83 |
"This mode replaces incoming text according to `erc-replace-alist'." |
|---|
| 84 |
((add-hook 'erc-insert-modify-hook |
|---|
| 85 |
'erc-replace-insert)) |
|---|
| 86 |
((remove-hook 'erc-insert-modify-hook |
|---|
| 87 |
'erc-replace-insert))) |
|---|
| 88 |
|
|---|
| 89 |
(provide 'erc-replace) |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|