Liuw's Thinkpad

想要赢就先学会输,想要成功就先学会失败

Fast Configuration of Company Mode

without comments

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.

Written by liuw

January 12th, 2010 at 7:38 pm

Posted in UNIX-like,分享

Tagged with ,

Leave a Reply

*