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

Add support for multiple cursors to counsel-company #547

Closed
s-kostyaev opened this issue Jun 10, 2016 · 8 comments
Closed

Add support for multiple cursors to counsel-company #547

s-kostyaev opened this issue Jun 10, 2016 · 8 comments

Comments

@s-kostyaev
Copy link

s-kostyaev commented Jun 10, 2016

Multiple cursors are great. But with this package does not work any autocompletion. I fix it for counsel-company. I can do PR for this feature, but you can do my code better I think. This is working code:

(defvar-local my-counsel-company-prefix nil
  "Company prefix for use counsel-company with multiple-cursors.")
(defun my-counsel-company ()
  "Complete using `company-candidates'."
  (interactive)
  (company-mode 1)
  (company-cancel)
  (unless company-candidates
    (company-complete))
  (when company-point
    (setq my-counsel-company-prefix company-prefix)
    (company--fetch-candidates my-counsel-company-prefix)
    (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)
                                         (let ((annotation
                                                (company-call-backend 'annotation x)))
                                           (if (> (length annotation) 0)
                                               (progn
                                                 (set-text-properties
                                                  0 (length annotation)
                                                  '(face success) annotation)
                                                 (concat x "\t\t" annotation))
                                             x)))
                                       company-candidates)
              :action (lambda (x)
                        (company-cancel)
                        (ivy-completion-in-region-action
                         (replace-regexp-in-string "\t\t\.*" "" x))
                        (let
                            ((insertion (s-chop-prefix my-counsel-company-prefix
                                                       (replace-regexp-in-string "\t\t\.*" "" x))))
                          (mc/execute-command-for-all-fake-cursors
                           (lambda ()
                             (interactive)
                             (insert insertion))))))))
@s-kostyaev
Copy link
Author

This code also include annotations from #523

@abo-abo
Copy link
Owner

abo-abo commented Jun 10, 2016

I don't get it, what is it supposed to do with multiple-cursors? Also, I can't get the annotations to work either.

@s-kostyaev
Copy link
Author

s-kostyaev commented Jun 10, 2016

what is it supposed to do with multiple-cursors?

Insert completion for all cursors.

I can't get the annotations to work either.

Try it with irony-mode for example. Not all backends add annotations.

@s-kostyaev
Copy link
Author

mc-completion

@abo-abo
Copy link
Owner

abo-abo commented Jun 12, 2016

I've added a more generic solution to ivy-completion-in-region-action. So C-M-i (complete-symbol) should work fine with multiple-cursors. Since counsel-company uses the same function, it should also work. Please test.

@s-kostyaev
Copy link
Author

s-kostyaev commented Jun 12, 2016

Add (mc/enable-minor-mode 'company-mode) at counsel-company begining please. complete-symbol work with multiple cursors but I think that more correct select candidate once and insert it for all cursors. Also counsel-company not work with multiple cursors even after enabling company-mode for mc. It insert candidate only for original cursor.

@s-kostyaev
Copy link
Author

@abo-abo consel-company still broken. I can create PR with working code or create small melpa package ivy-company if you wontfix it.

@abo-abo
Copy link
Owner

abo-abo commented Jun 14, 2016

Seems to work fine for me. Let's try with the PR. But the package is fine as well, if you prefer.

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

2 participants