Last active
May 2, 2020 11:14
-
-
Save Bad-ptr/7787596 to your computer and use it in GitHub Desktop.
Allow company-mode in minibuffer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(with-eval-after-load "company-autoloads" | |
(global-company-mode 1) | |
(setq company-tooltip-limit 20 | |
company-minimum-prefix-length 1 | |
company-echo-delay 0 | |
company-begin-commands '(self-insert-command | |
c-electric-lt-gt c-electric-colon | |
completion-separator-self-insert-command) | |
company-idle-delay 0.2 | |
company-show-numbers t | |
company-tooltip-align-annotations t) | |
(defvar-local company-col-offset 0 "Horisontal tooltip offset.") | |
(defvar-local company-row-offset 0 "Vertical tooltip offset.") | |
(defun company--posn-col-row (posn) | |
(let ((col (car (posn-col-row posn))) | |
;; `posn-col-row' doesn't work well with lines of different height. | |
;; `posn-actual-col-row' doesn't handle multiple-width characters. | |
(row (cdr (posn-actual-col-row posn)))) | |
(when (and header-line-format (version< emacs-version "24.3.93.3")) | |
;; http://debbugs.gnu.org/18384 | |
(cl-decf row)) | |
(cons (+ col (window-hscroll) company-col-offset) (+ row company-row-offset)))) | |
(defun company-elisp-minibuffer (command &optional arg &rest ignored) | |
"`company-mode' completion back-end for Emacs Lisp in the minibuffer." | |
(interactive (list 'interactive)) | |
(case command | |
('prefix (and (minibufferp) | |
(case company-minibuffer-mode | |
('execute-extended-command (company-grab-symbol)) | |
(t (company-capf `prefix))))) | |
('candidates | |
(case company-minibuffer-mode | |
('execute-extended-command (all-completions arg obarray 'commandp)) | |
(t nil))))) | |
(defun minibuffer-company () | |
(unless company-mode | |
(when (and global-company-mode (or (eq this-command #'execute-extended-command) | |
(eq this-command #'eval-expression))) | |
(setq-local company-minibuffer-mode this-command) | |
(setq-local completion-at-point-functions | |
(list (if (fboundp 'elisp-completion-at-point) | |
#'elisp-completion-at-point | |
#'lisp-completion-at-point) t)) | |
(setq-local company-show-numbers nil) | |
(setq-local company-backends '((company-elisp-minibuffer company-capf))) | |
(setq-local company-tooltip-limit 8) | |
(setq-local company-col-offset 1) | |
(setq-local company-row-offset 1) | |
(setq-local company-frontends '(company-pseudo-tooltip-unless-just-one-frontend | |
company-preview-if-just-one-frontend)) | |
(company-mode 1) | |
(when (eq this-command #'execute-extended-command) | |
(company-complete))))) | |
(add-hook 'minibuffer-setup-hook #'minibuffer-company) | |
;;(remove-hook 'minibuffer-setup-hook #'minibuffer-company) | |
;;(add-hook 'eval-expression-minibuffer-setup-hook #'minibuffer-company) | |
;; (with-eval-after-load "company-flx-autoloads" | |
;; (company-flx-mode)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.