Skip to content

Instantly share code, notes, and snippets.

@bravosierrasierra
Created March 24, 2018 09:22
Show Gist options
  • Save bravosierrasierra/4e9653c7101e0ff36d0846411b7381f5 to your computer and use it in GitHub Desktop.
Save bravosierrasierra/4e9653c7101e0ff36d0846411b7381f5 to your computer and use it in GitHub Desktop.
*** company
http://company-mode.github.io/
**** company
#+begin_src emacs-lisp
(use-package company
:bind (
:map company-active-map
("\C-n" . company-select-next)
("\C-p" . company-select-previous)
("\C-d" . company-show-doc-buffer)
("M-." . company-show-location)
("TAB" . company-complete-common-or-cycle)
("<tab>" . company-complete-common-or-cycle)
("S-TAB" . company-select-previous)
("<backtab>" . company-select-previous)
)
:config
(global-company-mode t)
(setq company-idle-delay nil
delete-selection-mode t
company-minimum-prefix-length 2
company-dabbrev-downcase nil
company-dabbrev-other-buffers t
company-echo-delay 0
company-show-numbers t
company-dabbrev-code-everywhere t
company-dabbrev-code-ignore-case t
company-selection-wrap-around t
company-tooltip-align-annotations t
selection-coding-system 'utf-8
company-auto-complete-chars '(32 40 41 119 46 34 36 47 124 33)
company-backends '((
company-yasnippet
company-semantic
company-capf
company-gtags
company-etags
company-files
company-keywords
company-dabbrev-code
company-dabbrev)))
(evil-define-key 'insert prog-mode-map (kbd "s-SPC") 'company-complete)
(evil-define-key 'insert powershell-mode-map (kbd "s-SPC") 'company-complete)
;; complete via numbers
;; Web page: [[https://oremacs.com/2017/12/27/company-numbers/][Using digits to select company-mode candidates · (or emacs]]
;; Besides binding 0..9 to complete their corresponding candidate. Customization will now check company-candidates—the list of possible completions—for the above mentioned conflict. And if it's detected, the key pressed will be inserted instead of being used to select a candidate.
(setq company-show-numbers t)
(let ((map company-active-map))
(mapc
(lambda (x)
(define-key map (format "%d" x) 'ora-company-number))
(number-sequence 0 9))
(define-key map " " (lambda ()
(interactive)
(company-abort)
(self-insert-command 1)))
(define-key map (kbd "<return>") nil))
(defun ora-company-number ()
"Forward to `company-complete-number'.
Unless the number is potentially part of the candidate.
In that case, insert the number."
(interactive)
(let* ((k (this-command-keys))
(re (concat "^" company-prefix k)))
(if (cl-find-if (lambda (s) (string-match re s))
company-candidates)
(self-insert-command 1)
(company-complete-number
(if (equal k "0")
10
(string-to-number k))))))
)
#+end_src
**** company quickhelp
#+begin_src emacs-lisp
(use-package company-quickhelp
:bind (
:map company-active-map
("C-c h" . company-quickhelp-manual-begin)
)
:after (company)
:config
(setq company-quickhelp-delay 1)
(company-quickhelp-mode 1)
)
#+end_src
**** company colors
#+begin_src emacs-lisp
(use-package color)
(ignore-errors
(let ((bg (face-attribute 'default :background)))
(custom-set-faces
`(company-tooltip ((t (:inherit default :background ,(color-lighten-name bg 20)))))
`(company-scrollbar-bg ((t (:background ,(color-lighten-name bg 40)))))
`(company-scrollbar-fg ((t (:background ,(color-lighten-name bg 60)))))
`(company-tooltip-selection ((t (:inherit font-lock-function-name-face))))
`(company-tooltip-common ((t (:inherit font-lock-constant-face))))
;; '(company-scrollbar-bg ((t (:background "#ffffff"))))
;; '(company-scrollbar-fg ((t (:background "#ffffff"))))
;; '(company-scrollbar<-fg ((t (:background "#999999"))))
;; '(company-tooltip ((t (:inherit default :background "dim gray"))))
;; '(company-tooltip-common ((t (:inherit font-lock-constant-face))))
;; '(company-tooltip-selection ((t (:inherit font-lock-function-name-face))))
))
)
#+end_src
**** company completion in babel
#+begin_src emacs-lisp
;; company autocompletion in org babel
(defun add-pcomplete-to-capf ()
(add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
(add-hook 'org-mode-hook #'add-pcomplete-to-capf)
#+end_src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment