]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer '(evenp A)' to '(= 0 (% A 2))'
authorStefan Kangas <stefankangas@gmail.com>
Mon, 17 Feb 2025 04:10:33 +0000 (05:10 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 18 Feb 2025 08:51:24 +0000 (09:51 +0100)
* 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.

(cherry picked from commit 89bdb57f24e0bdc1a3d33d7124d93c9a1b45fa1d)

19 files changed:
lisp/calc/calc-comb.el
lisp/calc/calc-keypd.el
lisp/calc/calc-math.el
lisp/calc/calc-misc.el
lisp/calc/calc-stat.el
lisp/calendar/cal-tex.el
lisp/emacs-lisp/checkdoc.el
lisp/emacs-lisp/eieio.el
lisp/emacs-lisp/ert-x.el
lisp/emacs-lisp/ert.el
lisp/emacs-lisp/pcase.el
lisp/files-x.el
lisp/gnus/gnus-uu.el
lisp/gnus/nndiary.el
lisp/play/5x5.el
lisp/play/gametree.el
lisp/play/zone.el
lisp/vc/ediff-ptch.el
lisp/yank-media.el

index 1ac3347b7585300c5dd11ee4f8efc9469c31e75e..6e2fc08fecedaa99bffc99d8823f529a405b2db6 100644 (file)
                       '(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)
index a7cbe0ec31f833a0f46e4bc9e49590d15615fbb5..ed0282b5a9b167986d636f3c65205ff388732117 100644 (file)
     (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
index 88934c350276004e58b32223ab1f64db45e54ba2..18a2632146bbb4287f5d63ab563b41c140864cd8 100644 (file)
@@ -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)))))
index 0772b76409ae31a07cb34a06a3e0902968ad4811..564cbfc653744597d14c52e4f30574091fe3d0c3 100644 (file)
@@ -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))
index 57f42645e348da24f4719c845827833ac82b6a30..cbf85c51ab4d00d7e54d7954c9181e451ddf0c6b 100644 (file)
              (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))))))
 
index 688e842604d18af9d849d8fbfd28df00c68e98e1..f5bdfb970ccb2423375316731fcba48ed523ea84 100644 (file)
@@ -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)))
index 8d2e116dfa932c76747baedc71c7b31656abef31..a6fdf5cad6be965c1b3dc67fe34011dfd62015d2 100644 (file)
@@ -2110,7 +2110,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.
index 666c90181a41fdd31b6f19f88f039a12a4efcf70..6db7f26bbc2863980eafdf10580a69011c76581c 100644 (file)
@@ -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)))
index 3475d4499510a0b088b54a2747c471e3dcc32dc2..f3bc7d0bede5090baf0fdc22d8642e1d23a32c65 100644 (file)
@@ -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)))
index 2fb15aed2b66eb9e10fc4ee0096c08dbfff3bc44..a0c72d2a0c89131659cf3c686d6037f51fe87841 100644 (file)
@@ -569,7 +569,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)))
@@ -580,8 +580,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
index 483aa9b8434175b80900603111d27362ccd2cb75..bc2ffc590cca216569e4bcc51eb63b27c4760b1d 100644 (file)
@@ -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))
index cdc38508c5ac9b016bf4e4305542dd70b67bb7d5..21756f01b78f669865b60e5c2096b5238044c1a2 100644 (file)
@@ -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))
index 4372fd58669245bfbcedf940a38fc56e317b2520..bf745be0f6e1e808303c7067747ced85d490b641 100644 (file)
@@ -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)
index de051745f9248d4cb2872faadd29c912f9ac2d52..7bc46fa88f8e009613760cc144abb8ed1abf2391 100644 (file)
@@ -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)
index 3c5a36019271c51de03df447544d029977fbef21..e7638ef0f59d5ae04df165adcc6a6570156773b2 100644 (file)
@@ -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))
index ff0a8d97efbc3a274dbfa03f81a976d25b183e73..a9e93a11af9151cbcba8576e1657483669c611f0 100644 (file)
@@ -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)))
index b294dd6af677290e6eb39ee9524e0f179a45be57..39a33f1e2a05fac059b7d078185be80bba06714f 100644 (file)
@@ -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)))
 
index 42b0d6850ef7a8fbcd27e7b13dc55bf3551962d1..1e66a0163758d17df60880b014f41d4eec435391 100644 (file)
@@ -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))
index 8929181df83c7cd4e0de6095a6b95b0b3ebd3818..2b9a0e70e45109fcb0033ffcaafb467a0b2b736d 100644 (file)
@@ -171,7 +171,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))