From b4ca057ac67fc6589946b8bddc090a8cf4798dd9 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Tue, 25 Feb 2025 20:37:40 +0100 Subject: [PATCH] Demote errors in 'cl-case' to warnings --- lisp/emacs-lisp/cl-macs.el | 39 +++++++++++++++++++++--------------- lisp/progmodes/elisp-mode.el | 1 + 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 48d8a9c9a7f..a65a7aad5d5 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -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))))) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index befcc338cab..a86683be2a5 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -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. -- 2.39.5