diff options
| author | F. Jason Park | 2024-01-05 07:20:34 -0800 |
|---|---|---|
| committer | F. Jason Park | 2024-01-07 15:11:26 -0800 |
| commit | 50f430ebcd87b77207013f97e6e5d1b8fe93f990 (patch) | |
| tree | d294497a2a37a760f546299f0398b4dc5602dba0 | |
| parent | 37e87bc3eeb8e62e2900d73cf4dd9fc9e942d66d (diff) | |
| download | emacs-50f430ebcd87b77207013f97e6e5d1b8fe93f990.tar.gz emacs-50f430ebcd87b77207013f97e6e5d1b8fe93f990.zip | |
Clarify purpose of module aliases in ERC
* doc/misc/erc.texi: Mention that aliases should not be defined for
new modules.
* lisp/erc/erc-common.el (define-erc-module): Refactor slightly for
readability.
(erc-with-all-buffers-of-server): Redo doc string.
* lisp/erc/erc-pcomplete.el: Declare `completion' module's feature and
group as being `erc-pcomplete'.
* test/lisp/erc/erc-tests.el (erc--find-group--real): Assert group
lookup works for "normalized" module name `completion' of
`erc-pcomplete-mode'.
| -rw-r--r-- | doc/misc/erc.texi | 8 | ||||
| -rw-r--r-- | lisp/erc/erc-common.el | 31 | ||||
| -rw-r--r-- | lisp/erc/erc-pcomplete.el | 2 | ||||
| -rw-r--r-- | test/lisp/erc/erc-tests.el | 1 |
4 files changed, 28 insertions, 14 deletions
diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi index 52c7477c9dd..f877fb681fe 100644 --- a/doc/misc/erc.texi +++ b/doc/misc/erc.texi | |||
| @@ -678,6 +678,14 @@ signals an error. Users defining personal modules in an init file | |||
| 678 | should @code{(provide 'erc-my-module)} somewhere to placate ERC. | 678 | should @code{(provide 'erc-my-module)} somewhere to placate ERC. |
| 679 | Dynamically generating modules on the fly is not supported. | 679 | Dynamically generating modules on the fly is not supported. |
| 680 | 680 | ||
| 681 | Some older built-in modules have a second name along with a second | ||
| 682 | minor-mode toggle, which is just a function alias for its primary | ||
| 683 | counterpart. For practical reasons, ERC does not define a | ||
| 684 | corresponding variable alias because contending with indirect | ||
| 685 | variables complicates bookkeeping tasks, such as persisting module | ||
| 686 | state across IRC sessions. New modules should definitely avoid | ||
| 687 | defining aliases without a good reason. | ||
| 688 | |||
| 681 | Some packages have been known to autoload a module's definition | 689 | Some packages have been known to autoload a module's definition |
| 682 | instead of its minor-mode command, which severs the link between the | 690 | instead of its minor-mode command, which severs the link between the |
| 683 | library and the module. This means that enabling the mode by invoking | 691 | library and the module. This means that enabling the mode by invoking |
diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el index 2581e40f850..28ab6aad466 100644 --- a/lisp/erc/erc-common.el +++ b/lisp/erc/erc-common.el | |||
| @@ -333,6 +333,7 @@ instead of a `set' state, which precludes any actual saving." | |||
| 333 | (read (current-buffer)))) | 333 | (read (current-buffer)))) |
| 334 | 334 | ||
| 335 | (defmacro erc--find-feature (name alias) | 335 | (defmacro erc--find-feature (name alias) |
| 336 | ;; Don't use this outside of the file that defines NAME. | ||
| 336 | `(pcase (erc--find-group ',name ,(and alias (list 'quote alias))) | 337 | `(pcase (erc--find-group ',name ,(and alias (list 'quote alias))) |
| 337 | ('erc (and-let* ((file (or (macroexp-file-name) buffer-file-name))) | 338 | ('erc (and-let* ((file (or (macroexp-file-name) buffer-file-name))) |
| 338 | (intern (file-name-base file)))) | 339 | (intern (file-name-base file)))) |
| @@ -350,8 +351,12 @@ See Info node `(elisp) Defining Minor Modes' for more.") | |||
| 350 | (defmacro define-erc-module (name alias doc enable-body disable-body | 351 | (defmacro define-erc-module (name alias doc enable-body disable-body |
| 351 | &optional local-p) | 352 | &optional local-p) |
| 352 | "Define a new minor mode using ERC conventions. | 353 | "Define a new minor mode using ERC conventions. |
| 353 | Symbol NAME is the name of the module. | 354 | Expect NAME to be the module's name and ALIAS, when non-nil, to |
| 354 | Symbol ALIAS is the alias to use, or nil. | 355 | be a retired name used only for compatibility purposes. In new |
| 356 | code, assume NAME is the same symbol users should specify when | ||
| 357 | customizing `erc-modules' (see info node `(erc) Module Loading' | ||
| 358 | for more on naming). | ||
| 359 | |||
| 355 | DOC is the documentation string to use for the minor mode. | 360 | DOC is the documentation string to use for the minor mode. |
| 356 | ENABLE-BODY is a list of expressions used to enable the mode. | 361 | ENABLE-BODY is a list of expressions used to enable the mode. |
| 357 | DISABLE-BODY is a list of expressions used to disable the mode. | 362 | DISABLE-BODY is a list of expressions used to disable the mode. |
| @@ -382,7 +387,10 @@ Example: | |||
| 382 | (let* ((sn (symbol-name name)) | 387 | (let* ((sn (symbol-name name)) |
| 383 | (mode (intern (format "erc-%s-mode" (downcase sn)))) | 388 | (mode (intern (format "erc-%s-mode" (downcase sn)))) |
| 384 | (enable (intern (format "erc-%s-enable" (downcase sn)))) | 389 | (enable (intern (format "erc-%s-enable" (downcase sn)))) |
| 385 | (disable (intern (format "erc-%s-disable" (downcase sn))))) | 390 | (disable (intern (format "erc-%s-disable" (downcase sn)))) |
| 391 | (nmodule (erc--normalize-module-symbol name)) | ||
| 392 | (amod (and alias (intern (format "erc-%s-mode" | ||
| 393 | (downcase (symbol-name alias))))))) | ||
| 386 | `(progn | 394 | `(progn |
| 387 | (define-minor-mode | 395 | (define-minor-mode |
| 388 | ,mode | 396 | ,mode |
| @@ -399,13 +407,9 @@ if ARG is omitted or nil. | |||
| 399 | (if ,mode (,enable) (,disable)))) | 407 | (if ,mode (,enable) (,disable)))) |
| 400 | ,(erc--assemble-toggle local-p name enable mode t enable-body) | 408 | ,(erc--assemble-toggle local-p name enable mode t enable-body) |
| 401 | ,(erc--assemble-toggle local-p name disable mode nil disable-body) | 409 | ,(erc--assemble-toggle local-p name disable mode nil disable-body) |
| 402 | ,@(and-let* ((alias) | 410 | ,@(and amod `((defalias ',amod #',mode) |
| 403 | ((not (eq name alias))) | 411 | (put ',amod 'erc-module ',nmodule))) |
| 404 | (aname (intern (format "erc-%s-mode" | 412 | (put ',mode 'erc-module ',nmodule) |
| 405 | (downcase (symbol-name alias)))))) | ||
| 406 | `((defalias ',aname #',mode) | ||
| 407 | (put ',aname 'erc-module ',(erc--normalize-module-symbol name)))) | ||
| 408 | (put ',mode 'erc-module ',(erc--normalize-module-symbol name)) | ||
| 409 | ;; For find-function and find-variable. | 413 | ;; For find-function and find-variable. |
| 410 | (put ',mode 'definition-name ',name) | 414 | (put ',mode 'definition-name ',name) |
| 411 | (put ',enable 'definition-name ',name) | 415 | (put ',enable 'definition-name ',name) |
| @@ -462,10 +466,9 @@ If no server buffer exists, return nil." | |||
| 462 | ,@body))))) | 466 | ,@body))))) |
| 463 | 467 | ||
| 464 | (defmacro erc-with-all-buffers-of-server (process pred &rest forms) | 468 | (defmacro erc-with-all-buffers-of-server (process pred &rest forms) |
| 465 | "Execute FORMS in all buffers which have same process as this server. | 469 | "Evaluate FORMS in all buffers of PROCESS in which PRED returns non-nil. |
| 466 | FORMS will be evaluated in all buffers having the process PROCESS and | 470 | When PROCESS is nil, do so in all ERC buffers. When PRED is nil, |
| 467 | where PRED matches or in all buffers of the server process if PRED is | 471 | run FORMS unconditionally." |
| 468 | nil." | ||
| 469 | (declare (indent 2) (debug (form form body))) | 472 | (declare (indent 2) (debug (form form body))) |
| 470 | (macroexp-let2 nil pred pred | 473 | (macroexp-let2 nil pred pred |
| 471 | `(erc-buffer-filter (lambda () | 474 | `(erc-buffer-filter (lambda () |
diff --git a/lisp/erc/erc-pcomplete.el b/lisp/erc/erc-pcomplete.el index 52ebdc83e5e..05cbaf3872f 100644 --- a/lisp/erc/erc-pcomplete.el +++ b/lisp/erc/erc-pcomplete.el | |||
| @@ -58,7 +58,9 @@ add this string to nicks completed." | |||
| 58 | 58 | ||
| 59 | ;;;###autoload(put 'Completion 'erc--module 'completion) | 59 | ;;;###autoload(put 'Completion 'erc--module 'completion) |
| 60 | ;;;###autoload(put 'pcomplete 'erc--module 'completion) | 60 | ;;;###autoload(put 'pcomplete 'erc--module 'completion) |
| 61 | ;;;###autoload(put 'completion 'erc--feature 'erc-pcomplete) | ||
| 61 | ;;;###autoload(autoload 'erc-completion-mode "erc-pcomplete" nil t) | 62 | ;;;###autoload(autoload 'erc-completion-mode "erc-pcomplete" nil t) |
| 63 | (put 'completion 'erc-group 'erc-pcomplete) | ||
| 62 | (define-erc-module pcomplete Completion | 64 | (define-erc-module pcomplete Completion |
| 63 | "In ERC Completion mode, the TAB key does completion whenever possible." | 65 | "In ERC Completion mode, the TAB key does completion whenever possible." |
| 64 | ((add-hook 'erc-mode-hook #'pcomplete-erc-setup) | 66 | ((add-hook 'erc-mode-hook #'pcomplete-erc-setup) |
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index a71cc806f6a..2318fed28f2 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el | |||
| @@ -3186,6 +3186,7 @@ | |||
| 3186 | (should (eq (erc--find-group 'autojoin) 'erc-autojoin)) | 3186 | (should (eq (erc--find-group 'autojoin) 'erc-autojoin)) |
| 3187 | (should (eq (erc--find-group 'pcomplete 'Completion) 'erc-pcomplete)) | 3187 | (should (eq (erc--find-group 'pcomplete 'Completion) 'erc-pcomplete)) |
| 3188 | (should (eq (erc--find-group 'capab-identify) 'erc-capab)) | 3188 | (should (eq (erc--find-group 'capab-identify) 'erc-capab)) |
| 3189 | (should (eq (erc--find-group 'completion) 'erc-pcomplete)) | ||
| 3189 | ;; No group specified. | 3190 | ;; No group specified. |
| 3190 | (should (eq (erc--find-group 'smiley nil) 'erc)) | 3191 | (should (eq (erc--find-group 'smiley nil) 'erc)) |
| 3191 | (should (eq (erc--find-group 'unmorse nil) 'erc))) | 3192 | (should (eq (erc--find-group 'unmorse nil) 'erc))) |