From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#44016: 28.0.50; Add new "gnus-search" search interface to Gnus Date: Sun, 01 Nov 2020 18:50:50 -0500 Message-ID: References: <877drrigg6.fsf@ericabrahamsen.net> <87k0vqsqol.fsf@gnus.org> <87tuuu5fyf.fsf@ericabrahamsen.net> <874km9d4mc.fsf@ericabrahamsen.net> <87o8kgbvv6.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="12817"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 44016@debbugs.gnu.org To: Eric Abrahamsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 02 00:52:17 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 1kZN8z-0003EV-1Z for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Nov 2020 00:52:17 +0100 Original-Received: from localhost ([::1]:57194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZN8y-0004ce-0T for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 01 Nov 2020 18:52:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZN8k-0004cR-RQ for bug-gnu-emacs@gnu.org; Sun, 01 Nov 2020 18:52:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kZN8k-0008Sy-IW for bug-gnu-emacs@gnu.org; Sun, 01 Nov 2020 18:52:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kZN8k-0001uf-HU for bug-gnu-emacs@gnu.org; Sun, 01 Nov 2020 18:52:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Nov 2020 23:52: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.16042746627286 (code B ref 44016); Sun, 01 Nov 2020 23:52:02 +0000 Original-Received: (at 44016) by debbugs.gnu.org; 1 Nov 2020 23:51:02 +0000 Original-Received: from localhost ([127.0.0.1]:38999 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kZN7l-0001tR-Ua for submit@debbugs.gnu.org; Sun, 01 Nov 2020 18:51:02 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:28843) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kZN7j-0001sw-OI for 44016@debbugs.gnu.org; Sun, 01 Nov 2020 18:51:00 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 0077680853; Sun, 1 Nov 2020 18:50:54 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 4EAD6806AC; Sun, 1 Nov 2020 18:50:51 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1604274651; bh=2YnOOXO/R8mUuSWhuvtwotuluFliWl70+mjG1s/nDhA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Oq5THoyXmiWbRAe1Ex4twSrNIqtC02GLpaSf/VD2gEeRvAmURJzSmReud7KuUAfNf 3yzTnPlI/IhVn6LKK1n0d+Kb7CpR7e53U1+RlWJcpZBUws30wPIhXXxgcDRSzieESI uiO1onBqlVGoCkY+R0mA4BYjnXLHQeYS21CVVv2qVBq2QZksKKl9cEwfQQwWjiNJ3x vyeJm4C5XPLo/UWAmgzuMMPe8OINSobRWNltSln4o0QYs1hme3iotxJTWHGykPn4er 2NbyxnHiGItEA6v2yXg7upus6h+E42B7P/gif+ABjHJDmkVKE1ZnRPmwh9rxUBV/xO S1/u7E1RLeX4Q== Original-Received: from alfajor (unknown [157.52.9.240]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 1623712031C; Sun, 1 Nov 2020 18:50:51 -0500 (EST) In-Reply-To: <87o8kgbvv6.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sun, 01 Nov 2020 13:38:53 -0800") 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:192491 Archived-At: > 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--- IIUC this function is used to expand unambiguous abbreviations, right (rather than the more usual "completion" which is done as the user is typing)? It just happens to reuse the completion machinery to do the work. If so, it looks OK (I guess you could try and reuse the output from completion-all-completions in the last branch instead of calling completion-try-completion, but it might be more trouble than it's worth). > --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--- Hmm... here I think instead of calling `completion-in-region` yourself, you'd want to do something like: (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) ;; Isn't this redundant? (define-key km (kbd "TAB") #'completion-at-point) km)) (defun gnus-search--complete-key-data () "Return completion data for gnus-search keys." (list (save-excursion (if (re-search-backward " " (minibuffer-prompt-end) t) (1+ (point)) (minibuffer-prompt-end))) (point) gnus-search-expandable-keys)) (minibuffer-with-setup-hook (lambda () (add-hook 'completion-at-point-functions #'gnus-search--complete-key-data nil t)) (read-from-minibuffer ...)) See `read--expression` (used to provide completion on Elisp function and var names when reading an ELisp expression in the minibuffer, such as in `M-:`) for an example. If you want to auto-insert a `:` you'd then do it via an `:exit-function`. Stefan