[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#72210: 31.0.50; Feature request: multi-category support in `icomplet
From: |
Fernando de Morais |
Subject: |
bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'. |
Date: |
Sat, 20 Jul 2024 11:22:51 -0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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.
- bug#72210: 31.0.50; Feature request: multi-category support in `icomplete-fido-kill'.,
Fernando de Morais <=