]> git.eshelyaron.com Git - emacs.git/commitdiff
Demote errors in 'cl-case' to warnings
authorEshel Yaron <me@eshelyaron.com>
Tue, 25 Feb 2025 19:37:40 +0000 (20:37 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 25 Feb 2025 19:37:40 +0000 (20:37 +0100)
lisp/emacs-lisp/cl-macs.el
lisp/progmodes/elisp-mode.el

index 48d8a9c9a7f721465b854272219a112383c3f237..a65a7aad5d58b899f7090f744b0fcde9ce1cae04 100644 (file)
@@ -807,10 +807,10 @@ compared by `eql'.
         ,@(mapcar
            (lambda (c)
              (cons (cond (has-otherwise
-                          (error "Misplaced t or `otherwise' clause"))
-                         ((memq (car c) '(t otherwise))
-                          (setq has-otherwise t)
-                          t)
+                          (macroexp-warn-and-return
+                           "Preceding catch-all clause shadows this clause"
+                           nil 'suspicious nil (car c)))
+                         ((memq (car c) '(t otherwise)) (setq has-otherwise t))
                          ((eq (car c) 'cl--ecase-error-flag)
                           `(error "cl-ecase failed: %s, %s"
                                   ,temp ',(reverse head-list)))
@@ -822,22 +822,29 @@ compared by `eql'.
                                (memq (caar c) '(quote function)))
                           (macroexp-warn-and-return
                            (format-message
-                            (concat "Case %s will match `%s'.  If "
-                                    "that's intended, write %s "
-                                    "instead.  Otherwise, don't "
-                                    "quote `%s'.")
-                            (car c) (caar c) (list (cadar c) (caar c))
+                            (concat "This clause matches `%s' and `%s'.  "
+                                    "If that's intended, write %s instead.  "
+                                    "Otherwise, don't quote `%s'.")
+                            (caar c) (cadar c) (list (cadar c) (caar c))
                             (cadar c))
-                           `(cl-member ,temp ',(car c)) 'suspicious))
+                           `(cl-member ,temp ',(car c)) 'suspicious
+                           nil (car c)))
                          ((listp (car c))
-                          (setq head-list (append (car c) head-list))
-                          `(cl-member ,temp ',(car c)))
+                          (if (cl-subsetp (car c) head-list)
+                              (macroexp-warn-and-return
+                               (concat "All keys covered by preceding cases, "
+                                       "this clause can never match")
+                               nil 'suspicious nil (car c))
+                            (setq head-list (append (car c) head-list))
+                            `(cl-member ,temp ',(car c))))
                          (t
                           (if (memq (car c) head-list)
-                              (error "Duplicate key in case: %s"
-                                     (car c)))
-                          (push (car c) head-list)
-                          `(eql ,temp ,(if (keywordp (car c)) (car c) `',(car c)))))
+                              (macroexp-warn-and-return
+                               (format-message
+                                "Duplicate key in case: %s" (car c))
+                               nil 'suspicious nil (car c))
+                            (push (car c) head-list)
+                            `(eql ,temp ,(if (keywordp (car c)) (car c) `',(car c))))))
                    (or (cdr c) '(nil))))
            clauses)))))
 
index befcc338cabf5448b5e7cbec55dfe7880314abf2..a86683be2a5d00f1566c0453d17c619c9703f4cb 100644 (file)
@@ -658,6 +658,7 @@ be used instead.
               #'elisp-flymake-byte-compile nil t)
   (add-hook 'refactor-backend-functions #'elisp-refactor-backend nil t)
   (add-hook 'context-menu-functions #'elisp-context-menu 10 t)
+  (setq-local imenu-create-index-function #'elisp-create-index)
   (alist-set "compf" prettify-symbols-alist ?∘ #'equal))
 
 ;; Font-locking support.