all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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

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.