From: Eshel Yaron Date: Tue, 6 Aug 2024 09:51:28 +0000 (+0200) Subject: Bring back 'oddp' and 'evenp' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8d3fd3e3dceb9bd40a02db624ac199f1106be16f;p=emacs.git Bring back 'oddp' and 'evenp' --- diff --git a/lisp/calendar/cal-tex.el b/lisp/calendar/cal-tex.el index ea396329e4c..5f0813061d9 100644 --- a/lisp/calendar/cal-tex.el +++ b/lisp/calendar/cal-tex.el @@ -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/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index c75dd4b5914..0107cbb57d7 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el @@ -3750,7 +3750,7 @@ The placement of the padding is determined by the value of user option `todo-categories-align'." (let* ((len (todo-adjusted-category-label-length)) (strlen (length str)) - (strlen-odd (eq (logand strlen 1) 1)) + (strlen-odd (oddp strlen)) (padding (max 0 (/ (- len strlen) 2))) (padding-left (cond ((eq todo-categories-align 'left) 0) ((eq todo-categories-align 'center) padding) diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 1fae0ba6ba4..e952d3217fb 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)))) + (oddp (skip-syntax-backward "\\"))) (let ((current-prefix-arg (1- num))) (electric-pair-post-self-insert-function))) ;; Skip self. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 569bd7f03f7..a87b77a875e 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -3780,7 +3780,7 @@ This assumes the function has the `important-return-value' property." ;; Add missing &optional (or &rest) arguments. (dotimes (_ (- (/ (1+ fmax2) 2) alen)) (byte-compile-push-constant nil))) - ((zerop (logand fmax2 1)) + ((evenp fmax2) (byte-compile-report-error (format "Too many arguments for inlined function %S" form)) (byte-compile-discard (- alen (/ fmax2 2)))) diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el index 108dcd31f48..3c8940b9ad5 100644 --- a/lisp/emacs-lisp/cl-lib.el +++ b/lisp/emacs-lisp/cl-lib.el @@ -278,13 +278,9 @@ so that they are registered at compile-time as well as run-time." "Return t if NUMBER is negative." (< number 0)) -(defun cl-oddp (integer) - "Return t if INTEGER is odd." - (eq (logand integer 1) 1)) +(defalias 'cl-oddp 'oddp) -(defun cl-evenp (integer) - "Return t if INTEGER is even." - (eq (logand integer 1) 0)) +(defalias 'cl-evenp 'evenp) (defconst cl-digit-char-table (let* ((digits (make-vector 256 nil)) diff --git a/lisp/emacs-lisp/elint.el b/lisp/emacs-lisp/elint.el index 27c169cc657..b1f44687427 100644 --- a/lisp/emacs-lisp/elint.el +++ b/lisp/emacs-lisp/elint.el @@ -833,7 +833,7 @@ CODE can be a lambda expression, a macro, or byte-compiled code." "Lint the defcustom FORM in ENV." (if (and (> (length form) 3) ;; even no. of keyword/value args ? - (zerop (logand (length form) 1))) + (evenp (length form))) (elint-env-add-global-var (elint-form (nth 2 form) env) (car (cdr form))) (elint-error "Malformed variable declaration: %s" form) diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index fa9b437fcfd..3f6272b9c3d 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -294,8 +294,8 @@ The return value is the last VAL in the list. \(fn PLACE VAL PLACE VAL ...)" (declare (debug (&rest [gv-place form]))) - (if (/= (logand (length args) 1) 0) - (signal 'wrong-number-of-arguments (list 'setf (length args)))) + (unless (evenp (length args)) + (signal 'wrong-number-of-arguments (list 'setf (length args)))) (if (and args (null (cddr args))) (let ((place (pop args)) (val (car args))) diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el index 4524eccc7ef..e96aaa9bf3e 100644 --- a/lisp/emacs-lisp/macroexp.el +++ b/lisp/emacs-lisp/macroexp.el @@ -434,7 +434,7 @@ Assumes the caller has bound `macroexpand-all-environment'." ;; Malformed code is translated to code that signals an error ;; at run time. (let ((nargs (length args))) - (if (/= (logand nargs 1) 0) + (if (oddp nargs) (macroexp-warn-and-return (format-message "odd number of arguments in `setq' form") `(signal 'wrong-number-of-arguments '(setq ,nargs)) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 0ac58b09f64..b7679fa2e8e 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -9665,7 +9665,7 @@ if yet untried." "Format MSG according to ARGS. See also `format-spec'." - (when (eq (logand (length args) 1) 1) ; oddp + (when (oddp (length args)) (error "Obscure usage of this function appeared")) (let ((entry (erc-retrieve-catalog-entry msg))) (when (not entry) diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index cf695c20bc1..d85a9333f25 100644 --- a/lisp/gnus/message.el +++ b/lisp/gnus/message.el @@ -6006,7 +6006,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/hexl.el b/lisp/hexl.el index 28441a28d6e..9f25900e844 100644 --- a/lisp/hexl.el +++ b/lisp/hexl.el @@ -1011,7 +1011,7 @@ Embedded whitespace, dashes, and periods in the string are ignored." (let ((chars '())) (let ((len (length str)) (idx 0)) - (if (eq (logand len 1) 1) + (if (oddp len) (let ((num (hexl-hex-string-to-integer (substring str 0 1)))) (setq chars (cons num chars)) (setq idx 1))) diff --git a/lisp/keymap.el b/lisp/keymap.el index 737c11dbd83..39442146f01 100644 --- a/lisp/keymap.el +++ b/lisp/keymap.el @@ -656,7 +656,7 @@ in the echo area. ((eq keyword :repeat) (setq repeat (pop defs))) (t (push keyword opts) (push (pop defs) opts))))) - (unless (zerop (% (length defs) 2)) + (unless (evenp (length defs)) (error "Uneven number of key/definition pairs: %s" defs)) (let ((defs defs) diff --git a/lisp/mail/rfc2047.el b/lisp/mail/rfc2047.el index e122fe8c9b5..51b6c8e11c0 100644 --- a/lisp/mail/rfc2047.el +++ b/lisp/mail/rfc2047.el @@ -1020,10 +1020,10 @@ other than `\"' and `\\' in quoted strings." end (match-end 0) words nil) (while match - (push (list (match-string 2) ;; charset + (push (list (match-string 2) ;; charset (char-after (match-beginning 3)) ;; encoding - (substring (match-string 3) 2) ;; encoded-text - (match-string 1)) ;; encoded-word + (substring (match-string 3) 2) ;; encoded-text + (match-string 1)) ;; encoded-word words) ;; Look for the subsequent encoded-words. (when (setq match (looking-at eword-regexp)) @@ -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/subr.el b/lisp/subr.el index edfac77d50b..0bc8d7ba7e1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4052,8 +4052,7 @@ Otherwise, return nil." (defun plistp (object) "Non-nil if and only if OBJECT is a valid plist." (declare (pure t) (side-effect-free error-free)) - (let ((len (proper-list-p object))) - (and len (zerop (% len 2))))) + (let ((len (proper-list-p object))) (and len (evenp len)))) (defun macrop (object) "Non-nil if and only if OBJECT is a macro." @@ -7150,4 +7149,12 @@ that does the same thing as `caadr'." (funcall (car funs) (funcall (apply #'compose (cdr funs)) x))) #'identity)) +(defsubst plusp (number) "Return t if NUMBER is positive." (> number 0)) + +(defsubst minusp (number) "Return t if NUMBER is negative." (< number 0)) + +(defun oddp (integer) "Return t if INTEGER is odd." (eq (logand integer 1) 1)) + +(defun evenp (integer) "Return t if INTEGER is even." (eq (logand integer 1) 0)) + ;;; subr.el ends here