From 89bdb57f24e0bdc1a3d33d7124d93c9a1b45fa1d Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 17 Feb 2025 05:10:33 +0100 Subject: [PATCH] Prefer '(evenp A)' to '(= 0 (% A 2))' * lisp/calc/calc-comb.el (math-prime-test): * lisp/calc/calc-keypd.el (calc-keypad-press): * lisp/calc/calc-math.el (math-sqrt): (math-sqrt-raw): * lisp/calc/calc-misc.el (math-iipow): (math-iipow-show): * lisp/calc/calc-stat.el (calcFunc-vmedian): * lisp/calendar/cal-tex.el (cal-tex-cursor-filofax-2week): (cal-tex-cursor-filofax-daily): * lisp/elec-pair.el (electric-pair-post-self-insert-function): * lisp/emacs-lisp/checkdoc.el (checkdoc-in-example-string-p): * lisp/emacs-lisp/eieio.el (defclass): * lisp/emacs-lisp/ert-x.el (ert-propertized-string): * lisp/emacs-lisp/ert.el (ert--significant-plist-keys): (ert--plist-difference-explanation): * lisp/emacs-lisp/helper.el (Helper-help-scroller): * lisp/emacs-lisp/pcase.el (pcase-setq): * lisp/files-x.el (setq-connection-local): * lisp/gnus/gnus-uu.el (gnus-uu-post-encoded): * lisp/gnus/message.el (message-make-in-reply-to): * lisp/gnus/nndiary.el (nndiary-last-occurrence): (nndiary-next-occurrence): * lisp/mail/rfc2047.el (rfc2047-decode-region): * lisp/play/5x5.el (5x5-draw-grid): * lisp/play/gametree.el (gametree-compute-reduced-score): (gametree-insert-new-leaf): (gametree-break-line-here): * lisp/play/zone.el (zone-fret): * lisp/vc/ediff-ptch.el (ediff-get-patch-buffer): * lisp/yank-media.el (yank-media--utf-16-p): Prefer '(evenp A)' to '(= 0 (% A 2))' and variations thereof. --- lisp/calc/calc-comb.el | 4 ++-- lisp/calc/calc-keypd.el | 2 +- lisp/calc/calc-math.el | 4 ++-- lisp/calc/calc-misc.el | 4 ++-- lisp/calc/calc-stat.el | 2 +- lisp/calendar/cal-tex.el | 6 +++--- lisp/elec-pair.el | 2 +- lisp/emacs-lisp/checkdoc.el | 2 +- lisp/emacs-lisp/eieio.el | 2 +- lisp/emacs-lisp/ert-x.el | 2 +- lisp/emacs-lisp/ert.el | 6 +++--- lisp/emacs-lisp/helper.el | 2 +- lisp/emacs-lisp/pcase.el | 2 +- lisp/files-x.el | 2 +- lisp/gnus/gnus-uu.el | 2 +- lisp/gnus/message.el | 2 +- lisp/gnus/nndiary.el | 8 ++++---- lisp/mail/rfc2047.el | 2 +- lisp/play/5x5.el | 2 +- lisp/play/gametree.el | 6 +++--- lisp/play/zone.el | 2 +- lisp/vc/ediff-ptch.el | 2 +- lisp/yank-media.el | 2 +- 23 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lisp/calc/calc-comb.el b/lisp/calc/calc-comb.el index 1ac3347b758..6e2fc08fece 100644 --- a/lisp/calc/calc-comb.el +++ b/lisp/calc/calc-comb.el @@ -826,8 +826,8 @@ '(t)))) ((not (equal n (car math-prime-test-cache))) (cond ((if (consp n) - (= (% (nth 1 n) 2) 0) - (= (% n 2) 0)) + (evenp (nth 1 n)) + (evenp n)) '(nil 2)) ((if (consp n) (= (% (nth 1 n) 5) 0) diff --git a/lisp/calc/calc-keypd.el b/lisp/calc/calc-keypd.el index 2a9c8e75214..ad2b1741181 100644 --- a/lisp/calc/calc-keypd.el +++ b/lisp/calc/calc-keypd.el @@ -411,7 +411,7 @@ (if invhyp (calc-wrapper)) ; clear Inv and Hyp flags (unwind-protect (cond ((or (null cmd) - (= (% row 2) 0)) + (evenp row)) (beep)) ((and (> (minibuffer-depth) 0)) (cond (isstring diff --git a/lisp/calc/calc-math.el b/lisp/calc/calc-math.el index 53e5df30fad..49a64008e0a 100644 --- a/lisp/calc/calc-math.el +++ b/lisp/calc/calc-math.el @@ -402,7 +402,7 @@ If this can't be done, return NIL." (math-div (math-float num-sqrt) den-sqrt)))))) (and (eq (car-safe a) 'float) (if calc-symbolic-mode - (if (= (% (nth 2 a) 2) 0) + (if (evenp (nth 2 a)) (let ((res (cl-isqrt (nth 1 a)))) (if (= (* res res) (nth 1 a)) (math-make-float res (/ (nth 2 a) 2)) @@ -468,7 +468,7 @@ If this can't be done, return NIL." (t (if (null guess) (let ((ldiff (- (math-numdigs (nth 1 a)) 6))) - (or (= (% (+ (nth 2 a) ldiff) 2) 0) (setq ldiff (1+ ldiff))) + (or (evenp (+ (nth 2 a) ldiff)) (setq ldiff (1+ ldiff))) (setq guess (math-make-float (cl-isqrt (math-scale-int (nth 1 a) (- ldiff))) (/ (+ (nth 2 a) ldiff) 2))))) diff --git a/lisp/calc/calc-misc.el b/lisp/calc/calc-misc.el index 0772b76409a..564cbfc6537 100644 --- a/lisp/calc/calc-misc.el +++ b/lisp/calc/calc-misc.el @@ -898,7 +898,7 @@ loaded and the keystroke automatically re-typed." (defun math-iipow (a n) ; [O O S] (cond ((= n 0) 1) ((= n 1) a) - ((= (% n 2) 0) (math-iipow (math-mul a a) (/ n 2))) + ((evenp n) (math-iipow (math-mul a a) (/ n 2))) (t (math-mul a (math-iipow (math-mul a a) (/ n 2)))))) (defun math-iipow-show (a n) ; [O O S] @@ -906,7 +906,7 @@ loaded and the keystroke automatically re-typed." (let ((val (cond ((= n 0) 1) ((= n 1) a) - ((= (% n 2) 0) (math-iipow-show (math-mul a a) (/ n 2))) + ((evenp n) (math-iipow-show (math-mul a a) (/ n 2))) (t (math-mul a (math-iipow-show (math-mul a a) (/ n 2))))))) (math-working "pow" val) val)) diff --git a/lisp/calc/calc-stat.el b/lisp/calc/calc-stat.el index 57f42645e34..cbf85c51ab4 100644 --- a/lisp/calc/calc-stat.el +++ b/lisp/calc/calc-stat.el @@ -390,7 +390,7 @@ (math-reject-arg (car p) 'anglep)) (setq p (cdr p))) (setq flat (sort flat 'math-lessp)) - (if (= (% len 2) 0) + (if (evenp len) (math-div (math-add (nth (1- hlen) flat) (nth hlen flat)) 2) (nth hlen flat)))))) diff --git a/lisp/calendar/cal-tex.el b/lisp/calendar/cal-tex.el index c0bb9760810..f5bdfb970cc 100644 --- a/lisp/calendar/cal-tex.el +++ b/lisp/calendar/cal-tex.el @@ -1295,7 +1295,7 @@ Optional EVENT indicates a buffer position to use instead of point." (cal-tex-b-document) (cal-tex-cmd "\\pagestyle" "empty") (dotimes (i n) - (if (zerop (mod i 2)) + (if (evenp i) (insert "\\righthead") (insert "\\lefthead")) (cal-tex-arg @@ -1318,7 +1318,7 @@ Optional EVENT indicates a buffer position to use instead of point." (calendar-extract-year d)))))) (insert "%\n") (dotimes (_jdummy 7) - (if (zerop (mod i 2)) + (if (evenp i) (insert "\\rightday") (insert "\\leftday")) (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date))) @@ -1388,7 +1388,7 @@ Optional EVENT indicates a buffer position to use instead of point." (cal-tex-cmd "\\pagestyle" "empty") (dotimes (i n) (dotimes (j 4) - (let ((even (zerop (% j 2)))) + (let ((even (evenp j))) (insert (if even "\\righthead" "\\lefthead")) diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 10c14e55eae..aa2577300fd 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -558,7 +558,7 @@ The decision is taken by order of preference: ;; Backslash-escaped: no pairing, no skipping. ((save-excursion (goto-char beg) - (not (zerop (% (skip-syntax-backward "\\") 2)))) + (not (evenp (skip-syntax-backward "\\")))) (let ((current-prefix-arg (1- num))) (electric-pair-post-self-insert-function))) ;; Skip self. diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el index dd3da9ae8c0..3541e3d0a57 100644 --- a/lisp/emacs-lisp/checkdoc.el +++ b/lisp/emacs-lisp/checkdoc.el @@ -2109,7 +2109,7 @@ The text checked is between START and LIMIT." (goto-char start) (while (and (< (point) p) (re-search-forward "\\\\\"" limit t)) (setq c (1+ c))) - (and (< 0 c) (= (% c 2) 0)))))) + (and (< 0 c) (evenp c)))))) (defun checkdoc-in-abbreviation-p (begin) "Return non-nil if point is at an abbreviation. diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 8665934ebfd..0f029813f80 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el @@ -115,7 +115,7 @@ and reference them using the function `class-option'." (cl-check-type superclasses list) (cond ((and (stringp (car options-and-doc)) - (/= 1 (% (length options-and-doc) 2))) + (evenp (length options-and-doc))) (error "Too many arguments to `defclass'")) ((and (symbolp (car options-and-doc)) (oddp (length options-and-doc))) diff --git a/lisp/emacs-lisp/ert-x.el b/lisp/emacs-lisp/ert-x.el index 147787d3d38..0dacec130a0 100644 --- a/lisp/emacs-lisp/ert-x.el +++ b/lisp/emacs-lisp/ert-x.el @@ -260,7 +260,7 @@ structure with the plists in ARGS." (string (let ((begin (point))) (insert x) (set-text-properties begin (point) current-plist))) - (list (unless (zerop (mod (length x) 2)) + (list (unless (evenp (length x)) (error "Odd number of args in plist: %S" x)) (setq current-plist x)))) (buffer-string))) diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 5d1b9f2acbb..e8012326eb3 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -576,7 +576,7 @@ Return nil if they are." (defun ert--significant-plist-keys (plist) "Return the keys of PLIST that have non-null values, in order." - (cl-assert (zerop (mod (length plist) 2)) t) + (cl-assert (evenp (length plist)) t) (cl-loop for (key value . rest) on plist by #'cddr unless (or (null value) (memq key accu)) collect key into accu finally (cl-return accu))) @@ -587,8 +587,8 @@ Return nil if they are." Returns nil if they are equivalent, i.e., have the same value for each key, where absent values are treated as nil. The order of key/value pairs in each list does not matter." - (cl-assert (zerop (mod (length a) 2)) t) - (cl-assert (zerop (mod (length b) 2)) t) + (cl-assert (evenp (length a)) t) + (cl-assert (evenp (length b)) t) ;; Normalizing the plists would be another way to do this but it ;; requires a total ordering on all lisp objects (since any object ;; is valid as a text property key). Perhaps defining such an diff --git a/lisp/emacs-lisp/helper.el b/lisp/emacs-lisp/helper.el index d8f758d2fe5..8a173219545 100644 --- a/lisp/emacs-lisp/helper.el +++ b/lisp/emacs-lisp/helper.el @@ -80,7 +80,7 @@ (recenter)) ((and (or (eq continue 'backspace) (eq continue ?\177)) - (zerop (% state 2))) + (evenp state)) (scroll-down)) (t (setq continue nil)))))))) diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index a6a4751f49a..c68b8961ee3 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -370,7 +370,7 @@ undetected, binding variables to arbitrary values, such as nil. (cond (args (let ((arg-length (length args))) - (unless (= 0 (mod arg-length 2)) + (unless (evenp arg-length) (signal 'wrong-number-of-arguments (list 'pcase-setq (+ 2 arg-length))))) (let ((result)) diff --git a/lisp/files-x.el b/lisp/files-x.el index 0e8b99c1e4f..3f57321eb53 100644 --- a/lisp/files-x.el +++ b/lisp/files-x.el @@ -914,7 +914,7 @@ earlier in the `setq-connection-local'. The return value of the \(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 ((set-expr nil) (profile-vars nil)) diff --git a/lisp/gnus/gnus-uu.el b/lisp/gnus/gnus-uu.el index 4372fd58669..bf745be0f6e 100644 --- a/lisp/gnus/gnus-uu.el +++ b/lisp/gnus/gnus-uu.el @@ -2098,7 +2098,7 @@ If no file has been included, the user will be asked for a file." (make-string minlen ?-) file-name i parts (make-string - (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-))) + (if (evenp whole-len) (1- minlen) minlen) ?-))) (goto-char (point-min)) (when (re-search-forward "^Subject: " nil t) diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index dede5520d66..46c3550418f 100644 --- a/lisp/gnus/message.el +++ b/lisp/gnus/message.el @@ -6035,7 +6035,7 @@ In posting styles use `(\"Expires\" (make-expires-date 30))'." (while (search-forward "\"" nil t) (when (prog2 (backward-char) - (zerop (% (skip-chars-backward "\\\\") 2)) + (evenp (skip-chars-backward "\\\\")) (goto-char (match-beginning 0))) (insert "\\")) (forward-char)) diff --git a/lisp/gnus/nndiary.el b/lisp/gnus/nndiary.el index de051745f92..7bc46fa88f8 100644 --- a/lisp/gnus/nndiary.el +++ b/lisp/gnus/nndiary.el @@ -1353,9 +1353,9 @@ all. This may very well take some time.") (max (cond ((= month 2) (if (date-leap-year-p year) 29 28)) ((<= month 7) - (if (zerop (% month 2)) 30 31)) + (if (evenp month) 30 31)) (t - (if (zerop (% month 2)) 31 30)))) + (if (evenp month) 31 30)))) (doms dom-list) (dows dow-list) day days) @@ -1456,9 +1456,9 @@ all. This may very well take some time.") (max (cond ((= month 2) (if (date-leap-year-p year) 29 28)) ((<= month 7) - (if (zerop (% month 2)) 30 31)) + (if (evenp month) 30 31)) (t - (if (zerop (% month 2)) 31 30)))) + (if (evenp month) 31 30)))) (doms dom-list) (dows dow-list) day days) diff --git a/lisp/mail/rfc2047.el b/lisp/mail/rfc2047.el index 38b924851fc..13d1ac320b0 100644 --- a/lisp/mail/rfc2047.el +++ b/lisp/mail/rfc2047.el @@ -1076,7 +1076,7 @@ other than `\"' and `\\' in quoted strings." (while (search-forward "\"" end t) (when (prog2 (backward-char) - (zerop (% (skip-chars-backward "\\\\") 2)) + (evenp (skip-chars-backward "\\\\")) (goto-char (match-beginning 0))) (insert "\\")) (forward-char)) diff --git a/lisp/play/5x5.el b/lisp/play/5x5.el index 3c5a3601927..e7638ef0f59 100644 --- a/lisp/play/5x5.el +++ b/lisp/play/5x5.el @@ -312,7 +312,7 @@ Quit current game \\[5x5-quit-game]" (forward-char (+ 1 (/ (1+ 5x5-x-scale) 2))) (dotimes (x 5x5-grid-size) (when (5x5-cell solution-grid y x) - (if (= 0 (mod 5x5-x-scale 2)) + (if (evenp 5x5-x-scale) (progn (insert "()") (delete-region (point) (+ (point) 2)) diff --git a/lisp/play/gametree.el b/lisp/play/gametree.el index c0d43944e67..8ffddfc7275 100644 --- a/lisp/play/gametree.el +++ b/lisp/play/gametree.el @@ -347,7 +347,7 @@ Subnodes which have been manually scored are honored." ;; be either a leaf child, or a subheading. (let ((running gametree-default-score) (minmax - (if (= 0 (mod (gametree-current-branch-ply) 2)) + (if (evenp (gametree-current-branch-ply)) 'max 'min))) (while (and (not (eobp)) (= 0 (gametree-current-branch-depth))) ;handle leaves @@ -395,7 +395,7 @@ depth AT-DEPTH or smaller is found." (gametree-current-branch-ply))))) (goto-char (1- (point))) (insert "\n") - (insert (format (if (= 0 (mod starting-plies 2)) + (insert (format (if (evenp starting-plies) gametree-full-ply-format gametree-half-ply-format) (/ starting-plies 2)))))) @@ -450,7 +450,7 @@ only work of Black's moves are explicitly numbered, for instance gametree-full-ply-regexp "\\|" gametree-half-ply-regexp "\\)"))) (progn - (insert (format (if (= 0 (mod (gametree-looking-at-ply) 2)) + (insert (format (if (evenp (gametree-looking-at-ply)) gametree-full-ply-format gametree-half-ply-format) (/ (gametree-looking-at-ply) 2))) diff --git a/lisp/play/zone.el b/lisp/play/zone.el index b294dd6af67..39a33f1e2a0 100644 --- a/lisp/play/zone.el +++ b/lisp/play/zone.el @@ -454,7 +454,7 @@ run a specific program. The program must be a member of (dotimes (i 20) (goto-char pos) (delete-char 1) - (insert (if (= 0 (% i 2)) hmm c-string)) + (insert (if (evenp i) hmm c-string)) (zone-park/sit-for wbeg (setq wait (* wait 0.8)))) (delete-char -1) (insert c-string))) diff --git a/lisp/vc/ediff-ptch.el b/lisp/vc/ediff-ptch.el index 42b0d6850ef..1e66a016375 100644 --- a/lisp/vc/ediff-ptch.el +++ b/lisp/vc/ediff-ptch.el @@ -549,7 +549,7 @@ an optional argument, then use it." (cond ((ediff-buffer-live-p patch-buf)) ;; even prefix arg: patch in buffer - ((and (integerp arg) (eq 0 (mod arg 2))) + ((and (integerp arg) (evenp arg)) (setq patch-buf (ediff-prompt-for-patch-buffer))) ;; odd prefix arg: get patch from a file ((and (integerp arg) (oddp arg)) diff --git a/lisp/yank-media.el b/lisp/yank-media.el index 600cc0ffaf5..bb62ba272d3 100644 --- a/lisp/yank-media.el +++ b/lisp/yank-media.el @@ -172,7 +172,7 @@ non-supported selection data types." data))) (defun yank-media--utf-16-p (data) - (and (zerop (mod (length data) 2)) + (and (evenp (length data)) (let ((stats (vector 0 0))) (dotimes (i (length data)) (when (zerop (elt data i))