-
-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
This is related to the usage of embark-consult (my version is 20250622.535), my use case is: I want to do a cleanup of terminal buffers based on a text
(global-set-key (kbd "C-c S") (lambda () (interactive (consult-line-multi '(:mode vterm-mode)))))
I was already doing something like this with (consult-buffer)
The thing is that maybe, embark-act should propose to kill the buffer from the selected text
Here is the code I used to make it work, so it's solved on my side, just wanted to share this is if useful to others, and maybe, it should not be that difficult
Note: this was assisted partially with gemini3-pro
;; oantolin comment https://www.reddit.com/r/emacs/comments/16g08me/comment/k065g9m/
(define-key minibuffer-local-map (kbd "M-k") #'my/switch-to-buffer-kill)
(defun my/switch-to-buffer-kill (&optional arg)
"If target is a buffer, kill it via Embark.
If target is a consult-location, extract the buffer and kill it manually.
In both cases, keep the menu open."
(interactive "P")
(let* ((targets (embark--targets))
(target-entry (car targets))
(type (plist-get target-entry :type)))
(cond
;; embark sees a real buffer and we can directly suggest deletion
((eq type 'buffer)
(let ((embark-default-action-overrides '((buffer . kill-buffer)))
(embark-pre-action-hooks nil)
embark-quit-after-action)
(embark-dwim arg)))
;; embark sees a line/location. Extract buffer manually and kill it.
((eq type 'consult-location)
(let* ((target-string (plist-get target-entry :target))
;; Look for hidden marker in the string
(location-data (and (stringp target-string)
(get-text-property 0 'consult-location target-string)))
(buf (and (consp location-data)
(marker-buffer (car location-data)))))
(if buf
(progn
(with-current-buffer buf
(kill-buffer buf))
(setq embark-quit-after-action nil)))))
(t (message "my/ERROR: Don't know how to kill target type: %s" type)))))Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels