From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs Subject: bug#44016: 28.0.50; Add new "gnus-search" search interface to Gnus Date: Sun, 01 Nov 2020 13:38:53 -0800 Message-ID: <87o8kgbvv6.fsf@ericabrahamsen.net> References: <877drrigg6.fsf@ericabrahamsen.net> <87k0vqsqol.fsf@gnus.org> <87tuuu5fyf.fsf@ericabrahamsen.net> <874km9d4mc.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20022"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Stefan Monnier To: 44016@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 01 22:40:20 2020 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 1kZL5I-00057m-6C for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 01 Nov 2020 22:40:20 +0100 Original-Received: from localhost ([::1]:47804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZL5H-0000rp-6n for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 01 Nov 2020 16:40:19 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZL50-0000pw-Lq for bug-gnu-emacs@gnu.org; Sun, 01 Nov 2020 16:40:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55490) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kZL50-0001gP-CZ for bug-gnu-emacs@gnu.org; Sun, 01 Nov 2020 16:40:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kZL50-0004wg-9M for bug-gnu-emacs@gnu.org; Sun, 01 Nov 2020 16:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Nov 2020 21:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44016 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 44016-submit@debbugs.gnu.org id=B44016.160426674318926 (code B ref 44016); Sun, 01 Nov 2020 21:40:02 +0000 Original-Received: (at 44016) by debbugs.gnu.org; 1 Nov 2020 21:39:03 +0000 Original-Received: from localhost ([127.0.0.1]:38800 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kZL43-0004vC-0j for submit@debbugs.gnu.org; Sun, 01 Nov 2020 16:39:03 -0500 Original-Received: from ericabrahamsen.net ([52.70.2.18]:58556 helo=mail.ericabrahamsen.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kZL40-0004ug-Tu for 44016@debbugs.gnu.org; Sun, 01 Nov 2020 16:39:01 -0500 Original-Received: from localhost (c-73-254-86-141.hsd1.wa.comcast.net [73.254.86.141]) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id D3C22FA0B0; Sun, 1 Nov 2020 21:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericabrahamsen.net; s=mail; t=1604266735; bh=FO0b3Z5PcRCUgi3jSQeCJxX2LucQRQTh5NFzOV+/geo=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=ncWSaQ1YuNkLGENwDHgSzKdNFNHfJP1dtO8WsWtdNI+2FUc8Fgk50LrCgfgav96PM CtcZdgE/ZBU9h1oKF0c9NygR8A5w9Icx6McR1ZxQiWG9u9twhZhTO/pLnPXcW/g2Ax 9zXgn/IUvSd3QHIRhnugz7m/pqygOZg6g15WZ7aw= In-Reply-To: <874km9d4mc.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sat, 31 Oct 2020 22:32:11 -0700") 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" Xref: news.gmane.io gmane.emacs.bugs:192476 Archived-At: Eric Abrahamsen writes: > Eric Abrahamsen writes: > >> On 10/16/20 07:08 AM, Lars Ingebrigtsen wrote: >>> Eric Abrahamsen writes: >>> >>>> - This patch doesn't remove the nnir.el library, though that's now >>>> obsolete. I think removing it could be problematic: it's not like >>>> declaring functions/variables obsolete, where we can let people down >>>> gently. I suspect plenty of code uses (require 'nnir), which will >>>> cause blowups. Renaming gnus-search.el to nnir.el doesn't make a lot >>>> of sense, though. I'm considering leaving the nnir.el file in there, >>>> but containing nothing but a warning. >>> >>> Just move it to obsolete/. >> >> Oh, of course -- thanks. > > Finally done! I think. Most of the final work was writing the docs. Stefan, I am also dragging you into this briefly, because we talked (perhaps several years ago now) about providing nice completion for the search keys in this library: both using TAB in the minibuffer while entering the search query, and also expanding abbreviated keys programmatically during parsing. So far as I know I've done this correctly, but I wanted to run it by you and see if you had any suggestions/corrections. The expandable search keys are kept in `gnus-search-expandable-keys'. The programmatic completion part looks like: --8<---------------cut here---------------start------------->8--- +(defun gnus-search-query-expand-key (key) + (cond ((test-completion key gnus-search-expandable-keys) + ;; We're done! + key) + ;; There is more than one possible completion. + ((consp (cdr (completion-all-completions + key gnus-search-expandable-keys #'stringp 0))) + (signal 'gnus-search-parse-error + (list (format "Ambiguous keyword: %s" key)))) + ;; Return KEY, either completed or untouched. + ((car-safe (completion-try-completion + key gnus-search-expandable-keys + #'stringp 0))))) --8<---------------cut here---------------end--------------->8--- The desired behavior is that a key is expanded if it's a prefix of only one key in `gnus-search-expandable-keys', it's left alone if it isn't, and an error is raised if it's a prefix of more than one expandable key. That means the user can't enter their own arbitrary keys that are a prefix of a known key, but, too bad. The interactive minibuffer part looks like: --8<---------------cut here---------------start------------->8--- +(defvar gnus-search-minibuffer-map + (let ((km (make-sparse-keymap))) + (set-keymap-parent km minibuffer-local-map) + (define-key km (kbd "SPC") #'self-insert-command) + (define-key km (kbd "TAB") #'gnus-search-complete-key) + km)) + +(defun gnus-search-complete-key () + "Complete a search key at point. +Used when reading a search query from the minibuffer." + (interactive) + (when (completion-in-region + (save-excursion + (if (re-search-backward " " (minibuffer-prompt-end) t) + (1+ (point)) + (minibuffer-prompt-end))) + (point) gnus-search-expandable-keys) + (insert ":"))) + +(defun gnus-search-make-spec (arg) + (list (cons 'query + (read-from-minibuffer + "Query: " nil gnus-search-minibuffer-map + nil 'gnus-search-history)) + (cons 'raw arg))) --8<---------------cut here---------------end--------------->8--- This appears to work, though there's more that I can do in `gnus-search-complete-key' to check the surrounding text and handle various situations gracefully. Mostly I'm not entirely confident that `completion-in-region' is the right function to be using here. Thanks for any tips, Eric