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

IDO/helm support for apropos #1541

Closed
martintrojer opened this issue Feb 4, 2016 · 15 comments
Closed

IDO/helm support for apropos #1541

martintrojer opened this issue Feb 4, 2016 · 15 comments

Comments

@martintrojer
Copy link

Scenario; looking for a function somewhere in the codebase. All I have is the name.

M-x cider-apropos does what I want, but I would prefer the results to feed ido/helm as I am typing. Then when a var is selected, a buffer is opened at the correct line.

Also discussed here #1059

@bbatsov
Copy link
Member

bbatsov commented Feb 4, 2016

Yeah, we should cook something like this. Btw, you can add different action keys to ido so there can be options to go to the source, view the doc, conj.io, etc.

We'll implement something using completing-read and the apropos results and people will be able to pick by themselves what completion system is used.

@xiongtx
Copy link
Member

xiongtx commented Feb 10, 2016

Proof of concept for cider-apropos using Helm:

(require 'cider-apropos)

(defun cider-def-source--apropos (query)
  (helm-build-sync-source (concat "CIDER apropos: '" query "'")
    :action '(("Lookup doc" . cider-doc-lookup))
    :candidates (mapcar (lambda (dict)
                          (nrepl-dbind-response dict (name type doc)
                            (let* ((label (capitalize (if (string= type "variable") "var" type)))
                                   (help (concat "Display doc for this " (downcase label))))
                              (with-temp-buffer                                
                                (cider-propertize-region (list 'apropos-symbol name
                                                               'action 'cider-apropos-doc
                                                               'help-echo help)
                                  (insert-text-button name 'type 'apropos-symbol)
                                  (insert "\n") 
                                  (insert-text-button label 'type (intern (concat "apropos-" type)))
                                  (insert ": ") 
                                  (let ((beg (point)))
                                    (insert doc "\n")
                                    (fill-region beg (point-max)))) 
                                (cons (buffer-string)
                                      name)))))
                        (cider-sync-request:apropos query))
    :multiline t))

(helm :sources (cider-def-source--apropos "def")
      :buffer "*Helm CIDER apropos*")

Tip: Turn on helm-follow-mode with C-c C-f to quickly view documentation as you move through the list of candidates.

Other actions (e.g. cider-grimoire-lookup) can be easily added.

What I don't understand is how "jumping to source" works. I've love to have that as an action, but cider-docview-source is hard to grok. Would it be possible to have a function that takes a name like clojure.core/defn and jump to the source file?

@bbatsov
Copy link
Member

bbatsov commented Mar 2, 2016

Would it be possible to have a function that takes a name like clojure.core/defn and jump to the source file?

It already exists - cider-find-var.

bbatsov added a commit that referenced this issue Mar 20, 2016
Basically instead of seeing the results in a dedicated buffer, you'll
now see them in the minibuffer.
@bbatsov
Copy link
Member

bbatsov commented Mar 20, 2016

I've just added a couple of new commands - cider-apropos-select and cider-apropos-documentation-select. Play with them and let me know what you think.

@martintrojer
Copy link
Author

This works great.

One suggestion, I'd love to give a default selection for cider-apropos-act-on-symbol. In my case find-def.

@bbatsov
Copy link
Member

bbatsov commented Mar 31, 2016

One suggestion, I'd love to give a default selection for cider-apropos-act-on-symbol. In my case find-def.

File another issue about this and I'll look into it.

@martintrojer
Copy link
Author

#1646

@bbatsov bbatsov closed this as completed Apr 2, 2016
@xiongtx
Copy link
Member

xiongtx commented Apr 18, 2016

Isn't cider-apropos-documentation-select exactly the same as cider-apropos-documentation?

Below is cider-apropos-documentation-select:

(defun cider-apropos-documentation-select ()
  "Shortcut for (cider-apropos-select <query> nil t)."
  (interactive)
  (cider-ensure-connected)
  (cider-ensure-op-supported "apropos")
  (cider-apropos (read-string "Search for Clojure documentation (a regular expression): ") nil t))

And cider-apropos-documentation:

(defun cider-apropos-documentation ()
  "Shortcut for (cider-apropos <query> nil t)."
  (interactive)
  (cider-ensure-connected)
  (cider-ensure-op-supported "apropos")
  (cider-apropos (read-string "Search for Clojure documentation (a regular expression): ") nil t))

@bbatsov
Copy link
Member

bbatsov commented Apr 19, 2016

Ops. I've made a silly copy-paste mistake. I've just fixed it.

Thanks for bringing this up!

@xiongtx
Copy link
Member

xiongtx commented Apr 21, 2016

@martintrojer Can you try out Helm CIDER? This issue was the motivation this (not-yet-released) package, and Helm CIDER apropos is the first feature.

@martintrojer
Copy link
Author

I tested it with IDO and it worked fine.

@xiongtx
Copy link
Member

xiongtx commented Apr 22, 2016

Tested what with Ido? I don't use Ido, so I don't know its features.

@martintrojer
Copy link
Author

its a "completing" solution similar to helm. Both should work since the new cider function uses completing-read

@xiongtx
Copy link
Member

xiongtx commented Apr 22, 2016

No, I meant try the new package I'm working on (not yet released).

@arichiardi
Copy link
Contributor

@xiongtx using your package, very slick thank you! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants