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). This can be used to trigger completion or it can be used after company mode has been triggered to switch to a different set of completion candidates. You may want to assign a key binding in the company map, e.g. (define-key company-active-map (kbd "C-e") #'company-other-backend)
Configure the variable company-backends
. Company mode traverses this list in order to find a backend that accepts the current prefix (i.e. the text before point). It is entirely possible to have a backend in the list that accepts the current prefix but does not offer any completion candidates, at which point company mode won't auto-complete anything. You can customize the list to order the backends in a way that meets your needs.
A few examples of modifying company-backends
:
If you only ever wanted to complete filenames, you could make that your only backend:
(setq company-backends '(company-files))
That seems unlikely, so you're better off putting your most commonly used backend first and then using one of options mentioned earlier to switch backends or invoke one by name when you need something else.
You can also configure a 'group' backend that creates a merged set of completion candidates. Try this, for example:
(setq company-backends '((company-capf company-dabbrev-code company-files)))
This specifies a single backend that merges the candidates from three other backends. It will give you results from completion-at-point, dabbrev, and the file system.
You can use mode hooks to specify a different set of backends for different major modes. For example:
(add-hook 'org-mode-hook
(lambda ()
(setq-local company-backends '((company-files company-dabbrev)))))
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(setq-local company-backends '((company-capf company-dabbrev-code)))))