From: lawrence m. <we...@gm...> - 2003-11-09 19:19:57
|
What do people think of this change to erc's catalog handling. It replaces the current mechanism of defining umpteen different variables per catalog with defining one variable per catalog, a hash-table containing all the entries and their format strings. The only user-visible change is that erc-define-catalog is now a macro, rather than a function, so its arguments no longer have to be quoted. Should this be an undesirable backward incompatibilty, it's easy to change. Index: erc.el =================================================================== RCS file: /cvsroot/erc/erc/erc.el,v retrieving revision 1.584 diff -u -r1.584 erc.el --- erc.el 9 Nov 2003 18:08:35 -0000 1.584 +++ erc.el 9 Nov 2003 19:08:31 -0000 @@ -6768,21 +6768,37 @@ ;;; Message catalog -(defun erc-make-message-variable-name (catalog entry) - (intern (concat "erc-message-" - (symbol-name catalog) "-" (symbol-name entry)))) +(defun erc-make-message-catalog-name (catalog) + (intern (format "erc-message-catalog-%s" catalog))) +(defun erc-message-catalog (catalog) + (symbol-value (erc-make-message-catalog-name catalog))) + (defun erc-define-catalog-entry (catalog entry format-spec) - (set (erc-make-message-variable-name catalog entry) - format-spec)) + "Define an ENTRY in an ERC CATALOG, as FORMAT-SPEC. -(defun erc-define-catalog (catalog entries) - (dolist (entry entries) - (erc-define-catalog-entry catalog (car entry) (cdr entry)))) - -(erc-define-catalog - 'english - '((bad-ping-response . "Unexpected PING response from %n (time %t)") +See also `erc-define-catalog'." + (setq catalog (erc-message-catalog catalog)) + (puthash entry format-spec catalog)) + +(defmacro erc-define-catalog (catalog entries) + "Define an ERC message catalog. + +CATALOG should be the name of the language this catalog is in. +ENTRIES should be an alist mapping symbols to format strings. + +This defines a new variable `erc-message-catalog-CATALOG', a +hash-table, and populates it with ENTRIES." + `(progn + ,(or (boundp (erc-make-message-catalog-name catalog)) + `(defvar ,(erc-make-message-catalog-name catalog) + (make-hash-table :test #'eql) + ,(format "ERC %s catalog." catalog))) + (dolist (entry ',entries) + (erc-define-catalog-entry ',catalog (car entry) (cdr entry))))) + +(erc-define-catalog english + ((bad-ping-response . "Unexpected PING response from %n (time %t)") (bad-syntax . "Error occurred - incorrect usage?\n%c %u\n%d") (incorrect-args . "Incorrect arguments. Usage:\n%c %u\n%d") (cannot-find-file . "Cannot find file %f") @@ -6856,16 +6872,20 @@ (format ": %s" reason) ""))))) - (defvar erc-current-message-catalog 'english) (make-variable-buffer-local 'erc-current-message-catalog) + (defun erc-retrieve-catalog-entry (entry &optional catalog) - (unless catalog (setq catalog erc-current-message-catalog)) - (let ((var (erc-make-message-variable-name catalog entry))) - (if (boundp var) - (symbol-value var) - (when (boundp (erc-make-message-variable-name 'english entry)) - (symbol-value (erc-make-message-variable-name 'english entry)))))) + "Retrieve ENTRY from an ERC CATALOG. + +If CATALOG is nil, it defaults to the value of +`erc-current-message-catalog'. + +If CATALOG doesn't contain a value for ENTRY, the value of ENTRY in +`erc-message-catalog-english' is used." + (or catalog (setq catalog erc-current-message-catalog)) + (or (gethash entry (erc-message-catalog catalog) + (gethash entry (erc-message-catalog 'english))))) (defun erc-format-message (msg &rest args) (when (oddp (length args)) -- lawrence mitchell <we...@gm...> |