From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikita Karetnikov Subject: Re: guix-package --search Date: Wed, 23 Jan 2013 10:33:30 -0500 Message-ID: <87r4lb29sy.fsf@karetnikov.org> References: <87libor1c9.fsf@karetnikov.org> <87r4lfr0r3.fsf@karetnikov.org> <87obgi6v7f.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:52088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ty2KQ-0003sl-Ji for bug-guix@gnu.org; Wed, 23 Jan 2013 10:33:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ty2KJ-0001Jk-Cx for bug-guix@gnu.org; Wed, 23 Jan 2013 10:33:30 -0500 In-Reply-To: <87obgi6v7f.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "(unknown date)") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: bug-guix@gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > Instead, you can directly build the list of matching packages, like: > (fold-packages (lambda (package result) > (if (or (regexp-exec rx (package-synopsis package)) > (regexp-exec rx (package-description package))) > (cons package result) > result)) > '()) > This way, only one traversal is done. 'regexp-exec' will raise an error if either 'synopsis' or 'description' is not a string. That's why I wrapped it in 'false-if-exception'. > For i18n, we should actually use (gettext (package-description > package)), likewise for synopsis. This way, that will search through > text in the user=E2=80=99s native language. I added it, but I haven't properly tested it. Also, there is 'remove-duplicates' that works in the REPL. But it doesn't remove duplicates when I call it via 'guix-package -s'. (Sometimes they appear and sometimes they don't show up.) Anyway, I'm attaching the patch. Nikita --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-guix-package-Add-search.patch Content-Transfer-Encoding: quoted-printable From=20a365d7f796d0db711bb67902f65826af9e951d06 Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Wed, 23 Jan 2013 15:22:34 +0000 Subject: [PATCH] guix-package: Add '--search'. * guix-package.in (find-packages-by-description): New procedure. (show-help): Add '--search'. (%options): Likewise. (guix-package)[process-query]: Add support for '--search'. =2D-- guix-package.in | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-) diff --git a/guix-package.in b/guix-package.in index 85ac358..16a268b 100644 =2D-- a/guix-package.in +++ b/guix-package.in @@ -229,6 +229,39 @@ all of PACKAGES, a list of name/version/output/path tu= ples." (leave (_ "error: no previous profile; not rolling back~%"))) (else (switch-link))))) =20 +(define (find-packages-by-description rx) + "Search in SYNOPSIS and DESCRIPTION using RX. Return a list of +matching packages." + (define (remove-duplicates pred lst) + ;; Remove duplicates from sorted LST using PRED. + (cond ((null-list? lst) lst) + ((=3D (length lst) 1) lst) + ((=3D (length lst) 2) + (if (pred (first lst) (second lst)) (cdr lst) lst)) + ((pred (first lst) (second lst)) + (remove-duplicates pred (cdr lst))) + (else (cons (first lst) (remove-duplicates pred (cdr lst)))))) + + (define (same-location? p1 p2) + ;; Compare locations of two packages. + (eq? (package-location p1) (package-location p2))) + + (remove-duplicates + same-location? + (stable-sort + (fold-packages + (lambda (package result) + (if (or (false-if-exception + (regexp-exec rx (gettext (package-synopsis package)))) + (false-if-exception + (regexp-exec rx (gettext (package-description package))))) + (cons package result) + result)) + '()) + (lambda (p1 p2) + (stringstring (package-location p)))) + (find-packages-by-description regexp)) + #t)) (_ #f)))) =20 (setlocale LC_ALL "") =2D-=20 1.7.5.4 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJRAALgAAoJEM+IQzI9IQ38RckQAJSnYkQ0mko4gOyeLjbq3J9m bn51NflVfzId4bLJN2/gHduC9midgZMbG6/tq9cXPmClZ13iJjodOLkFoThDIjK7 +WIFz1n2lHO1H8DAt418jRqoTpyODsd5uBMPhwIla1mdrodGKhg6Goaqz360rE1I +G7Oc1GJQ7QbuZMwvWuBPCw41xD7fKtY34drrMMTBdgXmpPDZl164sViby882PRJ H53m/PzWnhycWpOIxdJGCVmnasTpXKdgQi1dG68hNVztvUkkx5Kahiu+cd+TyqFw 5oK/HV0T/KcjR9UYOoHK4prKOQXIi9r86BkcE90FTtnkRSEY9OVR0ScDtCEB41MN ejQuguFz4IUDjTfRepG+4atTyBH4hT0y2pYX4csfSwLZmV0am7nq5GQgXQqZHTfm 1EoEi/aVicB6CszM863Pw17LNTQ7f6iFMTha104QhjeUJH2KZQle8I4kscTqAmZR qKUamFnTSTV/4D/ON4KUCAipWb+0NrpdjSk2XyW/Uq0eVolv4wpPe4/WnPNWTolC GbzNCviOXwK1ZGgG0/I7okjrSfP5J/WlHTF6vtoA+g6W2+gNy6y9zjy2sOUSDLMs aaciy965IiyRa1Y/1xeV21fUxcB/vpB8StTpZVZiAtI1Wl9JO4N4cr7an8nryku5 Yw115EpdhYB1dEwB1cye =zicI -----END PGP SIGNATURE----- --==-=-=--