How can I define a command that searches the web for the evil visually selected text using google or some other search engine? counsel-search
already does this if you insert a string, but how can I define a command to do this using the selected text? (I'm using Evil.)
1 Answer
Try this function:
(defun counsel-search-selected (start end)
(interactive "r")
(let ((region (buffer-substring-no-properties start end)))
(counsel-search-action region)))
However, instead of search visual selected text. I prefer use thing-at-point
: M-x counsel-search
and press M-n
.
-
Wow, that's neat, I have no idea what buffer-substring-no-properties is, but it does the job. Also haven't know about thing-at-point, how would you implement the command which takes automatically the first suggested string of thing-at-point and counsel search it on the web in one click?– RareformFeb 18, 2022 at 7:28
-
buffer-substring-no-properties
remove text properties (like color etc.). For automatically insertthing-at-point
you can refer to with-emacs.com/posts/ui-hacks/execute-commands-like-marty-mcfly and github.com/seagle0128/.emacs.d/blob/master/lisp/… Feb 18, 2022 at 8:48 -
@TianshuWang: you should look up the
r
specification for theinteractive
form.– NickDFeb 18, 2022 at 20:53 -
M-s
M-w
&