(,disable)))
,(erc--assemble-toggle local-p name enable mode t enable-body)
,(erc--assemble-toggle local-p name disable mode nil disable-body)
- ,(when (and alias (not (eq name alias)))
- `(defalias
- ',(intern
- (format "erc-%s-mode"
- (downcase (symbol-name alias))))
- #',mode))
+ ,@(and-let* ((alias)
+ ((not (eq name alias)))
+ (aname (intern (format "erc-%s-mode"
+ (downcase (symbol-name alias))))))
+ `((defalias ',aname #',mode)
+ (put ',aname 'erc-module ',(erc--normalize-module-symbol name))))
+ (put ',mode 'erc-module ',(erc--normalize-module-symbol name))
;; For find-function and find-variable.
(put ',mode 'definition-name ',name)
(put ',enable 'definition-name ',name)
(let ((out (list (reverse new-modes))))
(pcase-dolist (`(,k . ,v) old-vars)
(when (and (string-prefix-p "erc-" (symbol-name k))
- (string-suffix-p "-mode" (symbol-name k)))
+ (string-suffix-p "-mode" (symbol-name k))
+ (get k 'erc-module))
(if v
(cl-pushnew k (car out))
(setf (car out) (delq k (car out)))
(erc-determine-parameters server port nick full-name user passwd)
- (save-excursion (run-mode-hooks))
- (dolist (mod (car delayed-modules)) (funcall mod +1))
- (dolist (var (cdr delayed-modules)) (set var nil))
+ ;; FIXME consolidate this prompt-setup logic with the pass above.
;; set up prompt
(unless continued-session
(erc-display-prompt)
(goto-char (point-max)))
+ (save-excursion (run-mode-hooks)
+ (dolist (mod (car delayed-modules)) (funcall mod +1))
+ (dolist (var (cdr delayed-modules)) (set var nil)))
+
;; Saving log file on exit
(run-hook-with-args 'erc-connect-pre-hook buffer)
(setq calls nil)))))
(ert-deftest erc--merge-local-modes ()
-
- (ert-info ("No existing modes")
- (let ((old '((a) (b . t)))
- (new '(erc-c-mode erc-d-mode)))
- (should (equal (erc--merge-local-modes new old)
- '((erc-c-mode erc-d-mode))))))
-
- (ert-info ("Active existing added, inactive existing removed, deduped")
- (let ((old '((a) (erc-b-mode) (c . t) (erc-d-mode . t) (erc-e-mode . t)))
- (new '(erc-b-mode erc-d-mode)))
- (should (equal (erc--merge-local-modes new old)
- '((erc-d-mode erc-e-mode) . (erc-b-mode)))))))
+ (cl-letf (((get 'erc-b-mode 'erc-module) 'b)
+ ((get 'erc-c-mode 'erc-module) 'c)
+ ((get 'erc-d-mode 'erc-module) 'd)
+ ((get 'erc-e-mode 'erc-module) 'e))
+
+ (ert-info ("No existing modes")
+ (let ((old '((a) (b . t)))
+ (new '(erc-c-mode erc-d-mode)))
+ (should (equal (erc--merge-local-modes new old)
+ '((erc-c-mode erc-d-mode))))))
+
+ (ert-info ("Active existing added, inactive existing removed, deduped")
+ (let ((old '((a) (erc-b-mode) (c . t) (erc-d-mode . t) (erc-e-mode . t)))
+ (new '(erc-b-mode erc-d-mode)))
+ (should (equal (erc--merge-local-modes new old)
+ '((erc-d-mode erc-e-mode) . (erc-b-mode))))))
+
+ (ert-info ("Non-module erc-prefixed mode ignored")
+ (let ((old '((erc-b-mode) (erc-f-mode . t) (erc-d-mode . t)))
+ (new '(erc-b-mode)))
+ (should (equal (erc--merge-local-modes new old)
+ '((erc-d-mode) . (erc-b-mode))))))))
(ert-deftest define-erc-module--global ()
(let ((global-module '(define-erc-module mname malias
(ignore c) (ignore d))
(defalias 'erc-malias-mode #'erc-mname-mode)
+ (put 'erc-malias-mode 'erc-module 'mname)
+ (put 'erc-mname-mode 'erc-module 'mname)
(put 'erc-mname-mode 'definition-name 'mname)
(put 'erc-mname-enable 'definition-name 'mname)
(put 'erc-mname-disable 'definition-name 'mname))))))
(ert-deftest define-erc-module--local ()
- (let* ((global-module '(define-erc-module mname malias
+ (let* ((global-module '(define-erc-module mname nil ; no alias
"Some docstring"
((ignore a) (ignore b))
((ignore c) (ignore d))
(setq erc-mname-mode nil)
(ignore c) (ignore d))))
- (defalias 'erc-malias-mode #'erc-mname-mode)
-
+ (put 'erc-mname-mode 'erc-module 'mname)
(put 'erc-mname-mode 'definition-name 'mname)
(put 'erc-mname-enable 'definition-name 'mname)
(put 'erc-mname-disable 'definition-name 'mname))))))