2021-04-19 12:21:01 +02:00
|
|
|
;;; erc-replace.el --- wash and massage messages inserted into the buffer -*- lexical-binding: t; -*-
|
2006-01-29 13:08:58 +00:00
|
|
|
|
2022-01-01 07:03:03 -05:00
|
|
|
;; Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;; Author: Andreas Fuchs <asf@void.at>
|
2022-01-24 10:59:05 -05:00
|
|
|
;; Maintainer: Amin Bandali <bandali@gnu.org>, F. Jason Park <jp@neverwas.me>
|
Update ERC module URLs
* lisp/erc/erc-autoaway.el, lisp/erc/erc-button.el,
lisp/erc/erc-compat.el, lisp/erc/erc-fill.el, lisp/erc/erc-imenu.el,
lisp/erc/erc-join.el, lisp/erc/erc-lang.el, lisp/erc/erc-match.el,
lisp/erc/erc-pcomplete.el, lisp/erc/erc-ring.el,
lisp/erc/erc-spelling.el, lisp/erc/erc-stamp.el,
lisp/erc/erc-track.el: Update URL to friendlier form, over https.
* lisp/erc/erc-ibuffer.el: Remove URL to nonexistent page.
* lisp/erc/erc-list.el, lisp/erc/erc-log.el, lisp/erc/erc-notify.el,
lisp/erc/erc-replace.el, lisp/erc/erc-services.el,
lisp/erc/erc-sound.el, lisp/erc/erc-speedbar.el,
lisp/erc/erc-truncate.el: Add URL to corresponding EmacsWiki page.
2020-01-24 01:09:43 -05:00
|
|
|
;; URL: https://www.emacswiki.org/emacs/ErcReplace
|
2021-02-10 20:58:16 +01:00
|
|
|
;; Keywords: comm, IRC, client, Internet
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 03:36:21 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2006-01-29 13:08:58 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 03:36:21 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This module allows you to systematically replace text in incoming
|
|
|
|
;; messages. Load erc-replace, and customize `erc-replace-alist'.
|
2012-09-17 13:41:04 +08:00
|
|
|
;; Then add to your init file:
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;; (require 'erc-replace)
|
|
|
|
;; (erc-replace-mode 1)
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'erc)
|
|
|
|
|
|
|
|
(defgroup erc-replace nil
|
2021-09-14 08:43:18 +02:00
|
|
|
"Replace text from incoming messages."
|
2006-01-29 13:08:58 +00:00
|
|
|
: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."
|
|
|
|
: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)
|
2021-03-18 23:14:33 -04:00
|
|
|
(setq from (eval from t)))
|
2006-01-29 13:08:58 +00:00
|
|
|
(while (re-search-forward from nil t)
|
|
|
|
(cond ((stringp to)
|
|
|
|
(replace-match to))
|
2021-03-18 23:14:33 -04:00
|
|
|
((functionp to)
|
2006-01-29 13:08:58 +00:00
|
|
|
(replace-match (funcall to (match-string 0))))
|
|
|
|
(t
|
2021-03-18 23:14:33 -04:00
|
|
|
(eval to t))))))
|
2006-01-29 13:08:58 +00:00
|
|
|
erc-replace-alist))
|
|
|
|
|
Put most erc autoloads in a dedicated file erc-loaddefs.el
These are features that are only useful after erc.el is loaded.
* lisp/erc/erc.el (top-level): Load erc-loaddefs.
* lisp/erc/erc-autoaway.el, lisp/erc/erc-button.el:
* lisp/erc/erc-capab.el, lisp/erc/erc-compat.el:
* lisp/erc/erc-dcc.el, lisp/erc/erc-desktop-notifications.el:
* lisp/erc/erc-ezbounce.el, lisp/erc/erc-fill.el:
* lisp/erc/erc-identd.el, lisp/erc/erc-imenu.el:
* lisp/erc/erc-join.el, lisp/erc/erc-list.el, lisp/erc/erc-log.el:
* lisp/erc/erc-match.el, lisp/erc/erc-menu.el:
* lisp/erc/erc-netsplit.el, lisp/erc/erc-notify.el:
* lisp/erc/erc-page.el, lisp/erc/erc-pcomplete.el:
* lisp/erc/erc-replace.el, lisp/erc/erc-ring.el:
* lisp/erc/erc-services.el, lisp/erc/erc-sound.el:
* lisp/erc/erc-speedbar.el, lisp/erc/erc-spelling.el:
* lisp/erc/erc-stamp.el, lisp/erc/erc-track.el:
* lisp/erc/erc-truncate.el, lisp/erc/erc-xdcc.el:
Set generated-autoload-file to "erc-loaddefs.el".
2017-11-28 21:16:02 -05:00
|
|
|
;;;###autoload(autoload 'erc-replace-mode "erc-replace")
|
2006-01-29 13:08:58 +00:00
|
|
|
(define-erc-module replace nil
|
|
|
|
"This mode replaces incoming text according to `erc-replace-alist'."
|
|
|
|
((add-hook 'erc-insert-modify-hook
|
2021-03-18 23:14:33 -04:00
|
|
|
#'erc-replace-insert))
|
2006-01-29 13:08:58 +00:00
|
|
|
((remove-hook 'erc-insert-modify-hook
|
2021-03-18 23:14:33 -04:00
|
|
|
#'erc-replace-insert)))
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
(provide 'erc-replace)
|
|
|
|
|
|
|
|
;;; erc-replace.el ends here
|
2008-01-25 03:28:10 +00:00
|
|
|
;;
|
|
|
|
;; Local Variables:
|
Put most erc autoloads in a dedicated file erc-loaddefs.el
These are features that are only useful after erc.el is loaded.
* lisp/erc/erc.el (top-level): Load erc-loaddefs.
* lisp/erc/erc-autoaway.el, lisp/erc/erc-button.el:
* lisp/erc/erc-capab.el, lisp/erc/erc-compat.el:
* lisp/erc/erc-dcc.el, lisp/erc/erc-desktop-notifications.el:
* lisp/erc/erc-ezbounce.el, lisp/erc/erc-fill.el:
* lisp/erc/erc-identd.el, lisp/erc/erc-imenu.el:
* lisp/erc/erc-join.el, lisp/erc/erc-list.el, lisp/erc/erc-log.el:
* lisp/erc/erc-match.el, lisp/erc/erc-menu.el:
* lisp/erc/erc-netsplit.el, lisp/erc/erc-notify.el:
* lisp/erc/erc-page.el, lisp/erc/erc-pcomplete.el:
* lisp/erc/erc-replace.el, lisp/erc/erc-ring.el:
* lisp/erc/erc-services.el, lisp/erc/erc-sound.el:
* lisp/erc/erc-speedbar.el, lisp/erc/erc-spelling.el:
* lisp/erc/erc-stamp.el, lisp/erc/erc-track.el:
* lisp/erc/erc-truncate.el, lisp/erc/erc-xdcc.el:
Set generated-autoload-file to "erc-loaddefs.el".
2017-11-28 21:16:02 -05:00
|
|
|
;; generated-autoload-file: "erc-loaddefs.el"
|
2008-01-25 03:28:10 +00:00
|
|
|
;; End:
|