From 515542b653c438014eda844eacc96cf23cfaaa2d Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 17 Feb 2025 23:00:54 +0100 Subject: [PATCH] Prefer oddp/evenp to open-coding in a few more cases * lisp/arc-mode.el (archive-zip-summarize): * lisp/cus-edit.el (setopt): * lisp/isearch.el (isearch-backslash): * lisp/simple.el (blink-paren-post-self-insert-function): * lisp/subr.el (setq-local, buffer-local-set-state): * lisp/term.el (term-within-quotes): * test/src/data-tests.el (test-bool-vector-bv-from-hex-string): Use oddp/evenp instead of open-coding them. Reported by Pip Cet . --- lisp/arc-mode.el | 3 +-- lisp/cus-edit.el | 2 +- lisp/isearch.el | 2 +- lisp/simple.el | 10 +++++----- lisp/subr.el | 4 ++-- lisp/term.el | 2 +- test/src/data-tests.el | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index e369b79cf06..b28669ca4cf 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -2090,8 +2090,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." ((memq creator '(0 5 6 7 10 11 15)) ; Dos etc. (logior ?\444 (if isdir (logior 16384 ?\111) 0) - (if (zerop - (logand 1 (get-byte (+ p 38)))) + (if (evenp (get-byte (+ p 38))) ?\222 0))) (t nil))) (fiddle (and archive-zip-case-fiddle diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index febbc8d1b8b..0f66b27f85b 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -1060,7 +1060,7 @@ even if it doesn't match the type.) \(fn [VARIABLE VALUE]...)" (declare (debug setq)) - (unless (zerop (mod (length pairs) 2)) + (unless (evenp (length pairs)) (error "PAIRS must have an even number of variable/value members")) (let ((expr nil)) (while pairs diff --git a/lisp/isearch.el b/lisp/isearch.el index c2e41927f08..e31c5f7e59a 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -2893,7 +2893,7 @@ The command accepts Unicode names like \"smiling face\" or (defun isearch-backslash (str) "Return t if STR ends in an odd number of backslashes." - (= (mod (- (length str) (string-match "\\\\*\\'" str)) 2) 1)) + (oddp (- (length str) (string-match "\\\\*\\'" str)))) (defun isearch-fallback (want-backslash &optional allow-invalid to-barrier) "Return point to previous successful match to allow regexp liberalization. diff --git a/lisp/simple.el b/lisp/simple.el index e1c0dd4a092..c46b094f5a3 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -9622,11 +9622,11 @@ More precisely, a char with closeparen syntax is self-inserted.") ;; Verify an even number of quoting characters precede the close. ;; FIXME: Also check if this parenthesis closes a comment as ;; can happen in Pascal and SML. - (= 1 (logand 1 (- (point) - (save-excursion - (forward-char -1) - (skip-syntax-backward "/\\") - (point)))))) + (oddp (- (point) + (save-excursion + (forward-char -1) + (skip-syntax-backward "/\\") + (point))))) (funcall blink-paren-function))) (put 'blink-paren-post-self-insert-function 'priority 100) diff --git a/lisp/subr.el b/lisp/subr.el index 7fdcf6731e7..fc438832340 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -176,7 +176,7 @@ pair. \(fn [VARIABLE VALUE]...)" (declare (debug setq)) - (unless (zerop (mod (length pairs) 2)) + (unless (evenp (length pairs)) (error "PAIRS must have an even number of variable/value members")) (let ((expr nil)) (while pairs @@ -217,7 +217,7 @@ in order to restore the state of the local variables set via this macro. \(fn [VARIABLE VALUE]...)" (declare (debug setq)) - (unless (zerop (mod (length pairs) 2)) + (unless (evenp (length pairs)) (error "PAIRS must have an even number of variable/value members")) `(prog1 (buffer-local-set-state--get ',pairs) diff --git a/lisp/term.el b/lisp/term.el index 753fffe5ec2..67de50ad04f 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -2181,7 +2181,7 @@ A useful command to bind to SPC. See `term-replace-by-expanded-history'." Quotes are single and double." (let ((countsq (term-how-many-region "\\(^\\|[^\\]\\)'" beg end)) (countdq (term-how-many-region "\\(^\\|[^\\]\\)\"" beg end))) - (or (= (mod countsq 2) 1) (= (mod countdq 2) 1)))) + (or (oddp countsq) (oddp countdq)))) (defun term-how-many-region (regexp beg end) "Return number of matches for REGEXP from BEG to END." diff --git a/test/src/data-tests.el b/test/src/data-tests.el index abbc88dea4c..44c786ac579 100644 --- a/test/src/data-tests.el +++ b/test/src/data-tests.el @@ -184,7 +184,7 @@ this is exactly representable and is greater than (let ((i 0)) (dolist (n (nreverse nibbles)) (dotimes (_ 4) - (aset bv i (> (logand 1 n) 0)) + (aset bv i (oddp n)) (cl-incf i) (setf n (ash n -1))))) bv))