]> git.eshelyaron.com Git - emacs.git/commitdiff
use-package: Add ':ignored-files' support to ':vc' keyword
authorTony Zorman <soliditsallgood@mailbox.org>
Sun, 15 Oct 2023 14:51:00 +0000 (16:51 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 18 May 2024 18:55:58 +0000 (20:55 +0200)
* lisp/use-package/use-package-core.el (use-package-split-when):
New utility function to split a list whenever a specified
predicate returns t.
(use-package-vc-valid-keywords): A new defconst to gather all
allowed keywords.
(use-package-normalize--vc-arg): Properly normalize the
':ignored-files' keyword, in that the following are all valid
ways of entering files:
  :ignored-files "a"
  :ignored-files ("a")
  :ignored-files "a" "b" "c"
  :ignored-files ("a" "b" "c")
(use-package-normalize/:vc): Adjust normalization, now that we
do not necessarily receive a valid plist as an input.  (Bug#66567)

* test/lisp/use-package/use-package-tests.el
(use-package-test-normalize/:vc): Add tests for ':ignored-files'
keyword.

(cherry picked from commit a019d2bd56818046854345922ad805f3212cd116)

lisp/use-package/use-package-core.el
test/lisp/use-package/use-package-tests.el

index 65640054c40401a82a1446690ca1aaa730d59167..bb12c3c4f2b22d0fa75edd3bd21f87a44e8a7c5c 100644 (file)
@@ -535,6 +535,24 @@ This is in contrast to merely setting it to 0."
        (let ((xs (use-package-split-list (apply-partially #'eq key) lst)))
          (cons (car xs) (use-package-split-list-at-keys key (cddr xs))))))
 
+(defun use-package-split-when (pred xs)
+  "Repeatedly split a list according to PRED.
+Split XS every time PRED returns t.  Keep the delimiters, and
+arrange the result in an alist.  For example:
+
+  (use-package-split-when #\\='keywordp \\='(:a 1 :b 2 3 4 :c 5))
+  ;; => \\='((:a 1) (:b 2 3 4) (:c 5))
+
+  (use-package-split-when (lambda (x) (> x 2)) \\='(10 1 3 2 4 -1 8 9))
+  ;; => \\='((10 1) (3 2) (4 -1) (8) (9))"
+  (unless (seq-empty-p xs)
+    (pcase-let* ((`(,first . ,rest) (if (funcall pred (car xs))
+                                        (cons (car xs) (cdr xs))
+                                      (use-package-split-list pred xs)))
+                 (`(,val . ,recur) (use-package-split-list pred rest)))
+      (cons (cons first val)
+            (use-package-split-when pred recur)))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;
 ;;; Keywords
@@ -1648,6 +1666,12 @@ Also see the Info node `(use-package) Creating an extension'."
       (push `(use-package-vc-install ',arg ,local-path) body))   ; runtime
     body))
 
+(defconst use-package-vc-valid-keywords
+  '( :url :branch :lisp-dir :main-file :vc-backend :rev
+     :shell-command :make :ignored-files)
+  "Valid keywords for the `:vc' keyword, see the Info
+node `(emacs)Fetching Package Sources'.")
+
 (defun use-package-normalize--vc-arg (arg)
   "Normalize possible arguments to the `:vc' keyword.
 ARG is a cons-cell of approximately the form that
@@ -1669,24 +1693,27 @@ indicating the latest commit) revision."
                          (:newest nil)
                          (_ (ensure-string v))))
                  (:vc-backend (ensure-symbol v))
+                 (:ignored-files (if (listp v) v (list v)))
                  (_ (ensure-string v)))))
-    (pcase-let ((valid-kws '( :url :branch :lisp-dir :main-file :vc-backend :rev
-                              :shell-command :make))
-                (`(,name . ,opts) arg))
+    (pcase-let* ((`(,name . ,opts) arg))
       (if (stringp opts)                ; (NAME . VERSION-STRING) ?
           (list name opts)
-        ;; Error handling
-        (cl-loop for (k _) on opts by #'cddr
-                 if (not (member k valid-kws))
-                 do (use-package-error
-                     (format "Keyword :vc received unknown argument: %s. Supported keywords are: %s"
-                             k valid-kws)))
-        ;; Actual normalization
-        (list name
-              (cl-loop for (k v) on opts by #'cddr
-                       if (not (eq k :rev))
-                       nconc (list k (normalize k v)))
-              (normalize :rev (plist-get opts :rev)))))))
+        (let ((opts (use-package-split-when
+                     (lambda (el)
+                       (seq-contains-p use-package-vc-valid-keywords el))
+                     opts)))
+          ;; Error handling
+          (cl-loop for (k . _) in opts
+                   if (not (member k use-package-vc-valid-keywords))
+                   do (use-package-error
+                       (format "Keyword :vc received unknown argument: %s. Supported keywords are: %s"
+                               k use-package-vc-valid-keywords)))
+          ;; Actual normalization
+          (list name
+                (cl-loop for (k . v) in opts
+                         if (not (eq k :rev))
+                         nconc (list k (normalize k (if (length= v 1) (car v) v))))
+                (normalize :rev (car (alist-get :rev opts)))))))))
 
 (defun use-package-normalize/:vc (name _keyword args)
   "Normalize possible arguments to the `:vc' keyword.
@@ -1702,9 +1729,9 @@ node `(use-package) Creating an extension'."
       ((or 'nil 't) (list name))                 ; guess name
       ((pred symbolp) (list arg))                ; use this name
       ((pred stringp) (list name arg))           ; version string + guess name
-      ((pred plistp)                             ; plist + guess name
+      (`(,(pred keywordp) . ,(pred listp))       ; list + guess name
        (use-package-normalize--vc-arg (cons name arg)))
-      (`(,(pred symbolp) . ,(or (pred plistp)    ; plist/version string + name
+      (`(,(pred symbolp) . ,(or (pred listp)     ; list/version string + name
                                 (pred stringp)))
        (use-package-normalize--vc-arg arg))
       (_ (use-package-error "Unrecognized argument to :vc.\
index d1e68c2a790b863cf0d8eb7408ce3ab51fa2d31a..76de29be471a5fb6c5155ef6f3a81cf134bac2ff 100644 (file)
   (should (equal '(foo)
                  (use-package-normalize/:vc 'foo :vc nil)))
   (should (equal '(bar)
-                 (use-package-normalize/:vc 'foo :vc '(bar)))))
+                 (use-package-normalize/:vc 'foo :vc '(bar))))
+  (should (equal
+           '(foo (:ignored-files ("a" "b" "c")) :last-release)
+           (use-package-normalize/:vc 'foo :vc '((:ignored-files "a" "b" "c")))))
+  (should (equal
+           (use-package-normalize/:vc 'foo :vc '((:ignored-files "a")))
+           (use-package-normalize/:vc 'foo :vc '((:ignored-files ("a"))))))
+  (should (equal (use-package-normalize/:vc 'foo :vc '((:ignored-files "a" "b" "c")))
+                 (use-package-normalize/:vc 'foo :vc '((:ignored-files ("a" "b" "c")))))))
 
 ;; Local Variables:
 ;; no-byte-compile: t