reddit / emacs

How to copy from vertico with embark-copy-as-kill without category?

darkawower 路 2022-12-18 08:58
I use use vertico+embark. How to copy with embark-copy-as-kill only content without a category from vertico? Right now after copying from consult-ripgrep i am getting <file-path>: <content> i want to get content only. For example My copying from consult-ripgrep README.org:710: (set-face-attribute 'default nil :font "JetBrainsMono Nerd Font 14" :italic nil :height 146)) But i expect: (set-face-attribute 'default nil :font "JetBrainsMono Nerd Font 14" :italic nil :height 146)) To be honest, I couldn't even find out which package is responsible for this, vertico or embark
oantolin 路 2022-12-22 21:17
You can register with Embark a function to be used to transform the candidate prior to copying it. For example, you could do something like this: (defun strip-file-info (type string) (cons type (substring string (1+ (next-single-property-change (1+ (next-single-property-change 0 'face string)) 'face string))))) (setf (alist-get 'consult-grep embark-transformer-alist) #'strip-file-info) It skips past text with a different face twice, which takes advantage of the fact that `consult-grep` put the file and line numbers in a special face but does *not* use a special face for the separating colon. (In other words, the code works now but changes in `consult` could break it.)
darkawower 路 2022-12-23 16:23
Thank you, it works perfectly. I'll try to understand 馃檭
darkawower 路 2022-12-28 18:24
unfortunately this solution broke embark the export functionality, and i can't use wget right now 馃ゲ
oantolin 路 2022-12-28 20:28
Oh, that's right! I forgot that export uses transformed candidates! I'm not sure what wget has to do with anything. I think that to keep export working, your best bet is replacing embark-copy-as-kill for consult-grep targets: (defun copy-grep-results-as-kill (strings) (embark-copy-as-kill (mapcar (lambda (string) (substring string (1+ (next-single-property-change (1+ (next-single-property-change 0 'face string)) 'face string)))) strings))) (add-to-list 'embark-multitarget-actions 'copy-grep-results-as-kill) (embark-define-keymap embark-consult-grep-map "Keymap for actions for consult-grep results." ("w" copy-grep-results-as-kill)) (setf (alist-get 'consult-grep embark-keymap-alist) 'embark-consult-grep-map)
darkawower 路 2022-12-28 21:46
Thank you very much :) This solution works and doesn't break embark-export