Skip to content
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 · 9 comments
Closed

Comments

@zzhjerry
Copy link

@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
Copy link
Owner

@abo-abo 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
Copy link

@mtuzinskiy 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
Copy link
Owner

@abo-abo 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
Copy link

@mtuzinskiy 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
Copy link
Owner

@abo-abo abo-abo commented Jul 26, 2017

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

@wykurz
Copy link

@wykurz wykurz commented Nov 29, 2020

This was working great for me until recently. Now running swiper-thing-at-point has an unfortunate side-effect of going to the last element found (rather than sticking to the one nearest to the cursor, as C-s M-n would.

@abo-abo do you have any suggestions what may be going on?

Thanks!

@basil-conto
Copy link
Collaborator

@basil-conto basil-conto commented Nov 29, 2020

@wykurz If this is something you can reliably reproduce, please submit a bug report with a reproduction recipe. TIA.

@wykurz
Copy link

@wykurz wykurz commented Dec 1, 2020

Yes, it's 100% reproducible. Created this: #2737

@wykurz
Copy link

@wykurz wykurz commented Dec 3, 2020

For others trying to use this - swiper-thing-at-point is now defined in swiper.el itself. So to use it just create a key binding like:

(global-set-key (kbd "M-s") 'swiper-thing-at-point)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.