123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- (require 'erc)
- (defgroup erc-replace nil
- "Replace text from incoming messages"
- :group 'erc)
- (defcustom erc-replace-alist nil
- "Alist describing text to be replaced in incoming messages.
- This is useful for filters.
- The alist has elements of the form (FROM . TO). FROM can be a regular
- expression or a variable, or any sexp, TO can be a string or a
- function to call, or any sexp. If a function, it will be called with
- one argument, the string to be replaced, and it should return a
- replacement string."
- :group 'erc-replace
- :type '(repeat (cons :tag "Search & Replace"
- (choice :tag "From"
- regexp
- variable
- sexp)
- (choice :tag "To"
- string
- function
- sexp))))
- (defun erc-replace-insert ()
- "Function to run from `erc-insert-modify-hook'.
- It replaces text according to `erc-replace-alist'."
- (mapcar (lambda (elt)
- (goto-char (point-min))
- (let ((from (car elt))
- (to (cdr elt)))
- (unless (stringp from)
- (setq from (eval from)))
- (while (re-search-forward from nil t)
- (cond ((stringp to)
- (replace-match to))
- ((and (symbolp to) (fboundp to))
- (replace-match (funcall to (match-string 0))))
- (t
- (eval to))))))
- erc-replace-alist))
- (define-erc-module replace nil
- "This mode replaces incoming text according to `erc-replace-alist'."
- ((add-hook 'erc-insert-modify-hook
- 'erc-replace-insert))
- ((remove-hook 'erc-insert-modify-hook
- 'erc-replace-insert)))
- (provide 'erc-replace)
|