From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tony Zorman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66567: [PATCH] use-package: Add ignored-files support to :vc keyword Date: Sun, 15 Oct 2023 18:42:16 +0200 Message-ID: <877cnn4z2v.fsf@hyperspace> Reply-To: Tony Zorman Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27632"; mail-complaints-to="usenet@ciao.gmane.io" To: 66567@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 15 20:00:03 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qs5PH-0006zH-IP for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Oct 2023 20:00:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qs5Ow-0007T9-1b; Sun, 15 Oct 2023 13:59:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qs5Os-0007Sx-Si for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 13:59:39 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qs5Os-0003HE-KJ for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 13:59:38 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qs5PG-0007TV-Ei for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 14:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tony Zorman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Oct 2023 18:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66567 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169739278328671 (code B ref -1); Sun, 15 Oct 2023 18:00:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Oct 2023 17:59:43 +0000 Original-Received: from localhost ([127.0.0.1]:54082 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qs5Ot-0007SH-T6 for submit@debbugs.gnu.org; Sun, 15 Oct 2023 13:59:43 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:33124) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qs4Cd-0004k8-R0 for submit@debbugs.gnu.org; Sun, 15 Oct 2023 12:42:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qs4CA-00052X-4P for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 12:42:26 -0400 Original-Received: from mout-p-101.mailbox.org ([80.241.56.151]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1qs4C7-0007pZ-Et for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 12:42:25 -0400 Original-Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4S7mHY3TSGz9sTn for ; Sun, 15 Oct 2023 18:42:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1697388137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=kAvjylnCrAZd62H0c3Gjfv1vCjGeafru8kgAVKvanVU=; b=pGnlQciuplyT75PgU9sZL5MuJycXKYSlO37Qj/tgUtuslyjHl6GLw0izopkbuVWead0kPG 3Elgt8hl7a0kbxuOJdL4GSRK+QHDvc2WXkR+tJbbvJYlNfzAT9yOofUQeLq70kvGVjNiiB ivborSpvkWg1tSiiRCO3G52Pjn8mNTfj4KEtUFD7HXS5lm0kFaLvq7fEQB6KBXmFsJekA/ n2BmNChfFelPZyFt06wDbM+sRfuzirtoSgapuHIvG9NB0obHknsvcZVZuOPojSF5ttGAp9 vL86QgTHlmEtztmnke72k1w6be6eS/gLjyF5HQ182n3V68V7bu3k4PK37N4rCg== X-MBO-RS-META: zbftdxrf1yhdduwmjz9gz1x47yn1qjyu X-MBO-RS-ID: 7633468e5deedfe1914 Received-SPF: pass client-ip=80.241.56.151; envelope-from=tonyzorman@mailbox.org; helo=mout-p-101.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 15 Oct 2023 13:59:38 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272530 Archived-At: --=-=-= Content-Type: text/plain Hi, this patch augments use-package's :vc keyword with the ability to ignore files. This is according to the functionality added to package-vc.el in 68318dfd16. There is also another small commit lurking in there that enables support for :make and :shell-command, both of which were added in 5ac08768aa. Tony --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-use-package-Update-list-of-valid-vc-keywords.patch >From 2b3c81c1854dc4767105021a6a777c6cb1b04bca Mon Sep 17 00:00:00 2001 From: Tony Zorman Date: Sun, 15 Oct 2023 16:50:00 +0200 Subject: [PATCH] ; use-package: Update list of valid :vc keywords lisp/use-package/use-package-core.el: Add :shell-command, :make to valid keywords. --- lisp/use-package/use-package-core.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index 34c45b7aec..5d0d554baf 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -1654,7 +1654,8 @@ use-package-normalize--vc-arg (t (ensure-string v)))) (:vc-backend (ensure-symbol v)) (_ (ensure-string v))))) - (pcase-let ((valid-kws '(:url :branch :lisp-dir :main-file :vc-backend :rev)) + (pcase-let ((valid-kws '( :url :branch :lisp-dir :main-file :vc-backend :rev + :shell-command :make)) (`(,name . ,opts) arg)) (if (stringp opts) ; (NAME . VERSION-STRING) ? (list name opts) -- 2.42.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-use-package-Add-ignored-files-support-to-vc-keyword.patch >From baf9490a3f3b18a336fe8c860f820beda01ba131 Mon Sep 17 00:00:00 2001 From: Tony Zorman Date: Sun, 15 Oct 2023 16:51:00 +0200 Subject: [PATCH] use-package: Add :ignored-files support to :vc keyword * 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. * test/lisp/use-package/use-package-tests.el (use-package-test-normalize/:vc): Add tests for :ignored-files keyword. --- lisp/use-package/use-package-core.el | 61 ++++++++++++++++------ test/lisp/use-package/use-package-tests.el | 10 +++- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index 5d0d554baf..1c2e4676d7 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -521,6 +521,24 @@ use-package-split-list-at-keys (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 @@ -1634,6 +1652,12 @@ use-package-handler/:vc (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 @@ -1653,24 +1677,27 @@ use-package-normalize--vc-arg ((eq v :newest) nil) (t (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. @@ -1686,9 +1713,9 @@ use-package-normalize/:vc ((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 "Unrecognised argument to :vc.\ diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 9181a8171a..5636ba8a4f 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -2014,7 +2014,15 @@ use-package-test-normalize/:vc (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 -- 2.42.0 --=-=-= Content-Type: text/plain -- Tony Zorman | https://tony-zorman.com/ --=-=-=--