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
josuah opened this Issue Dec 27, 2015 · 12 comments

Comments

Projects
None yet
3 participants
@josuah

josuah 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

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Dec 27, 2015

Owner

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

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.

@josuah

This comment has been minimized.

Show comment
Hide comment
@josuah

josuah Dec 27, 2015

Glad to hear it! Closing the issue for now.

josuah commented Dec 27, 2015

Glad to hear it! Closing the issue for now.

@josuah josuah closed this Dec 27, 2015

abo-abo added a commit that referenced this issue Jan 5, 2016

ivy.el (ivy-mode): Set completing-read-function
* 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

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jan 5, 2016

Owner

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).

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).

@josuah

This comment has been minimized.

Show comment
Hide comment
@josuah

josuah 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.

josuah 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.

@josuah

This comment has been minimized.

Show comment
Hide comment
@josuah

josuah Jan 5, 2016

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

josuah commented Jan 5, 2016

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

@s-kostyaev

This comment has been minimized.

Show comment
Hide comment
@s-kostyaev

s-kostyaev May 24, 2016

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

s-kostyaev commented May 24, 2016

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

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo May 24, 2016

Owner

@s-kostyaev Have a look.

Owner

abo-abo commented May 24, 2016

@s-kostyaev Have a look.

@s-kostyaev

This comment has been minimized.

Show comment
Hide comment
@s-kostyaev

s-kostyaev May 24, 2016

@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 commented May 24, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@s-kostyaev

s-kostyaev May 25, 2016

@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 commented May 25, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@s-kostyaev

s-kostyaev 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)

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

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo May 25, 2016

Owner

@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.

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

This comment has been minimized.

Show comment
Hide comment

s-kostyaev commented May 25, 2016

@abo-abo done.

@Sarcasm Sarcasm referenced this issue Apr 27, 2017

Closed

iotask: request for testing #376

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