|
From: Max F. <ma...@la...> - 2004-07-04 13:19:46
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
- --=-=-=
Ever offended someone, or lost your job, because you inadvertently
sent something to the wrong channel?
This little module takes a list of per-channel regexps and warns you
that you are about to do something dangerous if the regexps are
matched. E.g. with:
(setq erc-wrong-channel-regexps
'(("#work\|#company" "project alpha" "waste" "time\|money")
("#france" "french" "idiots"))
if you send "I'm on project alpha. What a waste of money :-(" to #work,
the erc will ask you if you're sure you want to do that and will let
you cancel the action.
Hope you find it as useful as I do, and make sure your friends or your
coworkers don't find your .emacs file...
Max.
- --=-=-=
Content-Type: application/emacs-lisp
Content-Disposition: attachment; filename=erc-wrong-channel.el
Content-Transfer-Encoding: quoted-printable
;; erc-wrong-channel.el -- protect yourself from writing to the wrong chann=
el
;; Copyright (C) 2004 Max Froumentin <ma...@la...>
;; Author: Max Froumentin <ma...@la...>
;; Keywords: comm
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file 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
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This file implements a way to check what one is writing to a channel
;; by asking for confirmation is user-defined regexps are sent
;; To activate:
;;
;; (require 'erc-wrong-channel)
;; (erc-wrong-channel-mode t)
;;
;; and customise erc-wrong-channel-regexps, e.g:
;;
;; (("#work" "project alpha" "waste" "\(time\|money\)")
;; ("#france" "french" "idiots"))
;;
;; that second line will make erc ask for confirmation if the user sends a
;; line with both "french" and "idiots" in channel #france=20
;;
;; TODO:
;; -make code more efficient
;; -take server into account when checking
;; -make sure this code works!
;;; Code:
(require 'erc)
(defvar erc-wrong-channel-version "$Revision: $" "ERC Wrong Channel revisio=
n")
(defgroup erc-wrong-channel nil
"Make sure that you're not sending your text to the wrong channel"
:group 'erc)
;;;###autoload (autoload 'erc-wrong-channel-mode "erc-wrong-channel-mode" n=
il t)
(define-erc-module wrong-channel nil
"Checks user input against a per-channel list of regexps. If
matched, ask that the user confirms they want to send that text"
((add-hook 'erc-send-pre-hook 'erc-wrong-channel-check))
((remove-hook 'erc-send-pre-hook 'erc-wrong-channel-check)))
(defcustom erc-wrong-channel-regexps nil
"List of lists of regexps. The first item in inner lists is a regexp
that matches a channel name, the other items are regexps to match against
user input in that channel. e.g.
((\"#foo\" \"\bjohn\b\" \"a\(rse\|ss\)hole\")
(\"#bar\" \"peter\" \"idiot\")
The first line means: if in any channel whose name contains the string=20
\"#foo\" the user types a line that matches all of the following regexps
then erc will prompt for confirmation whether the user really wants to se=
nd
that line to that channel."
:group 'erc-wrong-channel
:type '(repeat '(repeat regexp)))
=20=20
(defun erc-wrong-channel-check (s)
"check string s against erc-wrong-channel-regexps"
(if (erc-wrong-channel-any (mapcar (lambda (r)=20
(erc-wrong-channel-check-1 s r))
erc-wrong-channel-regexps))
(if (yes-or-no-p (concat "Really send '" s "' to " (buffer-name) "? "=
))
(message"So be it...")
(keyboard-quit))))
(defun erc-wrong-channel-check-1 (s l)
(and
(string-match (car l) (buffer-name))
(erc-wrong-channel-list-match-all (cdr l) s)))
(defun erc-wrong-channel-any (l)
"returns true if any of the expressions in l is true. This is
meant to implement the 'some' function in Common lisp"
(and l
(or (car l)
(erc-wrong-channel-any (cdr l)))))
(defun erc-wrong-channel-list-match-all (lst str)
"Return non-nil if all the regexps in LST match STR."
(not (memq nil (mapcar (lambda (regexp)
(string-match regexp str))
lst))))
(provide 'erc-wrong-channel)
;;; erc-wrong-channel.el ends here
- --=-=-=--
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA6APXw87kC83B6J0RApx6AKCPGWL8VXZ4HhdHDXUXxsNFLY/nUwCfeM5y
TDEqkf8refbuFA9l0+jpYis=
=o+7U
-----END PGP SIGNATURE-----
|