]> git.eshelyaron.com Git - emacs.git/commitdiff
checkdoc: Minor code cleanups
authorStefan Kangas <stefankangas@gmail.com>
Sun, 7 Jul 2024 10:58:39 +0000 (12:58 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 8 Jul 2024 20:55:59 +0000 (22:55 +0200)
* lisp/emacs-lisp/checkdoc.el
(checkdoc-message-text-search): Use 'while-let'.
(checkdoc-message-text-engine): Use 'when' and 'unless'.

(cherry picked from commit 1883603dfc52f71aa515c60103967938a6eec002)

lisp/emacs-lisp/checkdoc.el

index 16ea749a2ebceb5c4a86b68ad201c7d803948f48..945a38c89d6f689a2890860408d77836c7e6b052 100644 (file)
@@ -2581,11 +2581,10 @@ Code:, and others referenced in the style guide."
   "Search between BEG and END for a style error with message text.
 Optional arguments BEG and END represent the boundary of the check.
 The default boundary is the entire buffer."
-  (let ((e nil)
-       (type nil))
+  (let ((e nil))
     (if (not (or beg end)) (setq beg (point-min) end (point-max)))
     (goto-char beg)
-    (while (setq type (checkdoc-message-text-next-string end))
+    (while-let ((type (checkdoc-message-text-next-string end)))
       (setq e (checkdoc-message-text-engine type)))
     e))
 
@@ -2682,34 +2681,33 @@ should not end with a period, and should start with a capital letter.
 The function `y-or-n-p' has similar constraints.
 Argument TYPE specifies the type of question, such as `error' or `y-or-n-p'."
   ;; If type is nil, then attempt to derive it.
-  (if (not type)
-      (save-excursion
-       (up-list -1)
-       (if (looking-at "(format")
-           (up-list -1))
-       (setq type
-             (cond ((looking-at "(error")
-                    'error)
-                   (t 'y-or-n-p)))))
+  (unless type
+    (save-excursion
+      (up-list -1)
+      (when (looking-at "(format")
+        (up-list -1))
+      (setq type
+            (cond ((looking-at "(error")
+                   'error)
+                  (t 'y-or-n-p)))))
   (let ((case-fold-search nil))
     (or
      ;; From the documentation of the symbol `error':
      ;; In Emacs, the convention is that error messages start with a capital
      ;; letter but *do not* end with a period.  Please follow this convention
      ;; for the sake of consistency.
-     (if (and (checkdoc--error-bad-format-p)
-             (not (checkdoc-autofix-ask-replace
-                    (match-beginning 1) (match-end 1)
-                    "Capitalize your message text?"
-                    (capitalize (match-string 1))
-                   t)))
-         (checkdoc-create-error "Messages should start with a capital letter"
-                                (match-beginning 1) (match-end 1)
-                                `("Capitalize"
-                                  ((,(current-buffer)
-                                    (,(match-beginning 1) ,(match-end 1)
-                                     ,(capitalize (match-string 1)))))))
-       nil)
+     (when (and (checkdoc--error-bad-format-p)
+               (not (checkdoc-autofix-ask-replace
+                      (match-beginning 1) (match-end 1)
+                      "Capitalize your message text?"
+                      (capitalize (match-string 1))
+                     t)))
+       (checkdoc-create-error "Messages should start with a capital letter"
+                              (match-beginning 1) (match-end 1)
+                              `("Capitalize"
+                                ((,(current-buffer)
+                                  (,(match-beginning 1) ,(match-end 1)
+                                   ,(capitalize (match-string 1))))))))
      ;; In general, sentences should have two spaces after the period.
      (checkdoc-sentencespace-region-engine (point)
                                           (save-excursion (forward-sexp 1)
@@ -2719,22 +2717,21 @@ Argument TYPE specifies the type of question, such as `error' or `y-or-n-p'."
                                         (save-excursion (forward-sexp 1)
                                                         (point)))
      ;; Here are message type specific questions.
-     (if (and (eq type 'error)
-             (save-excursion (forward-sexp 1)
-                             (forward-char -2)
-                             (looking-at "\\."))
-             (not (checkdoc-autofix-ask-replace (match-beginning 0)
-                                                (match-end 0)
-                                                 "Remove period from error?"
-                                                ""
-                                                t)))
-        (checkdoc-create-error
-         "Error messages should *not* end with a period"
-         (match-beginning 0) (match-end 0)
-          `("Remove fullstop"
-            ((,(current-buffer)
-              (,(match-beginning 0) ,(match-end 0) "")))))
-       nil)
+     (when (and (eq type 'error)
+               (save-excursion (forward-sexp 1)
+                               (forward-char -2)
+                               (looking-at "\\."))
+               (not (checkdoc-autofix-ask-replace (match-beginning 0)
+                                                  (match-end 0)
+                                                   "Remove period from error?"
+                                                  ""
+                                                  t)))
+       (checkdoc-create-error
+       "Error messages should *not* end with a period"
+       (match-beginning 0) (match-end 0)
+        `("Remove fullstop"
+          ((,(current-buffer)
+            (,(match-beginning 0) ,(match-end 0) ""))))))
      ;; From `(elisp) Programming Tips': "A question asked in the
      ;; minibuffer with `yes-or-no-p' or `y-or-n-p' should start with
      ;; a capital letter and end with '?'."