0

I want to enable and disable company-mode. Would I have to reset setup variables, everytime I want to enable company-mode? Should I call company-setup before calling company-enable. Is the placement of (add-hook 'after-init-hook 'global-company-mode) correct as part of setup?

(defun company-setup ()
  "Text completion-at-point drop-down framework displaying
possible candidates at cursor point as one types."

  (interactive)

  (setq company-minimum-prefix-length 2)

  (setq company-backends '(company-dabbrev company-dabbrev-code))

  (setq company-dabbrev-other-buffers 'all)
  (setq company-dabbrev-ignore-case 'keep-prefix)

  (setq company-dabbrev-code-other-buffers 'all)
  (setq company-dabbrev-code-ignore-case t)
  (setq company-dabbrev-code-everywhere t)
   
  (add-hook 'after-init-hook 'global-company-mode))

(defun company-enable ()
  "Disables company completion"
  (interactive)
  (company-mode 1))
2
  • The function company-setup is enabling company-mode globally, unlike company-enable, ignoring the other customizations. They have different implications. What do you want to do? If your goal is to call the functions interactively, then you can avoid the hook and directly call (global-company-mode 1). Aug 2 at 0:52
  • I want to enable and disable company-mode globally at will, with the dabbrev settings. What does company-mode do that conflicts with global-company-mode?
    – Ephram
    Aug 2 at 1:08

1 Answer 1

0

The following should enable dabbrev customizations with company-mode.

(with-eval-after-load "company"
  (setq company-minimum-prefix-length 2
        company-backends '(company-dabbrev company-dabbrev-code)
        company-dabbrev-other-buffers 'all
        company-dabbrev-ignore-case 'keep-prefix
        company-dabbrev-code-other-buffers 'all
        company-dabbrev-code-ignore-case t
        company-dabbrev-code-everywhere t))

You can now enable/disable company-mode globally "at will" with "M-x global-company-mode". You can use the after-init-hook if you want to have the mode enabled on startup.

2
  • I still cannot understand the difference between company-mode and global-company-mode.
    – Ephram
    Aug 2 at 10:20
  • That would be a perfectly good question to ask - as a question, not parenthetically in a comment.
    – NickD
    Aug 2 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.