From 06787fcc58766fa3d818ca4c9f4504b8a7cb863e Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 17 Feb 2025 05:06:20 +0100 Subject: [PATCH] Prefer '(oddp A)' to '(= 1 (% A 2))' * lisp/align.el (align-match-tex-pattern): * lisp/calc/calc-funcs.el (math-bernoulli-number): * lisp/cedet/semantic/bovine/el.el (semantic-ctxt-current-assignment): * lisp/comint.el (comint-within-quotes): * lisp/emacs-lisp/chart.el (chart-axis-draw): * lisp/emacs-lisp/cl-extra.el (cl-round): * lisp/emacs-lisp/eieio.el (defclass): * lisp/emacs-lisp/elint.el (elint-check-setq-form): * lisp/emulation/cua-rect.el (cua--rectangle-right-side): * lisp/progmodes/gud.el (gud-gdb-completions-1): * lisp/ps-print.el (ps-end-job): * lisp/ses.el (ses-center): * lisp/vc/ediff-ptch.el (ediff-get-patch-buffer): Prefer '(oddp A)' to '(= 1 (% A 2))' and variations thereof. (cherry picked from commit e373a6e0d30c28045a0f33e662933c2c2660a220) --- lisp/align.el | 2 +- lisp/calc/calc-funcs.el | 2 +- lisp/comint.el | 2 +- lisp/emacs-lisp/chart.el | 2 +- lisp/emacs-lisp/cl-extra.el | 2 +- lisp/emacs-lisp/eieio.el | 2 +- lisp/emacs-lisp/elint.el | 2 +- lisp/emulation/cua-rect.el | 2 +- lisp/progmodes/gud.el | 2 +- lisp/ps-print.el | 2 +- lisp/ses.el | 2 +- lisp/vc/ediff-ptch.el | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lisp/align.el b/lisp/align.el index 2b1e8cb8466..2f1c932f9ba 100644 --- a/lisp/align.el +++ b/lisp/align.el @@ -1035,7 +1035,7 @@ current position." (while (and (> pos (point-min)) (eq (char-before pos) ?\\)) (setq count (1+ count) pos (1- pos))) - (eq (mod count 2) 1)) + (oddp count)) (goto-char (match-beginning (if reverse 1 2))))) result)) diff --git a/lisp/calc/calc-funcs.el b/lisp/calc/calc-funcs.el index 28e9c1f30bb..8535e580da7 100644 --- a/lisp/calc/calc-funcs.el +++ b/lisp/calc/calc-funcs.el @@ -867,7 +867,7 @@ (nreverse coefs))) (defun math-bernoulli-number (n) - (if (= (% n 2) 1) + (if (oddp n) (if (= n 1) '(frac -1 2) 0) diff --git a/lisp/comint.el b/lisp/comint.el index 0f99eaf1464..94a40550229 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1754,7 +1754,7 @@ Go to the history element by the absolute history position HIST-POS." Quotes are single and double." (let ((countsq (comint-how-many-region "\\(^\\|[^\\]\\)'" beg end)) (countdq (comint-how-many-region "\\(^\\|[^\\]\\)\"" beg end))) - (or (= (mod countsq 2) 1) (= (mod countdq 2) 1)))) + (or (oddp countsq) (oddp countdq)))) (defun comint-how-many-region (regexp beg end) "Return number of matches for REGEXP from BEG to END." diff --git a/lisp/emacs-lisp/chart.el b/lisp/emacs-lisp/chart.el index 6f2f85fc765..2a01501f99e 100644 --- a/lisp/emacs-lisp/chart.el +++ b/lisp/emacs-lisp/chart.el @@ -347,7 +347,7 @@ of the drawing." (odd nil) p1) (while s - (setq odd (= (% (length s) 2) 1)) + (setq odd (oddp (length s))) (setq r (chart-translate-namezone (oref a chart) i)) (if (eq dir 'vertical) (setq p (/ (+ (car r) (cdr r)) 2)) diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index ec7dc5aa9e3..2d9b8d0b0f1 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el @@ -392,7 +392,7 @@ With two arguments, return rounding and remainder of their quotient." (res (cl-floor (+ x hy) y))) (if (and (= (car (cdr res)) 0) (= (+ hy hy) y) - (/= (% (car res) 2) 0)) + (oddp (car res))) (list (1- (car res)) hy) (list (car res) (- (car (cdr res)) hy)))) (let ((q (round (/ x y)))) diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index ea54aa01696..666c90181a4 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el @@ -118,7 +118,7 @@ and reference them using the function `class-option'." (/= 1 (% (length options-and-doc) 2))) (error "Too many arguments to `defclass'")) ((and (symbolp (car options-and-doc)) - (/= 0 (% (length options-and-doc) 2))) + (oddp (length options-and-doc))) (error "Too many arguments to `defclass'"))) (if (stringp (car options-and-doc)) diff --git a/lisp/emacs-lisp/elint.el b/lisp/emacs-lisp/elint.el index fcc17106131..5ae8880167d 100644 --- a/lisp/emacs-lisp/elint.el +++ b/lisp/emacs-lisp/elint.el @@ -798,7 +798,7 @@ CODE can be a lambda expression, a macro, or byte-compiled code." (defun elint-check-setq-form (form env) "Lint the setq FORM in ENV." - (or (= (mod (length form) 2) 1) + (or (oddp (length form)) ;; (setq foo) is valid and equivalent to (setq foo nil). (elint-warning "Missing value in setq: %s" form)) (let ((newenv env) diff --git a/lisp/emulation/cua-rect.el b/lisp/emulation/cua-rect.el index 18a5ce930ec..7783d18f6e4 100644 --- a/lisp/emulation/cua-rect.el +++ b/lisp/emulation/cua-rect.el @@ -187,7 +187,7 @@ Activates the region if needed. Only lasts until the region is deactivated." ;; t if point is on right side of rectangle. (if (and topbot (= (cua--rectangle-left) (cua--rectangle-right))) (< (cua--rectangle-corner) 2) - (= (mod (cua--rectangle-corner) 2) 1))) + (oddp (cua--rectangle-corner)))) (defun cua--rectangle-column () (if (cua--rectangle-right-side) diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index df9b87f903e..6c36d08c9ee 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -920,7 +920,7 @@ CONTEXT is the text before COMMAND on the line." (while (string-match "\\([^'\\]\\|\\\\'\\)*'" str pos) (setq count (1+ count) pos (match-end 0))) - (and (= (mod count 2) 1) + (and (oddp count) (setq complete-list (list (concat str "'")))))) complete-list) diff --git a/lisp/ps-print.el b/lisp/ps-print.el index c1258db2c54..d133e0bad67 100644 --- a/lisp/ps-print.el +++ b/lisp/ps-print.el @@ -6462,7 +6462,7 @@ If FACE is not a valid face name, use default face." (replace-match (format "/Lines %d def\n/PageCount %d def" total-lines total-pages) t))))) ;; Set dummy page - (and ps-spool-duplex (= (mod ps-page-order 2) 1) + (and ps-spool-duplex (oddp ps-page-order) (let ((ps-n-up-printing 0)) (ps-header-sheet) (ps-output "/PrintHeader false def\n/ColumnIndex 0 def\n" diff --git a/lisp/ses.el b/lisp/ses.el index 88e83ae160b..d23cefc53f4 100644 --- a/lisp/ses.el +++ b/lisp/ses.el @@ -4105,7 +4105,7 @@ printer otherwise." value ; Too large for field, anyway. (setq half (make-string (/ width 2) fill)) (concat half value half - (if (> (% width 2) 0) (char-to-string fill)))))) + (if (oddp width) (char-to-string fill)))))) (defun ses-center-span (value &optional fill printer) "Print VALUE, centered within the span that starts in the current column diff --git a/lisp/vc/ediff-ptch.el b/lisp/vc/ediff-ptch.el index e83e7e95c0f..42b0d6850ef 100644 --- a/lisp/vc/ediff-ptch.el +++ b/lisp/vc/ediff-ptch.el @@ -552,7 +552,7 @@ an optional argument, then use it." ((and (integerp arg) (eq 0 (mod arg 2))) (setq patch-buf (ediff-prompt-for-patch-buffer))) ;; odd prefix arg: get patch from a file - ((and (integerp arg) (eq 1 (mod arg 2))) + ((and (integerp arg) (oddp arg)) (setq patch-buf (ediff-prompt-for-patch-file))) (t (setq patch-buf (if (y-or-n-p "Is the patch already in a buffer? ") -- 2.39.5