Use seq-doseq for iterating over strings in ERC

* lisp/erc/erc-common.el (erc--doarray): Remove unused function.
* lisp/erc/erc.el (erc--channel-mode-types, erc--process-channel-modes)
(erc--parse-user-modes): Replace `erc--doarray' with `seq-doseq'.
* test/lisp/erc/erc-tests.el (erc--doarray): Remove test.
This commit is contained in:
F. Jason Park 2025-10-30 22:58:26 -07:00
parent 12730179ac
commit c84aea1c1b
3 changed files with 3 additions and 35 deletions

View file

@ -641,25 +641,6 @@ Otherwise, return LIST-OR-ATOM."
(car ,list-or-atom) (car ,list-or-atom)
,list-or-atom)))) ,list-or-atom))))
(defmacro erc--doarray (spec &rest body)
"Map over ARRAY, running BODY with VAR bound to iteration element.
Behave more or less like `seq-doseq', but tailor operations for
arrays.
\(fn (VAR ARRAY [RESULT]) BODY...)"
(declare (indent 1) (debug ((symbolp form &optional form) body)))
(let ((array (make-symbol "array"))
(len (make-symbol "len"))
(i (make-symbol "i")))
`(let* ((,array ,(nth 1 spec))
(,len (length ,array))
(,i 0))
(while-let (((< ,i ,len))
(,(car spec) (aref ,array ,i)))
,@body
(cl-incf ,i))
,(nth 2 spec))))
(provide 'erc-common) (provide 'erc-common)
;;; erc-common.el ends here ;;; erc-common.el ends here

View file

@ -7607,7 +7607,7 @@ Use the getter of the same name to retrieve the current value.")
(ct (make-char-table 'erc--channel-mode-types)) (ct (make-char-table 'erc--channel-mode-types))
(type ?a)) (type ?a))
(dolist (cs types) (dolist (cs types)
(erc--doarray (c cs) (seq-doseq (c cs)
(aset ct c type)) (aset ct c type))
(cl-incf type)) (cl-incf type))
(make-erc--channel-mode-types :key key (make-erc--channel-mode-types :key key
@ -7626,7 +7626,7 @@ complement relevant letters in STRING."
(table (erc--channel-mode-types-table obj)) (table (erc--channel-mode-types-table obj))
(fallbackp (erc--channel-mode-types-fallbackp obj)) (fallbackp (erc--channel-mode-types-fallbackp obj))
(+p t)) (+p t))
(erc--doarray (c string) (seq-doseq (c string)
(cond ((= ?+ c) (setq +p t)) (cond ((= ?+ c) (setq +p t))
((= ?- c) (setq +p nil)) ((= ?- c) (setq +p nil))
((and status-letters (string-search (string c) status-letters)) ((and status-letters (string-search (string c) status-letters))
@ -7719,7 +7719,7 @@ dropped were they not already absent."
(let ((addp t) (let ((addp t)
;; ;;
redundant-add redundant-drop adding dropping) redundant-add redundant-drop adding dropping)
(erc--doarray (c string) (seq-doseq (c string)
(pcase c (pcase c
(?+ (setq addp t)) (?+ (setq addp t))
(?- (setq addp nil)) (?- (setq addp nil))

View file

@ -165,19 +165,6 @@
(advice-remove 'buffer-local-value 'erc-with-server-buffer))) (advice-remove 'buffer-local-value 'erc-with-server-buffer)))
(ert-deftest erc--doarray ()
(let ((array "abcdefg")
out)
;; No return form.
(should-not (erc--doarray (c array) (push c out)))
(should (equal out '(?g ?f ?e ?d ?c ?b ?a)))
;; Return form evaluated upon completion.
(setq out nil)
(should (= 42 (erc--doarray (c array (+ 39 (length out)))
(when (cl-evenp c) (push c out)))))
(should (equal out '(?f ?d ?b)))))
(ert-deftest erc-hide-prompt () (ert-deftest erc-hide-prompt ()
(let ((erc-hide-prompt erc-hide-prompt) (let ((erc-hide-prompt erc-hide-prompt)
(inhibit-message noninteractive) (inhibit-message noninteractive)