* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. @ 2024-07-20 14:22 Fernando de Morais 2024-07-25 7:42 ` Eli Zaretskii 2024-09-01 14:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 2 replies; 14+ messages in thread From: Fernando de Morais @ 2024-07-20 14:22 UTC (permalink / raw) To: 72210 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. ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. 2024-07-20 14:22 bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' Fernando de Morais @ 2024-07-25 7:42 ` Eli Zaretskii 2024-08-17 8:08 ` Eli Zaretskii 2024-09-01 14:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 1 sibling, 1 reply; 14+ messages in thread From: Eli Zaretskii @ 2024-07-25 7:42 UTC (permalink / raw) To: Fernando de Morais, João Távora; +Cc: 72210 > From: Fernando de Morais <fernandodemorais.jf@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? ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. 2024-07-25 7:42 ` Eli Zaretskii @ 2024-08-17 8:08 ` Eli Zaretskii 2024-08-31 7:57 ` Eli Zaretskii 0 siblings, 1 reply; 14+ messages in thread From: Eli Zaretskii @ 2024-08-17 8:08 UTC (permalink / raw) To: joaotavora; +Cc: fernandodemorais.jf, 72210 Ping! João, any comments to this issue? > Cc: 72210@debbugs.gnu.org > Date: Thu, 25 Jul 2024 10:42:47 +0300 > From: Eli Zaretskii <eliz@gnu.org> > > > From: Fernando de Morais <fernandodemorais.jf@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? > > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. 2024-08-17 8:08 ` Eli Zaretskii @ 2024-08-31 7:57 ` Eli Zaretskii 2024-08-31 22:14 ` João Távora 0 siblings, 1 reply; 14+ messages in thread From: Eli Zaretskii @ 2024-08-31 7:57 UTC (permalink / raw) To: joaotavora; +Cc: fernandodemorais.jf, 72210 Ping! Ping! João, please respond. > Cc: fernandodemorais.jf@gmail.com, 72210@debbugs.gnu.org > Date: Sat, 17 Aug 2024 11:08:14 +0300 > From: Eli Zaretskii <eliz@gnu.org> > > Ping! João, any comments to this issue? > > > Cc: 72210@debbugs.gnu.org > > Date: Thu, 25 Jul 2024 10:42:47 +0300 > > From: Eli Zaretskii <eliz@gnu.org> > > > > > From: Fernando de Morais <fernandodemorais.jf@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? > > > > > > > > > > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. 2024-08-31 7:57 ` Eli Zaretskii @ 2024-08-31 22:14 ` João Távora 2024-09-01 4:48 ` Eli Zaretskii 0 siblings, 1 reply; 14+ messages in thread From: João Távora @ 2024-08-31 22:14 UTC (permalink / raw) To: Eli Zaretskii; +Cc: fernandodemorais.jf, 72210 On Sat, Aug 31, 2024 at 8:57 AM Eli Zaretskii <eliz@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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. 2024-08-31 22:14 ` João Távora @ 2024-09-01 4:48 ` Eli Zaretskii 0 siblings, 0 replies; 14+ messages in thread From: Eli Zaretskii @ 2024-09-01 4:48 UTC (permalink / raw) To: João Távora, Stefan Monnier; +Cc: fernandodemorais.jf, 72210 > From: João Távora <joaotavora@gmail.com> > Date: Sat, 31 Aug 2024 23:14:04 +0100 > Cc: fernandodemorais.jf@gmail.com, 72210@debbugs.gnu.org > > On Sat, Aug 31, 2024 at 8:57 AM Eli Zaretskii <eliz@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? ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. 2024-07-20 14:22 bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' Fernando de Morais 2024-07-25 7:42 ` Eli Zaretskii @ 2024-09-01 14:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2024-09-02 16:23 ` Fernando de Morais 1 sibling, 1 reply; 14+ messages in thread From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-01 14:46 UTC (permalink / raw) To: Fernando de Morais; +Cc: 72210 > `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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. 2024-09-01 14:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-02 16:23 ` Fernando de Morais 2024-09-14 7:42 ` Eli Zaretskii 2024-09-17 21:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 2 replies; 14+ messages in thread From: Fernando de Morais @ 2024-09-02 16:23 UTC (permalink / raw) To: Stefan Monnier; +Cc: 72210 [-- Attachment #1: Type: text/plain, Size: 1591 bytes --] Hello Stefan, Stefan Monnier <monnier@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. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-support-for-multi-category-to-icomplete-fido-kil.patch --] [-- Type: text/x-patch, Size: 2595 bytes --] From 7fd715580d70d1c7cb7dbbe3035a439c4d06c49d Mon Sep 17 00:00:00 2001 From: Fernando de Morais <fernandodemorais.jf@gmail.com> Date: Mon, 2 Sep 2024 13:14:04 -0300 Subject: [PATCH] Add support for multi-category to icomplete-fido-kill * etc/NEWS: Announce the multi-category support in 'icomplete-fido-kill'. * lisp/icomplete.el (icomplete--refine-multi-category): New function. (icomplete-fido-kill): Apply the helper function to refine 'multi-category' to its actual type. --- etc/NEWS | 7 +++++++ lisp/icomplete.el | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 1e66f084117..86c2995cf19 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -65,6 +65,13 @@ different values for completion-affecting variables like applies for the styles configuration in 'completion-category-overrides' and 'completion-category-defaults'. +** Icomplete + +--- +*** 'icomplete-fido-kill' now works within multi-category environments. +This function can now delete a file or kill a buffer within a +multi-category environment, such as 'consult-buffer'. + ** Windows +++ diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 2ea5e36fa88..1ef861ff270 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -317,6 +317,16 @@ Return non-nil if something was stepped." ;;;_* Helpers for `fido-mode' (or `ido-mode' emulation) +(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', @@ -330,8 +340,10 @@ require user confirmation." (if (< (point) end) (call-interactively 'kill-line) (let* ((all (completion-all-sorted-completions)) - (thing (car all)) - (cat (icomplete--category)) + (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 -- 2.46.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. 2024-09-02 16:23 ` Fernando de Morais @ 2024-09-14 7:42 ` Eli Zaretskii 2024-09-17 21:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 1 sibling, 0 replies; 14+ messages in thread From: Eli Zaretskii @ 2024-09-14 7:42 UTC (permalink / raw) To: monnier, Fernando de Morais; +Cc: 72210 > Cc: 72210@debbugs.gnu.org > From: Fernando de Morais <fernandodemorais.jf@gmail.com> > Date: Mon, 02 Sep 2024 13:23:19 -0300 > > Stefan Monnier <monnier@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? ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' 2024-09-02 16:23 ` Fernando de Morais 2024-09-14 7:42 ` Eli Zaretskii @ 2024-09-17 21:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2024-09-19 16:19 ` Fernando de Morais 1 sibling, 1 reply; 14+ messages in thread From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-17 21:15 UTC (permalink / raw) To: Fernando de Morais; +Cc: Daniel Mendler, 72210 [-- Attachment #1: Type: text/plain, Size: 1578 bytes --] > #+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 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: icomplete.patch --] [-- Type: text/x-diff, Size: 2302 bytes --] 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) ^ permalink raw reply related [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' 2024-09-17 21:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-19 16:19 ` Fernando de Morais 2024-09-24 17:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 14+ messages in thread From: Fernando de Morais @ 2024-09-19 16:19 UTC (permalink / raw) To: Stefan Monnier; +Cc: Daniel Mendler, 72210 Hello Stefan, Stefan Monnier <monnier@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. ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' 2024-09-19 16:19 ` Fernando de Morais @ 2024-09-24 17:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2024-10-14 1:57 ` Fernando de Morais 0 siblings, 1 reply; 14+ messages in thread From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-24 17:50 UTC (permalink / raw) To: Fernando de Morais; +Cc: Daniel Mendler, 72210 [-- Attachment #1: Type: text/plain, Size: 1095 bytes --] >> 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 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: icomplete.patch --] [-- Type: text/x-diff, Size: 3473 bytes --] 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 "./"))) ^ permalink raw reply related [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' 2024-09-24 17:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-14 1:57 ` Fernando de Morais 2024-10-14 12:59 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 14+ messages in thread From: Fernando de Morais @ 2024-10-14 1:57 UTC (permalink / raw) To: Stefan Monnier; +Cc: Daniel Mendler, 72210 Hello Stefan, Stefan Monnier <monnier@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. ^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' 2024-10-14 1:57 ` Fernando de Morais @ 2024-10-14 12:59 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 0 replies; 14+ messages in thread From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-14 12:59 UTC (permalink / raw) To: Fernando de Morais; +Cc: Daniel Mendler, 72210 > 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2024-10-14 12:59 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-07-20 14:22 bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill' Fernando de Morais 2024-07-25 7:42 ` Eli Zaretskii 2024-08-17 8:08 ` Eli Zaretskii 2024-08-31 7:57 ` Eli Zaretskii 2024-08-31 22:14 ` João Távora 2024-09-01 4:48 ` Eli Zaretskii 2024-09-01 14:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2024-09-02 16:23 ` Fernando de Morais 2024-09-14 7:42 ` Eli Zaretskii 2024-09-17 21:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2024-09-19 16:19 ` Fernando de Morais 2024-09-24 17:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2024-10-14 1:57 ` Fernando de Morais 2024-10-14 12:59 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.