0

While I am typing company shows suggestons. When I press space I want to abort suggestions and apply space, but instead it only does abort. Hence I need to press two times space to apply space.

[Q] How could I abort and apply space when company suggests completion?

(add-hook 'after-init-hook 'global-company-mode)
(setq company-auto-complete t)

(with-eval-after-load "company"
  (define-key company-active-map (kbd "C-p") #'company-select-previous-or-abort)
  (define-key company-active-map (kbd "C-n") #'company-select-next-or-abort)
  (define-key company-active-map (kbd "C-h") #'backward-delete-char)
  (define-key company-active-map (kbd ".") #'company-abort)
  (define-key company-active-map (kbd "SPC") #'company-abort)
  (define-key company-active-map (kbd "C-f") #'company-abort)
  )

(eval-after-load 'company
  '(progn
     (define-key company-active-map (kbd "TAB") 'company-complete-common-or-cycle)
     (define-key company-active-map (kbd "<tab>") 'company-complete-common-or-cycle)))

(setq company-frontends
      '(company-pseudo-tooltip-unless-just-one-frontend
        company-preview-frontend
        company-echo-metadata-frontend))

(setq company-auto-complete t)
(global-set-key (kbd "C-c C-k") 'company-complete)
1

Quite an ugly (and untested) suggestion:

  1. Define an ad-hoc function:
(defun company-abort-and-insert-space ()
  (interactive)
  (company-abort)
  (insert " "))
  1. Replace
(define-key company-active-map (kbd "SPC") #'company-abort)

by

(define-key company-active-map (kbd "SPC") #'company-abort-and-insert-space)

in your init.el file.

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.