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

counsel-imenu: jump to definition on candidate select #2188

Closed
sojitko opened this issue Aug 8, 2019 · 12 comments
Closed

counsel-imenu: jump to definition on candidate select #2188

sojitko opened this issue Aug 8, 2019 · 12 comments

Comments

@sojitko
Copy link
Contributor

@sojitko sojitko commented Aug 8, 2019

With swiper, selecting a candidate temporarily moves buffer to its location for a preview.
counsel-imenu which shares the same interface does not have this behavior.

Updating buffer location on candidate selection is very valuable as it gives context while searching desired target.
counsel-imenu users would benefit with it.

Does anyone have an idea if that would be easy to implement and maybe give some tips?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Aug 21, 2019

You can press C-M-n in place of C-n to move. This applies to any Ivy commands.

@sojitko
Copy link
Contributor Author

@sojitko sojitko commented Sep 8, 2019

The behavior I have in mind is moving anytime new candidate is selected, just as in swiper.

@abo-abo abo-abo closed this in 2b974b4 Oct 11, 2019
@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Oct 11, 2019

Thanks. You can now configure:

(ivy-configure 'counsel-imenu
  :update-fn 'auto)

@manuel-uberti
Copy link
Contributor

@manuel-uberti manuel-uberti commented Oct 12, 2019

Doesn't seem to work on my init.el:

Error in post-command-hook (ivy--queue-exhibit): (wrong-type-argument listp #("Variables: mu-initial-file-name-handler-alist" 0 9 (idx 0 face ivy-grep-info) 9 45 (idx 0)))

abo-abo added a commit that referenced this issue Oct 12, 2019
* counsel.el (counsel--imenu-candidates): Extract.
(counsel-imenu-get-candidates-from): Return a proper alist.
(counsel-imenu-action): Simplify.

* ivy.el (ivy-read): Detect alist for :update-fn 'auto.

Fixes #2188
@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Oct 12, 2019

@manuel-uberti Thanks, please test.

@manuel-uberti
Copy link
Contributor

@manuel-uberti manuel-uberti commented Oct 12, 2019

A different error this time. counsel-imenu starts, but as soon as I start typing I get:

Error in post-command-hook (ivy--queue-exhibit): (wrong-type-argument integer-or-marker-p nil)

abo-abo added a commit that referenced this issue Oct 12, 2019
In case there is no match, and :update-fn is 'auto, it will call the
action with nil.

The action is called with nil, so that functions like
`swiper-isearch-action` can clean up.

Re #2188
@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Oct 12, 2019

@manuel-uberti Thanks again. Please test. Again :)

@manuel-uberti
Copy link
Contributor

@manuel-uberti manuel-uberti commented Oct 12, 2019

No error this time, but there is no movement in the buffer when I move between candidates unless I select one of them. I mean, it is behaving like it was behaving before, but I think OP wanted a sort of live movement similar to Swiper/Isearch.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Oct 12, 2019

@manuel-uberti Did you do this config?

(ivy-configure 'counsel-imenu
  :update-fn 'auto)

It's not on by default.

@manuel-uberti
Copy link
Contributor

@manuel-uberti manuel-uberti commented Oct 12, 2019

Had to restart Emacs. Now it is working. Fantastic, thank you!

@atanasj
Copy link

@atanasj atanasj commented Jan 30, 2020

I know this issues is closed, but where do I add the below to my config?

(ivy-configure 'counsel-imenu
  :update-fn 'auto)

I tried to just paste it in, or add it in but I get an error and it wont load it... Any help is greatly appreciated. Thanks in advance.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Feb 7, 2020

@atanasj I've just tested and the code still works. Here's what I did:

In this repo, add this code to targets/plain.el:

(ivy-configure 'counsel-imenu
  :update-fn 'auto)
(global-set-key (kbd "C-c i") 'counsel-imenu)

Run make plain. Open e.g. ivy.el and C-c i C-n. Works as expected.

astoff added a commit to astoff/swiper that referenced this issue Jan 1, 2021
astoff added a commit to astoff/swiper that referenced this issue Jan 1, 2021
* counsel.el (counsel--imenu-candidates): Extract.
(counsel-imenu-get-candidates-from): Return a proper alist.
(counsel-imenu-action): Simplify.

* ivy.el (ivy-read): Detect alist for :update-fn 'auto.

Fixes abo-abo#2188
astoff added a commit to astoff/swiper that referenced this issue Jan 1, 2021
In case there is no match, and :update-fn is 'auto, it will call the
action with nil.

The action is called with nil, so that functions like
`swiper-isearch-action` can clean up.

Re abo-abo#2188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants