|
From: lawrence m. <we...@gm...> - 2003-10-17 23:00:59
|
Having been bitten again by the "oops, using some silly speak erc module in the wrong channel" problem for the umpteenth time, I decided to do something about it. This patch adds a new optional argument to DEFINE-ERC-MODULE, LOCAL-P. If LOCAL-P is non-NIL, erc-FOO-mode will be created as a buffer-local variable. If this seems like a good idea, I'll commit it. Index: erc.el =================================================================== RCS file: /cvsroot/erc/erc/erc.el,v retrieving revision 1.576 diff -u -r1.576 erc.el --- erc.el 17 Oct 2003 07:55:35 -0000 1.576 +++ erc.el 17 Oct 2003 22:53:58 -0000 @@ -925,13 +925,16 @@ (defvar erc-dbuf nil) (make-variable-buffer-local 'erc-dbuf) -(defmacro define-erc-module (name alias doc enable-body disable-body) +(defmacro define-erc-module (name alias doc enable-body disable-body + &optional local-p) "Define a new minor mode using ERC conventions. Symbol NAME is the name of the module. Symbol ALIAS is the alias to use, or nil. DOC is the documentation string to use for the minor mode. ENABLE-BODY is a list of expressions used to enable the mode. DISABLE-BODY is a list of expressions used to disable the mode. +If LOCAL-P is non-nil, the mode will be created as a buffer-local +mode. Rather than a global one. This will define a minor mode called erc-NAME-mode, possibly an alias erc-ALIAS-mode, as well as the helper functions @@ -958,7 +961,7 @@ With arg, turn ERC %S mode on if and only if arg is positive. %s" name name doc) nil nil nil - :global t :group (quote ,group) + :global (not ,local-p) :group (quote ,group) (if ,mode (,enable) (,disable))) Note that I think this change doesn't work if one is using XEmacs, since ERC-DEFINE-MINOR-MODE in erc-compat doesn't deal with any possible keyword arguments. I think that this changed version does work though. Could XEmacsers test it? | (defmacro erc-define-minor-mode (mode doc &optional init-value lighter | keymap &rest body) | "Define a minor mode like in Emacs." | ;; Deal with at least /some/ keywords. | ;; the rest don't seem to be as important. | (let (keyw globalp group) | (while (keywordp (setq keyw (car body))) | (setq body (cdr body)) | (case keyw | (:global (setq globalp (pop body))) | (:group (setq group (pop body))) | (t (pop body)))) | `(progn | (if ,group | (defcustom ,mode ,init-value | "Non-nil if the corresponding mode is enabled." | :group ,group | :type 'boolean) | (defvar ,mode ,init-value | "Non-nil if the corresponding mode is enabled.")) | (unless ,globalp | (make-variable-buffer-local ',mode)) | (defun ,mode (&optional arg) | ,doc | (interactive) | (setq ,mode (if arg | (> (prefix-numeric-value arg) 0) | (not ,mode))) | ,@body | ,mode) | (add-minor-mode ,mode ,lighter ,keymap)))) -- lawrence mitchell <we...@gm...> |