From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' Date: Tue, 17 Sep 2024 17:15:18 -0400 Message-ID: References: <87ttgk16tg.fsf@gmail.com> <87r0a258js.fsf@gmail.com> Reply-To: Stefan Monnier 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="36554"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Daniel Mendler , 72210@debbugs.gnu.org To: Fernando de Morais Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 17 23:16:05 2024 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 1sqfYK-0009MM-Fw for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 17 Sep 2024 23:16:04 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqfY9-0000JF-Nl; Tue, 17 Sep 2024 17:15:53 -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 1sqfY5-0000Iz-DT for bug-gnu-emacs@gnu.org; Tue, 17 Sep 2024 17:15:49 -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 1sqfY2-0000x0-QB for bug-gnu-emacs@gnu.org; Tue, 17 Sep 2024 17:15:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=nd0ywzcPnxSBZcqDEZlAVEyZWStKxUzRS51vCHe0iBs=; b=Un3XWRHQHfKFk6rdPhXyaueGfqWTmpOnDR8mCkT/DnpCRoPHfuqmmA8d0rdLFh7McnUT43GBd4ZKgS8sAk92LkvJ985WrGaiJX6yJ/5IeSLRNT2exbhWm06qcfiQ3FB42dHlK6F+JmI2PTWOINDplOppfb9HivsmQrNypcmQd9ViG/RqgeZF3a9HOECICZhdcbbMHaFxZWVQJMIYkMnSNFSahUm2kfL+TReXZdhpEeQ61Pi5xRIVHX0Hnv2Ytp5DGa1SRruIHTgaq4mq4LSYhLdxhAq8NPHGcn4ZZJUceX5f+NvbK85kb24nyJ/Gv6KMjoNyUB8acaerJPVAQgneuQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sqfYH-000600-Mv for bug-gnu-emacs@gnu.org; Tue, 17 Sep 2024 17:16:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Sep 2024 21:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72210 X-GNU-PR-Package: emacs Original-Received: via spool by 72210-submit@debbugs.gnu.org id=B72210.172660774623029 (code B ref 72210); Tue, 17 Sep 2024 21:16:01 +0000 Original-Received: (at 72210) by debbugs.gnu.org; 17 Sep 2024 21:15:46 +0000 Original-Received: from localhost ([127.0.0.1]:56135 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqfY2-0005zN-DX for submit@debbugs.gnu.org; Tue, 17 Sep 2024 17:15:46 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:8489) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqfY0-0005z7-9O for 72210@debbugs.gnu.org; Tue, 17 Sep 2024 17:15:45 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 19BA5441418; Tue, 17 Sep 2024 17:15:22 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1726607719; bh=gpKOQae0B0lZkUHpHmBCFHiICA4/axtJialkYvcij5Q=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=KjCz7N/zoiTV9eY2mLy3voc1DNYAQLDRwipvZ2al2/nWuf/JZ7qz7lFd4cP0zuAws ltt0KtacR0BUYphlddJdCbzypaN2TbauchhDL6g9lAyhd+XWhNfEUk69Dr2UEf6/H+ fYM6SmDJtLg4+ZTSf6f6gR74m677Xdp7Mp0tDQvafQ+60eHdOJ36Bxh5Bdh6U+c6dP /wu9TUoN0U1/DAbszGHzN6iDTOOY1sKNrgbage+2Bqdk+FaADZwLTWrDhxONibk7sz P2oENohg6luXbGSyklBWm+RDACjeTxg9JLRG9HGyJWkFFvcKxixMOODj/N6/wjjWx3 KglKo1zGYISrA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 99675441364; Tue, 17 Sep 2024 17:15:19 -0400 (EDT) Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 84AD81204FB; Tue, 17 Sep 2024 17:15:19 -0400 (EDT) In-Reply-To: <87r0a258js.fsf@gmail.com> (Fernando de Morais's message of "Mon, 02 Sep 2024 13:23:19 -0300") 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:291975 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > #+begin_src emacs-lisp > (progn > (package-initialize) > (load-library "consult") > (icomplete-vertical-mode t) > (keymap-set icomplete-minibuffer-map "C-k" 'icomplete-fido-kill)) > #+end_src > > - Then, ``M-x consult-buffer''; > - Type *M (this should turn the `*Messages*' buffer the current > candidate); > - Then ``C-k'' > > The following message should appear in the minibuffer: > > [Sorry, don=E2=80=99t know how to kill things for =E2=80=98multi-category= =E2=80=99] Oh, I see, so the issue is that `consult-buffer` lists not just actual buffers but also recently visited files and other sources, so it specifies as `category` the symbol `multi-category` and then it uses some internal convention about how each completion candidate is annotated with its type. > Follows attached! This is my first patch, so I might have made > mistakes, but I'm here to adjust whatever you deem necessary. And your patch adds support to `icomplete.el` for this specific convention. There are a few too many things that are "ad-hoc" in that approach for my taste, but I agree that there's a good justification for adding support for completion tables that can use a mix of different types and thus need to offer some way to know further details about the category of any given completion candidate. Maybe a better option would be something like the patch below, so `consult` could define its own method for its own category, which could even extend the semantics to do thing like delete bookmarks when applied to bookmarks, etc... Stefan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=icomplete.patch diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 2ea5e36fa88..8013f68dcf4 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -317,6 +317,20 @@ icomplete-vertical-goto-last ;;;_* Helpers for `fido-mode' (or `ido-mode' emulation) +(cl-defgeneric icomplete-fkill-candidate (category _candidate) + (error "Sorry, don't know how to kill things for `%s'" category)) + +(cl-defmethod icomplete-kill-candidate ((_ (eq 'buffer)) thing) + (when (yes-or-no-p (concat "Kill buffer " thing "? ")) + (kill-buffer thing))) + +(cl-defmethod icomplete-kill-candidate ((_ (eq 'file)) thing) + (let* ((dir (file-name-directory (icomplete--field-string))) + (file (expand-file-name thing dir))) + (when (yes-or-no-p (concat "Delete file " file "? ")) + (delete-file file) t)))) + + (defun icomplete-fido-kill () "Kill line or current completion, like `ido-mode'. If killing to the end of line make sense, call `kill-line', @@ -331,26 +345,12 @@ icomplete-fido-kill (call-interactively 'kill-line) (let* ((all (completion-all-sorted-completions)) (thing (car all)) - (cat (icomplete--category)) - (action - (cl-case cat - (buffer - (lambda () - (when (yes-or-no-p (concat "Kill buffer " thing "? ")) - (kill-buffer thing)))) - ((project-file file) - (lambda () - (let* ((dir (file-name-directory (icomplete--field-string))) - (path (expand-file-name thing dir))) - (when (yes-or-no-p (concat "Delete file " path "? ")) - (delete-file path) t)))) - (t - (error "Sorry, don't know how to kill things for `%s'" cat))))) + (cat (icomplete--category))) (when (let (;; Allow `yes-or-no-p' to work and don't let it ;; `icomplete-exhibit' anything. (enable-recursive-minibuffers t) (icomplete-mode nil)) - (funcall action)) + (icomplete-kill-candidate cat thing)) (completion--cache-all-sorted-completions (icomplete--field-beg) (icomplete--field-end) --=-=-=--