]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer plusp/minusp to open-coding them in subr.el
authorStefan Kangas <stefankangas@gmail.com>
Mon, 17 Feb 2025 21:48:47 +0000 (22:48 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 18 Feb 2025 08:58:27 +0000 (09:58 +0100)
* lisp/subr.el (lsh, nbutlast, number-sequence, add-to-history)
(read-char-from-minibuffer, split-string, subst-char-in-string)
(forward-whitespace, forward-symbol, forward-same-syntax)
(progress-reporter-do-update, version-list-<): Prefer plusp/minusp to
open-coding them.

(cherry picked from commit 8a7c1a31ac0a61384661878e9f7f7e77ada34ade)

lisp/subr.el

index 5eea614f6d60b9383068f15efb7e439628f70734..7a013c750ae2739852c3188a1aee20757336ab62 100644 (file)
@@ -581,7 +581,7 @@ treatment of negative COUNT provided by this function."
                (format-message "avoid `lsh'; use `ash' instead")
                form '(suspicious lsh) t form)))
            (side-effect-free t))
-  (when (and (< value 0) (< count 0))
+  (when (and (minusp value) (minusp count))
     (when (< value most-negative-fixnum)
       (signal 'args-out-of-range (list value count)))
     (setq value (logand (ash value -1) most-positive-fixnum))
@@ -805,7 +805,7 @@ If N is omitted or nil, remove the last element."
     (or n (setq n 1))
     (and (< n m)
         (progn
-          (if (> n 0) (setcdr (nthcdr (- (1- m) n) list) nil))
+          (if (plusp n) (setcdr (nthcdr (- (1- m) n) list) nil))
           list))))
 
 (defun delete-dups (list)
@@ -878,7 +878,7 @@ of course, also replace TO with a slightly larger value
     (or inc (setq inc 1))
     (when (zerop inc) (error "The increment can not be zero"))
     (let (seq (n 0) (next from))
-      (if (> inc 0)
+      (if (plusp inc)
           (while (<= next to)
             (setq seq (cons next seq)
                   n (1+ n)
@@ -2547,7 +2547,7 @@ HISTORY-VAR cannot refer to a lexical variable."
     (when (and (listp history)
               (or keep-all
                   (not (stringp newelt))
-                  (> (length newelt) 0))
+                  (plusp (length newelt)))
               (or keep-all
                   (not (equal (car history) newelt))))
       (if history-delete-duplicates
@@ -5310,7 +5310,7 @@ Modifies the match data; use `save-match-data' if necessary."
                         (setq this (substring this 0 tem)))))
 
                ;; Trimming could make it empty; check again.
-               (when (or keep-nulls (> (length this) 0))
+               (when (or keep-nulls (plusp (length this)))
                  (push this list)))))))
 
     (while (and (string-match rexp string
@@ -5387,7 +5387,7 @@ Unless optional argument INPLACE is non-nil, return a new string."
         res)
     (let ((i (length string))
          (newstr (if inplace string (copy-sequence string))))
-      (while (> i 0)
+      (while (plusp i)
         (setq i (1- i))
         (if (eq (aref newstr i) fromchar)
            (aset newstr i tochar)))
@@ -5860,7 +5860,7 @@ backwards ARG times if negative."
   (interactive "^p")
   (if (natnump arg)
       (re-search-forward "[ \t]+\\|\n" nil 'move arg)
-    (while (< arg 0)
+    (while (minusp arg)
       (if (re-search-backward "[ \t]+\\|\n" nil 'move)
          (or (eq (char-after (match-beginning 0)) ?\n)
              (skip-chars-backward " \t")))
@@ -5877,7 +5877,7 @@ backwards ARG times if negative."
   (interactive "^p")
   (if (natnump arg)
       (re-search-forward "\\(\\sw\\|\\s_\\)+" nil 'move arg)
-    (while (< arg 0)
+    (while (minusp arg)
       (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil 'move)
          (skip-syntax-backward "w_"))
       (setq arg (1+ arg)))))
@@ -5890,11 +5890,11 @@ With prefix argument ARG, do it ARG times if positive, or move
 backwards ARG times if negative."
   (interactive "^p")
   (or arg (setq arg 1))
-  (while (< arg 0)
+  (while (minusp arg)
     (skip-syntax-backward
      (char-to-string (char-syntax (char-before))))
     (setq arg (1+ arg)))
-  (while (> arg 0)
+  (while (plusp arg)
     (skip-syntax-forward (char-to-string (char-syntax (char-after))))
     (setq arg (1- arg))))
 
@@ -6346,7 +6346,7 @@ NEW-MESSAGE, if non-nil, sets a new message for the reporter."
                (if suffix
                    (aset parameters 6 suffix)
                  (setq suffix (or (aref parameters 6) "")))
-               (if (> percentage 0)
+               (if (plusp percentage)
                    (message "%s%d%% %s" text percentage suffix)
                  (message "%s %s" text suffix)))))
          ;; Pulsing indicator
@@ -6577,9 +6577,9 @@ turn is higher than (1 -2), which is higher than (1 -3)."
    ;; l1 null and l2 null         ==> l1 length = l2 length
    ((and (null l1) (null l2)) nil)
    ;; l1 not null and l2 null     ==> l1 length > l2 length
-   (l1 (< (version-list-not-zero l1) 0))
+   (l1 (minusp (version-list-not-zero l1)))
    ;; l1 null and l2 not null     ==> l2 length > l1 length
-   (t  (< 0 (version-list-not-zero l2)))))
+   (t  (plusp (version-list-not-zero l2)))))
 
 
 (defun version-list-= (l1 l2)