syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.64k stars 4.89k forks source link

Bind "C-x C-f" to company-files in evil insert state for Vim users #1797

Closed tuhdo closed 4 years ago

tuhdo commented 9 years ago

company-files currently does not show completion automatically. Users have to explicitly execute the command. This command should be bound to C-x C-f in insert state to amend the missing Vim feature.

tuhdo commented 9 years ago

@pesterhazy for now, the easiest thing is to enable global-company-mode then bind C-x C-f to company-files in evil insert state.

(define-key evil-insert-state-map (kbd "C-x C-f") 'company-files)

@syl20bnr I think it's time to enable global company again. We have a solution that we can control which backends to globally enable and which to locally enable.

(defmacro spacemacs|defvar-company-backends (mode)
  "Define a MODE specific company backend variable with default backends.
The variable name format is company-backends-MODE."
  `(defvar ,(intern (format "company-backends-%S" mode))
     '((company-dabbrev-code company-gtags company-etags company-keywords)
       company-files company-dabbrev)
     ,(format "Company backend list for %S" mode)))

We can achieve the same thing using setq-default, so we don't have to generate tons of variables if we have many major modes. We only need a single variable.

I think this will greatly simplify our current company architecture.

@trishume what do you think?

trishume commented 9 years ago

Not sure what you are talking about with company-files not activating, it works fine for me. The trick with it is that it only offers completion if you are in a string literal and you start it with / or ./.

I personally never use it because almost always I want to use project-relative paths rather than relative to the root of my filesystem or the current file. I also generally don't want to prefix my file paths. What we really need is a manual key binding that pops up file completion relative to the projectile root, with no prefix.

As for company architecture I totally agree about global company. I'm not sure about your architecture suggestion though, I'd have to think about it more to tell if that would be better or worse than what we have right now.

tuhdo commented 9 years ago

company-files is not activated in buffers that do not have comapny-mode enabled. And not always we want files related to project root, in particular when you want to include paths i.e. files in /etc.

Currently Spacemacs generates a variable for each major mode, and duplicates the default backend list for each major mode i.e. this list '((company-dabbrev-code company-gtags company-etags company-keywords) company-files company-dabbrev). It makes me feel like the more layers that support company I add, the slower spacemacs is getting. We can avoid it altogether with setq-default, and add more backends with setq-local. So, we can reuse the global list and create local list just in time.

tuhdo commented 9 years ago

As for insert with relative path, you can do that with helm-projectile-find-file:

If you don't insert any relative path, helm-projectile-find-files insert the absolute path to the selected file.

trishume commented 9 years ago

Cool, man I constantly learn things about helm from you, I've got to start writing them down, I doubt I remember have the helm wisdom you have imparted upon me.

As for company architecture change I would be in support of it as long as it doesn't make anything work less well than it currently does, particularly complex integrations like ycmd and c-c++. It seems like it might make things cleaner while still keeping a similar organization. I'm in favour of anything that will reduce the currently quite high number of lines required to add company integration to a layer.

StreakyCobra commented 8 years ago

@syl20bnr Any thought on the continuation of this thread?

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!