From: Stefan Kangas Date: Mon, 17 Feb 2025 22:00:54 +0000 (+0100) Subject: Prefer oddp/evenp to open-coding in a few more cases X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=aeab411ac5e62ba50124839cb5735a12e14856f4;p=emacs.git 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 . (cherry picked from commit 515542b653c438014eda844eacc96cf23cfaaa2d) --- diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index 18dd0f42f8e..1ad9c084ed9 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -2092,8 +2092,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 ee0e9a53f1b..2ce2c45b51b 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -1062,7 +1062,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 a0e546101a4..39dac326da5 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -2853,7 +2853,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 78fb3f5d368..8f9216d2cc2 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -9442,11 +9442,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 7a013c750ae..5b224b1fc67 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 ad85cc2cdbd..954a1d9b972 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -2177,7 +2177,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))