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-at-point for generic completion at point #331

Closed
ghost opened this issue Dec 27, 2015 · 13 comments
Closed

counsel-at-point for generic completion at point #331

ghost opened this issue Dec 27, 2015 · 13 comments

Comments

@ghost
Copy link

ghost commented Dec 27, 2015

I reconstituted these snippets from your dotfiles. Are these right?

(require 'python)
(define-key python-mode-map (kbd "C-M-i") 'counsel-jedi)
(require 'lisp-mode)
(define-key lisp-mode-map (kbd "C-M-i") 'counsel-cl)
(require 'clojure-mode)
(define-key clojure-mode-map (kbd "C-M-i") 'counsel-clj)
(define-key lisp-mode-shared-map "C-M-i" 'counsel-el)
;; or maybe
(define-key emacs-lisp-mode-map "C-M-i" 'counsel-el)

And maybe as well

(define-key org-mode-map (kbd "C-c C-q") 'counsel-org-tag)

Such snippets could either be added to the wiki or the readme snippet. But what would be really great would be a generic completion method, like ido-at-point, which would complete symbol at point with ivy using built-in completion system or the counsel-* completions functions if dependencies are available.

It may not require much changes to this package, since using it and re-defining this function worked for me:

(defun ido-at-point-read (comps common)
  (completing-read "" comps nil t common))

(ido-at-point-mode 1)

ivy-completing-read worked as well.

Thank you for your attention and awesome completion system!

[EDIT] Oh, and no hurry of course, this is a suggestion and not a request!

@abo-abo
Copy link
Owner

abo-abo commented Dec 27, 2015

Thanks, I'll work on this in the future. I've been meaning to write a completion-in-region-function for some time now.

@ghost
Copy link
Author

ghost commented Dec 27, 2015

Glad to hear it! Closing the issue for now.

@ghost ghost closed this as completed Dec 27, 2015
abo-abo added a commit that referenced this issue Jan 5, 2016
* ivy.el (ivy-completion-beg): Rename from `counsel-completion-beg'.
(ivy-completion-end): Rename from `counsel-completion-end'.
(ivy-completion-in-region-action): Rename from `counsel--el-action'.
(ivy-completion-in-region): New defun.
(ivy-mode): Set `completing-read-function' to 'ivy-completion-in-region.

* counsel.el: Update due to renames.

Fixes #331
@abo-abo
Copy link
Owner

abo-abo commented Jan 5, 2016

OK, ivy-mode now does in addition what ido-at-point does.

So counsel-el can be replaced with completion-at-point when ivy-mode is active.

However, I haven't yet figured out how to hook e.g. counsel-jedi into completion-at-point. Probably it should be the responsibility of (jedi:setup).

@ghost
Copy link
Author

ghost commented Jan 5, 2016

Oh, that is great news, thank you!
Ivy is amazing: with 20 more lines, I can remove a package!

I do not know how jedi is usually integrated with complenion systems.

Maybe company and autocomplete implementations could help.

Both seems to use jedi-core as a basis.

Maybe you have seen all of this already.

@ghost
Copy link
Author

ghost commented Jan 5, 2016

Yes, by looking at the sources, you are already aware of it! ^^

@s-kostyaev
Copy link

What do you think about counsel-company? Counsel may be very good frontend for company like helm-company.

abo-abo added a commit that referenced this issue May 24, 2016
@abo-abo
Copy link
Owner

abo-abo commented May 24, 2016

@s-kostyaev Have a look.

@s-kostyaev
Copy link

@abo-abo Thanks. Looks good. Can you also add action for showing docs for candidates? I don't know how it works in company, but helm-company can't do this. Wait for new melpa build.

@s-kostyaev
Copy link

@abo-abo for me very useful something like this:

(defun counsel-company ()
  "Complete using `company-candidates'."
  (interactive)
  (unless company-candidates
    (company-complete))
  (when company-point
    (company-complete-common)
    (when (looking-back company-common (line-beginning-position))
      (setq ivy-completion-beg (match-beginning 0))
      (setq ivy-completion-end (match-end 0)))
    (ivy-read "company cand: " (mapcar (lambda (x)
                                         (concat
                                          x
                                          "\t\t"
                                          (company-call-backend 'annotation x)))
                                       company-candidates)
              :action (lambda (x)
                        (ivy-completion-in-region-action
                         (replace-regexp-in-string "\t\t\.*" "" x))
                        (run-at-time 0.01 nil 'company-pseudo-tooltip-hide)))))

But I think that annotation should have another face. May be need some defcustom for customize that.

@s-kostyaev
Copy link

s-kostyaev commented May 25, 2016

I think adding annotations (with correct face) must be done by transformer, but my transformer does not work for now:

(defun counsel-company-transformer (str)
  "Add highlighted annotation into STR."
  (let ((annotation (company-call-backend 'annotation str))
    (set-text-properties 1 (length annotation) '(face success) annotation)
    (concat str "\t\t" annotation))))

(ivy-set-display-transformer 'counsel-company 'counsel-company-transformer)

@abo-abo
Copy link
Owner

abo-abo commented May 25, 2016

@s-kostyaev Could you please open a new issue with the above two code snippets? I don't have time right now to deal with them, but I don't want to forget about it. An open issue helps to track it, but I don't want to re-open this one.

@s-kostyaev
Copy link

@abo-abo done.

@NightMachinery
Copy link

@s-kostyaev Where is the new issue you opened about showing docs with counsel-company?

This issue was closed.
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

3 participants