New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to search for the thing under the cursor with just one key binding? #1068

Closed
zzhjerry opened this Issue Jun 13, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@zzhjerry

zzhjerry commented Jun 13, 2017

I know C-s C-w or C-s M-n could do it. But I wonder if this can be done with just 1 key binding.

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Jun 14, 2017

There's no option to do this. But it's easy to write some custom code. I can give an example if you need it.

@mtuzinskiy

This comment has been minimized.

mtuzinskiy commented Jul 26, 2017

@abo-abo Yes, could you please give an example?
I would like to implement the SPC-* functionality from the Spacemacs, i.e. when pressing SPC-* on any word, it performs a project-wide search.

I mapped the SPC-* to

(progn
    (counsel-projectile-ag)
    (ivy-next-history-element)))

But it doesn't work. I'm new to elisp. Please help.
P.S. Thank you for the great Ivy!

@abo-abo abo-abo closed this in 714f9f8 Jul 26, 2017

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Jul 26, 2017

Here's a code that you could use:

(defun ivy-with-thing-at-point (cmd)
  (let ((ivy-initial-inputs-alist
         (list
          (cons cmd (thing-at-point 'symbol)))))
    (funcall cmd)))

;; Example 1
(defun counsel-ag-thing-at-point ()
  (interactive)
  (ivy-with-thing-at-point 'counsel-ag))

;; Example 2
(defun swiper-thing-at-point ()
  (interactive)
  (ivy-with-thing-at-point 'swiper))
@mtuzinskiy

This comment has been minimized.

mtuzinskiy commented Jul 26, 2017

@abo-abo tried it, doesn't work. The thing is that, unlike Swiper, the counsel-ag has no :inital-value argument (as well as counsel-projectile-ag). What to do?

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Jul 26, 2017

@mtuzinskiy You should update the package from Git, or wait a few hours and update from MELPA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment