From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id GKlPMAQrdmFfOgAAsNZ9tg (envelope-from ); Mon, 25 Oct 2021 03:56:52 +0000 Received: from out2.migadu.com ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id SBLtKwQrdmF0QQAAbx9fmQ (envelope-from ); Mon, 25 Oct 2021 03:56:52 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1635134212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=58grJ4M8DNtE9T5BJWu7l3n5bmS38DnuadUJtX0m/Bc=; b=0LKLif+vrH3tG79MHxAl6k/BhGYOXNkIwEYS+NOrdDiwNIX+X/VCvmGT/O+HPodGe+RTSc GBH2UYP5FvkI1WGJQnKfZ8O/5BkvaHfgo4JQxeiu8t+oBcA1LGDNzgk6CLytf1mKotuyPM a8uF4hNpOCGsnd07izpzav4wCKrww3r9Me48eFY6yLAWWq8BgW+OEiDqk1GagO8+JMEQYw oE7lIGcHUkcerS1rq0J38z5WCUbeMRkZD6c46mFoyF56wOhQVrqHcaqJVYSW4LC04OttUE NyMF5EAGXTlObQubWFALPFSuE5S//ogiiPe0cS+uRUzLvMSTVMrQgm0Aw/FYsA== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 09/10] lei q: Offer candidates for --include and --only Date: Sun, 24 Oct 2021 23:56:29 -0400 Message-Id: <20211025035630.297598-10-kyle@kyleam.com> In-Reply-To: <20211025035630.297598-1-kyle@kyleam.com> References: <20211025035630.297598-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com X-TUID: OpAKz5hVayZC The --include option of lei-q enables searching external sources that are not already registered, whether they are local inboxes or remote URLs. --only also does this, along with restricting the results to the specified sources. As such, registered inboxes make sense as values for --only, in _addition_ to any values the make sense for --include. --- piem-lei.el | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/piem-lei.el b/piem-lei.el index e575f4f3..2f09c387 100644 --- a/piem-lei.el +++ b/piem-lei.el @@ -382,6 +382,71 @@ (define-derived-mode piem-lei-query-mode special-mode "lei-query" ;;;;; lei-q transient +(defun piem-lei-externals () + "Return configured externals." + (seq-remove + (lambda (e) (string-prefix-p "boost=" e)) + (split-string + (with-output-to-string + (piem-lei-insert-output + (list "ls-external" "-z") standard-output)) + "\0" t))) + +(defun piem-lei-inboxdir-urls () + "Return hash table mapping each inboxdir to its URL. +These values correspond to local inboxes that are configured via +public-inbox's configuration." + (let ((case-fold-search t) + (pi-cfg (piem--git-config-list (piem-public-inbox-config-file))) + inboxdir-urls) + (maphash + (lambda (key val) + (when (string-match + (rx string-start "publicinbox." + (group (one-or-more not-newline)) "." + (or "inboxdir" "mainrepo") + string-end) + key) + (push (cons (car val) + (when-let ((url (car (gethash + (format "publicinbox.%s.url" + (match-string 1 key)) + pi-cfg)))) + (piem--ensure-trailing-slash url))) + inboxdir-urls))) + pi-cfg) + inboxdir-urls)) + +(defun piem-lei-external-sources (&optional include-registered) + "Return a list of known external sources. +Unless INCLUDE-REGISTERED is non-nil, the result does not include +sources that have already been registered with lei as an +external (via `lei add-external')." + (let ((inboxdir-urls (piem-lei-inboxdir-urls))) + (nconc + (let ((inboxdirs (mapcar #'car inboxdir-urls))) + (if include-registered + inboxdirs + (cl-set-difference inboxdirs (piem-lei-externals) :test #'equal))) + (cl-set-difference + (delq nil + (mapcar (lambda (x) + (when-let ((url (plist-get (cdr x) :url))) + ;; lei-add-external normalizes URLs to + ;; have a trailing slash. + (piem--ensure-trailing-slash url))) + (piem-merged-inboxes))) + (delq nil (mapcar #'cdr inboxdir-urls)) + :test #'equal)))) + +(defun piem-lei-read-external-source (prompt &optional default history) + (completing-read prompt (piem-lei-external-sources) + nil nil nil history default)) + +(defun piem-lei-read-external-source-all (prompt &optional default history) + (completing-read prompt (piem-lei-external-sources t) + nil nil nil history default)) + (defun piem-lei-q-read-sort-key (&rest _ignore) (pcase (read-char-choice "re[c]eived re[l]evance [d]ocid " (list ?c ?l ?d)) @@ -389,17 +454,22 @@ (defun piem-lei-q-read-sort-key (&rest _ignore) (?l "relevance") (?d "docid"))) +;; TODO: Support reading multiple values. (transient-define-argument piem-lei-q:--include () :description "Include external in search" :class 'transient-option :shortarg "-I" - :argument "--include=") + :argument "--include=" + :reader #'piem-lei-read-external-source) + +;; TODO: Support reading multiple values. (transient-define-argument piem-lei-q:--only () :description "Search only this location" :class 'transient-option :shortarg "-O" - :argument "--only=") + :argument "--only=" + :reader #'piem-lei-read-external-source-all) (transient-define-argument piem-lei-q:--sort () :description "Sort key for results" -- 2.33.1