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, 24 Sep 2024 13:50:31 -0400 Message-ID: References: <87ttgk16tg.fsf@gmail.com> <87r0a258js.fsf@gmail.com> <87r09fr4zt.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="31602"; 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 24 19:51:58 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 1st9hc-00083z-Rv for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Sep 2024 19:51:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1st9hN-0000wT-E9; Tue, 24 Sep 2024 13:51:41 -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 1st9hM-0000wD-AY for bug-gnu-emacs@gnu.org; Tue, 24 Sep 2024 13:51:40 -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 1st9hM-0004s7-1R for bug-gnu-emacs@gnu.org; Tue, 24 Sep 2024 13:51:40 -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=drYFg8dcz2E5sCVkdw7U9w19n3mecANmR+fPHO0SjBo=; b=ouWL5rhi4G5Rlmd42e+grhyD7eNGkEy9+kWtnvsE+VqcmRhzl3HalemFmEcVQhZPkqvZqgjqkhRfBYmnS1rkfzGElrBiu2DcIu+UcMzabi+ZmhREt/Oey66L+B/9uh57Ti0998sFn75ZF5Xw/StZudnmj+IINb1/yMPs85UAuizaHC+k0fMvWFnTOnwJAlApCqTcwP9iy850q6XKBkVr+kJMddDazUssUiGZdvdms9tSfXjvFkRt+yjom3rE1MMbr/wy8WsIiqElPsz/5uXLDqpeMvBvlFS4f/crBqRnMxjl5j9mwThvSdAymBuDhWIu0A+bjTY526WJ5WYTzqaqqw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1st9hi-0003Oq-Jx for bug-gnu-emacs@gnu.org; Tue, 24 Sep 2024 13:52:02 -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, 24 Sep 2024 17:52:02 +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.172720026912976 (code B ref 72210); Tue, 24 Sep 2024 17:52:02 +0000 Original-Received: (at 72210) by debbugs.gnu.org; 24 Sep 2024 17:51:09 +0000 Original-Received: from localhost ([127.0.0.1]:60306 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st9gq-0003NE-HE for submit@debbugs.gnu.org; Tue, 24 Sep 2024 13:51:08 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:64150) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st9go-0003Mg-9S for 72210@debbugs.gnu.org; Tue, 24 Sep 2024 13:51:07 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 482F9100042; Tue, 24 Sep 2024 13:50:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1727200232; bh=/eKJg6eF3Izn8Nokm36nCqJzZvxNZf6r0XVevx3IXqQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=fnHMIjp/o46Yd41dO2POWDAz2Kn0iV4TvFtd3u0NMZxS48sOWBASVgciY0UDRUHIv zG84fQTF7M1l7wGASDcBoD2V66+Ycu8+VdbKGHa+yZmH3Erzd8jaC+PkPRUlujb389 T2KxO97WRBbxKobVnU9xRpV3UraUt8GF2unPJH3Rv+21axPXPl1iP2RLe81pV/FBsY 36nx2zdJh3N21BnoSlt12TdaZT6L8qkBJMFrlpJhIlyIUDQkR0zDyu+nceV2dCIy8k jNczcP5yhUMcW6V8uDb4f++noYMOoArCmV/uT+03N5YMXh/jDl70aVKEg7ULcWnwkk m9iekaCgZa9oQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 71D0510005D; Tue, 24 Sep 2024 13:50:32 -0400 (EDT) Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 60A051207E8; Tue, 24 Sep 2024 13:50:32 -0400 (EDT) In-Reply-To: <87r09fr4zt.fsf@gmail.com> (Fernando de Morais's message of "Thu, 19 Sep 2024 13:19:02 -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:292354 Archived-At: --=-=-= Content-Type: text/plain >> 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... > > This is indeed a better idea! I'm not very familiar with `cl-*' code, > but the way you suggest makes `icomplete-fido-kill' very flexible. As I > understand it, even if `consult' doesn't define its methods, we can > still do it ourselves as end users, without needing to advise or > override the original function. Indeed, tho it would rely on "internal knowledge" of consult's `multi-category`. I'm not 100% happy with my suggestion, tho. One of the problems is the name (should it include "fido"? Currently, `icomplete-fido-kill` and `icomplete-fido-ret` can misbehave in non-fido-mode, because of an assumption they make about the completion-style). The other is the confirmation prompt, which feels like it should be implemented once and for all outside of the generic function. For reference here's my current code. Stefan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=icomplete.patch diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 2ea5e36fa88..c37275587b6 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -317,6 +317,30 @@ icomplete-vertical-goto-last ;;;_* Helpers for `fido-mode' (or `ido-mode' emulation) +(cl-defgeneric icomplete-kill-candidate (category _candidate) + "\"Kill\" CANDIDATE, assuming it is of kind CATEGORY. +CANDIDATE is a string denoting a completion candidate, +CATEGORY should be a completion category, as specified +in `completion-metadata'. +\"Kill\" here means to actually delete the underlying object, such +as a file, buffer, ..." + (error "Don't know how to kill things for category `%s'" category)) + +(cl-defmethod icomplete-kill-candidate ((_ (eq 'buffer)) thing) + ;; FIXME: Shouldn't the confirmation prompting be done by the caller? + (when (yes-or-no-p (concat "Kill buffer " thing "? ")) + (kill-buffer thing))) + +(cl-defmethod icomplete-kill-candidate ((_ (eq 'file)) thing) + ;; FIXME: This makes assumptions about completion style: e.g. with + ;; partial-completion, `/usr/s/d/ema' can result in DIR being + ;; `/usr/s/d/' and THING being `share/doc/emacs', in which case DIR + ;; isn't the right base directory to pass to `expand-file-name'! + (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 +355,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) @@ -373,6 +383,8 @@ icomplete-fido-ret (file-name-directory (icomplete--field-string)))) (current (car completion-all-sorted-completions)) (probe (and dir current + ;; FIXME: Same problem as in + ;; `icomplete-kill-candidate' above. (expand-file-name (directory-file-name current) (substitute-env-vars dir))))) (cond ((and probe (file-directory-p probe) (not (string= current "./"))) --=-=-=--