Fast Configuration of Company Mode
http://nschum.de/src/emacs/company-mode/
Add following lines to dotemacs.
(add-to-list 'load-path "/path/to/company")
(autoload 'company-mode "company" nil t)
;; Add hook for file types.
(add-hook 'c-mode-hook (lambda() (company-mode)))
;; Bind company-manual-begin, company-complete-common, company-complete,
;; company-select-next to a key in the global map.
(global-set-key "\t" 'company-complete-common)
;; Alternatively, set company-idle-delay to t, so it will complete immediately.
;; Helper functions
(defun complete-or-indent ()
(interactive)
(if (company-manual-begin)
(company-complete-common)
(indent-according-to-mode)))
(defun indent-or-complete ()
(interactive)
(if (looking-at "\\_>")
(company-complete-common)
(indent-according-to-mode)))
Since I would like to use TAB for both completion and indentation, I prefer the following helper function to make life easier – company will mess up TAB key when in minibuffer.
(defun tab-complete-or-indent ()
(interactive)
(if (minibufferp)
(minibuffer-complete)
(if (company-manual-begin)
(company-complete-common)
(indent-according-to-mode))
)
)
(global-set-key [tab] 'tab-complete-or-indent)
Currently, I’m using the following configuration.
(add-hook 'c-mode-hook (lambda() (company-mode))) (add-hook 'lisp-mode-hook (lambda() (company-mode))) (add-hook 'emacs-lisp-mode-hook (lambda() (company-mode))) (setq company-begin-commands '(self-insert-command)) (setq company-idle-delay t) (setq company-minimum-prefix-length 1)
© 2010, liuw. All rights reserved.