GNU bug report logs -
#72210
31.0.50; Feature request: multi-category support in `icomplete-fido-kill'.
Previous Next
To reply to this bug, email your comments to 72210 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Sat, 20 Jul 2024 14:26:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Fernando de Morais <fernandodemorais.jf <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 20 Jul 2024 14:26:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Dear maintainers,
`icomplete-fido-kill' works very well, but cannot handle the deletion of
files or killing buffers when they are behind a multi-category
``situation''. Add this would be useful for those of us that combine
`icomplete' with, e.g., `consult-buffer'.
What follows is just the ``hacky'' approach that's currently being used
in my init:
#+begin_src emacs-lisp
;; Stolen from Embark <https://git.savannah.gnu.org/cgit/emacs/elpa.git/tree/embark.el?h=externals/embark#n2108>
(defun icomplete--refine-multi-category (target)
"Refine `multi-category' TARGET to its actual type."
(or (let ((mc (get-text-property 0 'multi-category target)))
(cond
;; The `cdr' of the `multi-category' property can be a buffer object.
((and (eq (car mc) 'buffer) (buffer-live-p (cdr mc)))
(cons 'buffer (buffer-name (cdr mc))))
((stringp (cdr mc)) mc)))
(cons 'general target)))
(defun icomplete-fido-kill ()
"Kill line or current completion, like `ido-mode'.
If killing to the end of line make sense, call `kill-line',
otherwise kill the currently selected completion candidate.
Exactly what killing entails is dependent on the things being
completed. If completing files, it means delete the file. If
completing buffers it means kill the buffer. Both actions
require user confirmation."
(interactive)
(let ((end (icomplete--field-end)))
(if (< (point) end)
(call-interactively 'kill-line)
(let* ((all (completion-all-sorted-completions))
;; Actual changes (
(refined-pair (when (eq 'multi-category (icomplete--category))
(icomplete--refine-multi-category (car all))))
(cat (or (car-safe refined-pair) (icomplete--category)))
(thing (or (cdr-safe refined-pair) (car all)))
;; )
(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)))))
(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))
(completion--cache-all-sorted-completions
(icomplete--field-beg)
(icomplete--field-end)
(cdr all)))
(message nil)))))
#+end_src
Thank you for any consideration on the matter.
--
Regards,
Fernando de Morais.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Thu, 25 Jul 2024 07:44:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 72210 <at> debbugs.gnu.org (full text, mbox):
> From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> Date: Sat, 20 Jul 2024 11:22:51 -0300
>
> Dear maintainers,
>
> `icomplete-fido-kill' works very well, but cannot handle the deletion of
> files or killing buffers when they are behind a multi-category
> ``situation''. Add this would be useful for those of us that combine
> `icomplete' with, e.g., `consult-buffer'.
>
> What follows is just the ``hacky'' approach that's currently being used
> in my init:
>
> #+begin_src emacs-lisp
> ;; Stolen from Embark <https://git.savannah.gnu.org/cgit/emacs/elpa.git/tree/embark.el?h=externals/embark#n2108>
> (defun icomplete--refine-multi-category (target)
> "Refine `multi-category' TARGET to its actual type."
> (or (let ((mc (get-text-property 0 'multi-category target)))
> (cond
> ;; The `cdr' of the `multi-category' property can be a buffer object.
> ((and (eq (car mc) 'buffer) (buffer-live-p (cdr mc)))
> (cons 'buffer (buffer-name (cdr mc))))
> ((stringp (cdr mc)) mc)))
> (cons 'general target)))
>
> (defun icomplete-fido-kill ()
> "Kill line or current completion, like `ido-mode'.
> If killing to the end of line make sense, call `kill-line',
> otherwise kill the currently selected completion candidate.
> Exactly what killing entails is dependent on the things being
> completed. If completing files, it means delete the file. If
> completing buffers it means kill the buffer. Both actions
> require user confirmation."
> (interactive)
> (let ((end (icomplete--field-end)))
> (if (< (point) end)
> (call-interactively 'kill-line)
> (let* ((all (completion-all-sorted-completions))
> ;; Actual changes (
> (refined-pair (when (eq 'multi-category (icomplete--category))
> (icomplete--refine-multi-category (car all))))
> (cat (or (car-safe refined-pair) (icomplete--category)))
> (thing (or (cdr-safe refined-pair) (car all)))
> ;; )
> (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)))))
> (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))
> (completion--cache-all-sorted-completions
> (icomplete--field-beg)
> (icomplete--field-end)
> (cdr all)))
> (message nil)))))
> #+end_src
>
> Thank you for any consideration on the matter.
João, any comments?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Sat, 17 Aug 2024 08:10:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 72210 <at> debbugs.gnu.org (full text, mbox):
Ping! João, any comments to this issue?
> Cc: 72210 <at> debbugs.gnu.org
> Date: Thu, 25 Jul 2024 10:42:47 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
>
> > From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> > Date: Sat, 20 Jul 2024 11:22:51 -0300
> >
> > Dear maintainers,
> >
> > `icomplete-fido-kill' works very well, but cannot handle the deletion of
> > files or killing buffers when they are behind a multi-category
> > ``situation''. Add this would be useful for those of us that combine
> > `icomplete' with, e.g., `consult-buffer'.
> >
> > What follows is just the ``hacky'' approach that's currently being used
> > in my init:
> >
> > #+begin_src emacs-lisp
> > ;; Stolen from Embark <https://git.savannah.gnu.org/cgit/emacs/elpa.git/tree/embark.el?h=externals/embark#n2108>
> > (defun icomplete--refine-multi-category (target)
> > "Refine `multi-category' TARGET to its actual type."
> > (or (let ((mc (get-text-property 0 'multi-category target)))
> > (cond
> > ;; The `cdr' of the `multi-category' property can be a buffer object.
> > ((and (eq (car mc) 'buffer) (buffer-live-p (cdr mc)))
> > (cons 'buffer (buffer-name (cdr mc))))
> > ((stringp (cdr mc)) mc)))
> > (cons 'general target)))
> >
> > (defun icomplete-fido-kill ()
> > "Kill line or current completion, like `ido-mode'.
> > If killing to the end of line make sense, call `kill-line',
> > otherwise kill the currently selected completion candidate.
> > Exactly what killing entails is dependent on the things being
> > completed. If completing files, it means delete the file. If
> > completing buffers it means kill the buffer. Both actions
> > require user confirmation."
> > (interactive)
> > (let ((end (icomplete--field-end)))
> > (if (< (point) end)
> > (call-interactively 'kill-line)
> > (let* ((all (completion-all-sorted-completions))
> > ;; Actual changes (
> > (refined-pair (when (eq 'multi-category (icomplete--category))
> > (icomplete--refine-multi-category (car all))))
> > (cat (or (car-safe refined-pair) (icomplete--category)))
> > (thing (or (cdr-safe refined-pair) (car all)))
> > ;; )
> > (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)))))
> > (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))
> > (completion--cache-all-sorted-completions
> > (icomplete--field-beg)
> > (icomplete--field-end)
> > (cdr all)))
> > (message nil)))))
> > #+end_src
> >
> > Thank you for any consideration on the matter.
>
> João, any comments?
>
>
>
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Sat, 31 Aug 2024 07:59:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 72210 <at> debbugs.gnu.org (full text, mbox):
Ping! Ping! João, please respond.
> Cc: fernandodemorais.jf <at> gmail.com, 72210 <at> debbugs.gnu.org
> Date: Sat, 17 Aug 2024 11:08:14 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
>
> Ping! João, any comments to this issue?
>
> > Cc: 72210 <at> debbugs.gnu.org
> > Date: Thu, 25 Jul 2024 10:42:47 +0300
> > From: Eli Zaretskii <eliz <at> gnu.org>
> >
> > > From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> > > Date: Sat, 20 Jul 2024 11:22:51 -0300
> > >
> > > Dear maintainers,
> > >
> > > `icomplete-fido-kill' works very well, but cannot handle the deletion of
> > > files or killing buffers when they are behind a multi-category
> > > ``situation''. Add this would be useful for those of us that combine
> > > `icomplete' with, e.g., `consult-buffer'.
> > >
> > > What follows is just the ``hacky'' approach that's currently being used
> > > in my init:
> > >
> > > #+begin_src emacs-lisp
> > > ;; Stolen from Embark <https://git.savannah.gnu.org/cgit/emacs/elpa.git/tree/embark.el?h=externals/embark#n2108>
> > > (defun icomplete--refine-multi-category (target)
> > > "Refine `multi-category' TARGET to its actual type."
> > > (or (let ((mc (get-text-property 0 'multi-category target)))
> > > (cond
> > > ;; The `cdr' of the `multi-category' property can be a buffer object.
> > > ((and (eq (car mc) 'buffer) (buffer-live-p (cdr mc)))
> > > (cons 'buffer (buffer-name (cdr mc))))
> > > ((stringp (cdr mc)) mc)))
> > > (cons 'general target)))
> > >
> > > (defun icomplete-fido-kill ()
> > > "Kill line or current completion, like `ido-mode'.
> > > If killing to the end of line make sense, call `kill-line',
> > > otherwise kill the currently selected completion candidate.
> > > Exactly what killing entails is dependent on the things being
> > > completed. If completing files, it means delete the file. If
> > > completing buffers it means kill the buffer. Both actions
> > > require user confirmation."
> > > (interactive)
> > > (let ((end (icomplete--field-end)))
> > > (if (< (point) end)
> > > (call-interactively 'kill-line)
> > > (let* ((all (completion-all-sorted-completions))
> > > ;; Actual changes (
> > > (refined-pair (when (eq 'multi-category (icomplete--category))
> > > (icomplete--refine-multi-category (car all))))
> > > (cat (or (car-safe refined-pair) (icomplete--category)))
> > > (thing (or (cdr-safe refined-pair) (car all)))
> > > ;; )
> > > (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)))))
> > > (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))
> > > (completion--cache-all-sorted-completions
> > > (icomplete--field-beg)
> > > (icomplete--field-end)
> > > (cdr all)))
> > > (message nil)))))
> > > #+end_src
> > >
> > > Thank you for any consideration on the matter.
> >
> > João, any comments?
> >
> >
> >
> >
>
>
>
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Sat, 31 Aug 2024 22:15:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 72210 <at> debbugs.gnu.org (full text, mbox):
On Sat, Aug 31, 2024 at 8:57 AM Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> Ping! Ping! João, please respond.
I'll not be implementing this. Might be a good idea, who knows. Maybe
ask Stefan for his opinion.
João
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Sun, 01 Sep 2024 04:53:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 72210 <at> debbugs.gnu.org (full text, mbox):
> From: João Távora <joaotavora <at> gmail.com>
> Date: Sat, 31 Aug 2024 23:14:04 +0100
> Cc: fernandodemorais.jf <at> gmail.com, 72210 <at> debbugs.gnu.org
>
> On Sat, Aug 31, 2024 at 8:57 AM Eli Zaretskii <eliz <at> gnu.org> wrote:
> >
> > Ping! Ping! João, please respond.
>
> I'll not be implementing this. Might be a good idea, who knows. Maybe
> ask Stefan for his opinion.
Thanks.
Stefan?
If no one thinks this is a good idea, I guess we should close this as
wontfix?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Sun, 01 Sep 2024 14:48:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 72210 <at> debbugs.gnu.org (full text, mbox):
> `icomplete-fido-kill' works very well, but cannot handle the deletion of
> files or killing buffers when they are behind a multi-category
> ``situation''. Add this would be useful for those of us that combine
> `icomplete' with, e.g., `consult-buffer'.
Can you provide a recipe? I'm not sufficiently familiar with that code
to really understand the problem you're facing.
> What follows is just the ``hacky'' approach that's currently being used
> in my init:
Any chance you can make it a patch against `icomplete.el`?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Mon, 02 Sep 2024 16:27:07 GMT)
Full text and
rfc822 format available.
Message #26 received at 72210 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hello Stefan,
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> `icomplete-fido-kill' works very well, but cannot handle the deletion of
>> files or killing buffers when they are behind a multi-category
>> ``situation''. Add this would be useful for those of us that combine
>> `icomplete' with, e.g., `consult-buffer'.
>
> Can you provide a recipe? I'm not sufficiently familiar with that code
> to really understand the problem you're facing.
Sure!
Please, install the `consult' package and, in an emacs -Q session,
evaluate the following:
#+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’t know how to kill things for ‘multi-category’]
The same happens when we try to use `icomplete-fido-kill' in files
listed by `consult-buffer'.
The expected result would be for `icomplete-fido-kill' to work normally,
killing the buffer, even though it is listed by `consult-buffer'.
>> What follows is just the ``hacky'' approach that's currently being used
>> in my init:
>
> Any chance you can make it a patch against `icomplete.el`?
Follows attached! This is my first patch, so I might have made
mistakes, but I'm here to adjust whatever you deem necessary.
--
Regards,
Fernando de Morais.
[0001-Add-support-for-multi-category-to-icomplete-fido-kil.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Sat, 14 Sep 2024 07:44:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 72210 <at> debbugs.gnu.org (full text, mbox):
> Cc: 72210 <at> debbugs.gnu.org
> From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> Date: Mon, 02 Sep 2024 13:23:19 -0300
>
> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>
> >> `icomplete-fido-kill' works very well, but cannot handle the deletion of
> >> files or killing buffers when they are behind a multi-category
> >> ``situation''. Add this would be useful for those of us that combine
> >> `icomplete' with, e.g., `consult-buffer'.
> >
> > Can you provide a recipe? I'm not sufficiently familiar with that code
> > to really understand the problem you're facing.
>
> Sure!
>
> Please, install the `consult' package and, in an emacs -Q session,
> evaluate the following:
>
> #+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’t know how to kill things for ‘multi-category’]
>
> The same happens when we try to use `icomplete-fido-kill' in files
> listed by `consult-buffer'.
>
> The expected result would be for `icomplete-fido-kill' to work normally,
> killing the buffer, even though it is listed by `consult-buffer'.
>
> >> What follows is just the ``hacky'' approach that's currently being used
> >> in my init:
> >
> > Any chance you can make it a patch against `icomplete.el`?
>
> Follows attached! This is my first patch, so I might have made
> mistakes, but I'm here to adjust whatever you deem necessary.
Stefan, any comments on the patch, or should I install it?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Tue, 17 Sep 2024 21:16:01 GMT)
Full text and
rfc822 format available.
Message #32 received at 72210 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> #+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’t know how to kill things for ‘multi-category’]
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
[icomplete.patch (text/x-diff, inline)]
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)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Thu, 19 Sep 2024 16:22:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 72210 <at> debbugs.gnu.org (full text, mbox):
Hello Stefan,
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
> 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.
Thanks!
--
Regards,
Fernando de Morais.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Tue, 24 Sep 2024 17:52:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 72210 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> 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
[icomplete.patch (text/x-diff, inline)]
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<file>' above.
(expand-file-name (directory-file-name current)
(substitute-env-vars dir)))))
(cond ((and probe (file-directory-p probe) (not (string= current "./")))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Mon, 14 Oct 2024 02:01:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 72210 <at> debbugs.gnu.org (full text, mbox):
Hello Stefan,
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> 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.
I wasn't sure if you were waiting for a response from Daniel or another
user of `icomplete', but from my side, I liked the idea of using
`cl-defgeneric'!
However, I couldn't use the implementation from the last patch. When I
try to load the patched `icomplete', I receive this error:
Unknown specializer (eq 'buffer)
Thank you for looking into this issue!
--
Regards,
Fernando de Morais.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72210
; Package
emacs
.
(Mon, 14 Oct 2024 13:01:02 GMT)
Full text and
rfc822 format available.
Message #44 received at 72210 <at> debbugs.gnu.org (full text, mbox):
> I wasn't sure if you were waiting for a response from Daniel or another
> user of `icomplete', but from my side,
Was kind of hoping for some help from someone, or just for my brain to
come up with a solution to the confirmation-prompt problem.
> I liked the idea of using `cl-defgeneric'!
🙂
> However, I couldn't use the implementation from the last patch.
> When I try to load the patched `icomplete', I receive this error:
>
> Unknown specializer (eq 'buffer)
That was a typo, it should say `eql` rather than `eq`, sorry 'bout that.
Stefan
This bug report was last modified 39 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.