Company-Mode

You can use company-mode as an autocompletion framework. It's a front-end that comes with backends to add completion in a variety of programming languages.


(use-package company
:pin melpa-stable
:commands (company-mode company-complete company-complete-common company-complete-selection helm-company)
:init
(setq company-minimum-prefix-length 3
      company-require-match nil
      company-selection-wrap-around t
      company-dabbrev-downcase t
      company-tooltip-limit 20; bigger popup window
	  company-tooltip-minimum-width 15
      company-tooltip-align-annotations t; align annotations to the right tooltip border
      company-eclim-auto-save nil
);end setqs
(eval-after-load 'company
'(add-to-list 'company-backends '(company-ispell  company-yasnippet company-abbrev company-dabbrev company-capf)))
:config
;dropdown by default = 0, no dropdown =1
(setq company-idle-delay 1000)
;(setq company-tooltip-idle-delay 0.1)
(setq company-minimum-prefix-length 3)
;(setq company-auto-complete t)
(setq company-ispell-dictionary  comp-ispell-dic-p )
(defun jcs--company-complete-selection--advice-around (fn)
    "Advice execute around `company-complete-selection' command."
    (let ((company-dabbrev-downcase t))
      (call-interactively fn)))
  (advice-add 'company-complete-selection :around #'jcs--company-complete-selection--advice-around)
(with-eval-after-load 'company
(define-key company-active-map (kbd "C-n") 'company-select-next)
(define-key company-active-map (kbd "C-p") 'company-select-previous)
);end set-keys
;orgmode has completion, enable company completion to work also with org
(defun add-pcomplete-to-capf ()
  (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
(add-hook 'org-mode-hook #'add-pcomplete-to-capf)
;some other company edits completions
;(setq-local completion-ignore-case t)
;(company-dabbrev-code-ignore-case t)
(setq company-dabbrev-ignore-case nil)
;(company-etags-ignore-case t)
; no ispell on certain modes
;(setq company-global-modes'(not eshell-mode comint-mode erc-mode  ;minibuffer-inactive-mode))
;bind below to tab, if company on manual begin uses tab, otherwise company
(defun complete-or-indent ()
    (interactive)
    (if (company-manual-begin)
        (company-complete-common)
      (indent-according-to-mode)))
;a piece of code that will allow yasnippet completion expansion if company did not complete
;; With this code, yasnippet will expand the snippet if company didn't complete the word. Another thing to remember is to
;; replace company-complete-common with company-complete if you're using it
(advice-add 'company-complete :before (lambda () (setq my-company-point (point))))
(advice-add 'company-complete :after (lambda ()
(when (equal my-company-point (point))
  			  			  (yas-expand))))
(global-company-mode)
:bind (
("C-t"   . company-complete);
;("C-c f" . company-files)
;("C-c a" . company-dabbrev)
;("C-c d" . company-ispell)
(:map company-active-map
("C-n"    . company-select-next)
("C-p"    . company-select-previous)
([return] . company-complete-selection)
("C-w"    . backward-kill-word)
("C-g"    . company-abort)
("C-c"    . company-search-abort)
("<tab>"  . complete-or-indent)
("C-s"  . company-search-candidates)
("C-o" . company-search-toggle-filtering)
));end bind
);end use-package company

On/Off

You can set company-idle-delay to a high number if you don't want to use it.



(defun toggle-company-idle-delay ()
"Stops or starts company auto-popup feature by setting delay to a few hours or zero."
(interactive)
(if (featurep 'company)
(if (= company-idle-delay 0.1)
    (setq company-idle-delay 10000)
    (setq company-idle-delay 0.1))));
;stops or starts company auto-complete-inserts wrong word on space for text-modes, great though for programming modes

(defun toggle-company-auto-complete ()
"Stops or starts company auto-complete."
(interactive)
(if (featurep 'company)
(if ( = company-auto-complete 1)
    (setq company-auto-complete nil)
    (setq company-auto-complete 1))));

Company Backends


Backends are dictionaries company searches to suggest words to complete the phrase you started typing.

You can set the order of the backends to change the completion suggestions.

(eval-after-load ‘company
’(add-to-list ‘company-backends ‘(company-ispell company-yasnippet company-abbrev company-dabbrev company-capf)))


Company Tryhard


You can use company-try-hard to choose a backend for you.



(use-package company-try-hard
:config
(global-set-key (kbd "C-l") 'company-try-hard)
(define-key company-active-map (kbd "C-l") 'company-try-hard)
);company-try-hard
;php-extras from 2014

PHP-Extras


(use-package php-extras
:commands (php-mode company-php)
);php-extras
;ac-php , as company backend

AC-PHP

You can use ac-php and ac-php-core-eldoc-setup to display PHP info in the mini-buffer when cursor is over a php function.


(use-package ac-php
:after (auto-complete yasnippet company php-mode)
:commands (php-mode company-php)
:config
(ac-php-core-eldoc-setup)
;ac-source-php
;:hook (php-mode . ac-php-mode)
);ac-php

Company-PHP

You can add a PHP backend.



;company-php


(use-package company-php
:after (company php-mode)
:commands (php-mode company-php)
:config
(set (make-local-variable 'company-backends)
'((
company-ac-php-backend
php-extras-company
ac-php
company-dabbrev-code
)));end add to backends
;ac-php-find-symbol-at-point
(local-set-key (kbd "M-.") #'ac-php-find-symbol-at-point)
);end company-php

Company-Yasnippet

You can add a Yasnippet backend.


;company-yasnippet

(use-package company-yasnippet
:load-path company-yasnippet-p
:init
(require 'company-yasnippet)
:commands (company-mode yas-minor-mode )
);company-yasnippet

Company-Mode/Enable-Yas


(defvar company-mode/enable-yas t
  "Enable yasnippet for all backends.")
(defun company-mode/backend-with-yas (backend)
  (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
      backend
    (append (if (consp backend) backend (list backend))
            '(:with company-yasnippet))))
(setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))

Company-Fuzzy

With company-fuzzy you get fuzzy matching.



;company fuzzy matching combines all backends for buffer into one selection narrowed as you type prefix
(use-package company-fuzzy
:after company
:commands company-fuzzy-mode
:config
(setq company-fuzzy-sorting-backend 'alphabetic)
(setq company-fuzzy-prefix-ontop t)
(setq company-fuzzy-show-annotation t)
;backends without prefixes for completion need this
(add-to-list 'company-fuzzy--no-prefix-backends 'company-yasnippet)
);;end company-fuzzy
;to enable in any give mode add to that modes company-backend hooks
;(company-fuzzy-mode 1)
;; helm-company choose from company completions with C-:

Helm-Company

If you still use helm, you can get completion in the mini-buffer.


(use-package helm-company
;load-path "path to helm-company.el"
:commands helm-company
);end helm-company

Define Keys



;define key helm-company

(with-eval-after-load 'company
  (define-key company-mode-map (kbd "C-:") 'helm-company)
  (define-key company-active-map (kbd "C-:") 'helm-company))
;company quick-help

Company-Quickhelp


(use-package company-quickhelp
:after (company pos-tip)
:commands (company-quickhelp-mode company-quickhelp-manual-begin)
;:config
;(setq company-quickhelp-delay nil)
;(eval-after-load 'company
;  '(define-key company-active-map (kbd "M-h") ;'company-quickhelp-manual-begin))
);end company-quickhelp