Skip to content

Add support for multiple cursors to counsel-company #547

@s-kostyaev

Description

@s-kostyaev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions