After some research, I came across the company mode git hub ticket,
which says that company mode uses dabbrev for plain text as backend.
dabbrev has an option to downcase things, it is turned on by default but can be turned off:
(setq company-dabbrev-downcase nil)
Now all is well.
They're pretty much equivalent, but company-mode has a better thought-out API for plugin developers. It's also much more actively maintained. But there are two key differences which may or may not matter to you:
Firstly, company-mode now targets Emacs 24, so if you're stuck with Emacs 23 then you're out of luck. auto-complete still works with Emacs 23.
I have the following snippet in my configuration and it seems like it's exactly what you want:
;; Add yasnippet support for all company backends
(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) (...
I've used autocomplete-mode for a good a few years and switched to company-mode a couple of months ago.
In basic usage there's not much of a difference. Like someone else posted this link has a good summary of the differences.
I found company-mode to be easier to configure and to let it do what I want it to. With autocomplete-mode I ran into issues now and ...
Here is how completion in company works (I am simplifying a bit; a more detailed description can be found in documentation of company-backends C-hvcompany-backendsRET.
You have a list of backends (completion engines) which company should try to provide completion at point. Company tries each of these backends one after the another, and the first one that ...
This is what I created for myself, facing the same issue. It is from company-mode's Emacs Wiki page, but heavily extended:
(defun check-expansion ()
(if (looking-at "\\_>") t
(if (looking-at "\\.") t
(if (looking-at "->") t nil)))))
(defun do-yas-expand ()
Emacs's builtin completion functionality offers similar fuzzy matching (tho by default it's used for "do-so-am" rather than for "DoSoAm") and IIUC recent versions of company-mode do use this at least in some cases.
E.g. if you open an Elisp buffer using Emacs-24.4 and the latest company-mode, if you type (wi-sy company will pop up a completion menu showing ...
You can set company-minimum-prefix-length to a desire value of your choice:
(setq company-minimum-prefix-length 2)
You can use the customize interface M-x customize and search for company in there using the search box. It will list relevant options related to the package. You can also search for a variable with C-h v or search for a command with C-h a, ...
As @Jesse already pointed out, what you want here is the company-files backend. There are several different ways to use it:
Bind a key to call company-files directly.
Use command company-begin-backend. This prompts you for the backend to use, then offers completion candidates.
Use company-other-backend to rotate through the list of backends (see next item)...
You can set a default company-backends, then use hook to append different backends to different mode.
Here is a way I config in my emacs.
;; set default `company-backends'
'((company-files ; files & directory
company-keywords ; keywords
FYI, some modes open only one inferior processs. For example, run-python will open an inferior process only if there isn't already an inferior process running. What you suggested with run-python actually does what you want.
For other modes (Matlab?), you could use a function that unhooks itself, like so:
(defun run-python-once ()
I had also a bad experience with company at the beginning, but in my setup I just put these lines.
(setq company-dabbrev-downcase 0)
(setq company-idle-delay 0)
The first variable is used to skip the downcase that company does to the variables I autocomplete, the second one I think you already have.
(defun tab-indent-or-complete ()
This is defined in company-active-map. You can unbind the return key in that map:
(define-key company-active-map (kbd "<return>") nil)
Note however that return and tab do different things when there are multiple candidates. Tab is bound to company-complete-common, while return is bound to company-complete-selection. If you unbind the return key then ...
Here's the code that I'm using:
(global-set-key "\C-o" 'aya-open-line)
(defun aya-open-line ()
"Call `open-line', unless there are abbrevs or snippets at point.
In that case expand them. If there's a snippet expansion in progress,
move to the next field. Call `open-line' if nothing else applies."
You've configured company-mode to load after your init file is evaluated using the after-init-hook, but are then trying to modify company-backends right away.
That variable isn't defined until company-mode is loaded. You either need to just require company, or defer setting that variable using eval-after-load:
My complete setup for fixing this annoying default behavior is:
;;; Prevent suggestions from being triggered automatically. In particular,
;;; this makes it so that:
;;; - TAB will always complete the current selection.
;;; - RET will only complete the current selection if the user has explicitly
;;; interacted with Company.
;;; - SPC will ...
I don't see a way built in to company-mode to do this, but you can add your own key binding to company-active-map.
As a quick experiment I took the company-show-doc-buffer implementation and simply removed the company--electric-do wrapper:
(defun my/company-show-doc-buffer ()
"Temporarily show the documentation buffer for the selection."
This can be solved by modifying company-transformers with the following code:
(push (apply-partially #'cl-remove-if
(or (string-match-p "[^\x00-\x7F]+" c)
(string-match-p "[0-9]+" c)
(if (equal major-mode "org")
company-mode does not rebind C-n or C-p probably to minimize interference with normal editing commands. To cycle through options, Company uses up, down, M-n, and M-p by default.
Use C-h f company-mode to peruse the mode specific documentation for Company. It will show the available bindings for the company popup when it is active.
However if you do want C-...
company-mode has company-capf. So the easiest way is adding pcomplete-completions-at-point to completion-at-point-functions:
(defun my-org-mode-hook ()
(add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
(add-hook 'org-mode-hook #'my-org-mode-hook)
Make sure company-capf is in the list of company-backends.
With company-mode, you can use C-s to search from available candidates that it display. The search query is displayed in the modeline (not really easy to spot, I know. I filed an issue here).
If you want to use Helm for completion, consider using helm-company or ac-helm. Haven't tried with ac-helm, but with helm-company, you can directly bind it to a key to ...
You have to run company-files for file completion. You can bind a different map for the files completion completion with
(define-key global-map (kbd "C-.") 'company-files)
Also make sure you have the company-files in company-backends (M-x > customize-group > company > company backends)
Unless you invoke one of the completion commands directly (such as M-x company-complete-common), the completion maybe-happens and the popup is rendered in company-post-command.
It looks at the current command, sees if it satisfies the value of company-begin-commands, and calls company--perform.
The latter looks at the buffer contents, and checks whether ...
OP here, my clang executable wasn't being recognized by company-clang because the name of the executable in my /usr/bin was clang-3.5 and not clang.
Using M-x customize-variable RET company-clang-executable RET as @elethan suggested and setting the absolute path to the clang executable didn't resolve the problem.
Above suggested that company-clang was ...
I read about Change Minor Mode Keys in the fantastic Xah Lee pages.
And I think I came with a solution.
I found two different keymaps in company.el: company-active-map and company-search-map.
So I redefined its default keybinding definitions that best suits my needs:
(define-key company-active-map (kbd "C-n") 'company-select-next)