2017-06-08 11:47:56 +02:00
|
|
|
;;; completion/company/config.el -*- lexical-binding: t; -*-
|
2017-02-19 18:41:26 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! company
|
2021-05-23 21:48:38 -04:00
|
|
|
:commands (company-complete-common
|
|
|
|
company-complete-common-or-cycle
|
|
|
|
company-manual-begin
|
|
|
|
company-grab-line)
|
2020-05-17 20:37:07 -04:00
|
|
|
:hook (doom-first-input . global-company-mode)
|
2018-04-18 18:22:23 -04:00
|
|
|
:init
|
2020-11-03 16:05:12 -05:00
|
|
|
(setq company-minimum-prefix-length 2
|
2018-02-02 15:57:49 -05:00
|
|
|
company-tooltip-limit 14
|
2017-02-19 18:41:26 -05:00
|
|
|
company-tooltip-align-annotations t
|
|
|
|
company-require-match 'never
|
2021-05-11 21:48:34 -04:00
|
|
|
company-global-modes
|
|
|
|
'(not erc-mode
|
|
|
|
message-mode
|
|
|
|
help-mode
|
|
|
|
gud-mode
|
|
|
|
vterm-mode)
|
2020-11-16 19:27:39 -05:00
|
|
|
company-frontends
|
|
|
|
'(company-pseudo-tooltip-frontend ; always show candidates in overlay tooltip
|
|
|
|
company-echo-metadata-frontend) ; show selected candidate docs in echo area
|
2020-04-30 01:35:20 -04:00
|
|
|
|
|
|
|
;; Buffer-local backends will be computed when loading a major mode, so
|
|
|
|
;; only specify a global default here.
|
2020-08-07 20:14:42 -04:00
|
|
|
company-backends '(company-capf)
|
2020-04-30 01:35:20 -04:00
|
|
|
|
2020-08-07 20:14:42 -04:00
|
|
|
;; These auto-complete the current selection when
|
|
|
|
;; `company-auto-complete-chars' is typed. This is too magical. We
|
|
|
|
;; already have the much more explicit RET and TAB.
|
|
|
|
company-auto-complete nil
|
2020-04-30 01:35:20 -04:00
|
|
|
company-auto-complete-chars nil
|
|
|
|
|
|
|
|
;; Only search the current buffer for `company-dabbrev' (a backend that
|
|
|
|
;; suggests text your open buffers). This prevents Company from causing
|
|
|
|
;; lag once you have a lot of buffers open.
|
|
|
|
company-dabbrev-other-buffers nil
|
|
|
|
;; Make `company-dabbrev' fully case-sensitive, to improve UX with
|
|
|
|
;; domain-specific words with particular casing.
|
|
|
|
company-dabbrev-ignore-case nil
|
|
|
|
company-dabbrev-downcase nil)
|
|
|
|
|
2021-05-23 21:48:38 -04:00
|
|
|
(when (featurep! +tng)
|
|
|
|
(add-hook 'global-company-mode-hook #'company-tng-mode))
|
|
|
|
|
2018-04-18 18:22:23 -04:00
|
|
|
:config
|
2019-04-21 19:59:44 -04:00
|
|
|
(when (featurep! :editor evil)
|
2019-07-09 16:12:44 +02:00
|
|
|
(add-hook 'company-mode-hook #'evil-normalize-keymaps)
|
2020-04-02 00:46:58 -04:00
|
|
|
(unless (featurep! +childframe)
|
|
|
|
;; Don't persist company popups when switching back to normal mode.
|
|
|
|
;; `company-box' aborts on mode switch so it doesn't need this.
|
2020-05-17 20:31:51 -04:00
|
|
|
(add-hook! 'evil-normal-state-entry-hook
|
|
|
|
(defun +company-abort-h ()
|
|
|
|
;; HACK `company-abort' doesn't no-op if company isn't active; causing
|
|
|
|
;; unwanted side-effects, like the suppression of messages in the
|
|
|
|
;; echo-area.
|
|
|
|
;; REVIEW Revisit this to refactor; shouldn't be necessary!
|
|
|
|
(when company-candidates
|
|
|
|
(company-abort)))))
|
2019-07-09 16:12:44 +02:00
|
|
|
;; Allow users to switch between backends on the fly. E.g. C-x C-s followed
|
|
|
|
;; by C-x C-n, will switch from `company-yasnippet' to
|
|
|
|
;; `company-dabbrev-code'.
|
2019-07-23 17:24:56 +02:00
|
|
|
(defadvice! +company--abort-previous-a (&rest _)
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
:before #'company-begin-backend
|
|
|
|
(company-abort)))
|
2019-07-09 16:12:44 +02:00
|
|
|
|
2020-10-07 21:45:09 -04:00
|
|
|
(add-hook 'after-change-major-mode-hook #'+company-init-backends-h 'append)
|
2017-02-19 18:41:26 -05:00
|
|
|
|
2020-10-16 00:28:25 -04:00
|
|
|
|
|
|
|
;; NOTE Fix #1335: ensure `company-emulation-alist' is the first item of
|
|
|
|
;; `emulation-mode-map-alists', thus higher priority than keymaps of
|
|
|
|
;; evil-mode. We raise the priority of company-mode keymaps
|
|
|
|
;; unconditionally even when completion is not activated. This should not
|
|
|
|
;; cause problems, because when completion is activated, the value of
|
|
|
|
;; `company-emulation-alist' is ((t . company-my-keymap)), when
|
|
|
|
;; completion is not activated, the value is ((t . nil)).
|
|
|
|
(add-hook! 'evil-local-mode-hook
|
|
|
|
(when (memq 'company-emulation-alist emulation-mode-map-alists)
|
2020-12-02 17:30:27 -05:00
|
|
|
(company-ensure-emulation-alist)))
|
|
|
|
|
|
|
|
;; Fix #4355: allow eldoc to trigger after completions.
|
|
|
|
(after! eldoc
|
|
|
|
(eldoc-add-command 'company-complete-selection
|
|
|
|
'company-complete-common
|
2021-02-25 13:56:41 -05:00
|
|
|
'company-capf
|
2020-12-02 17:30:27 -05:00
|
|
|
'company-abort)))
|
2018-05-14 20:45:47 +02:00
|
|
|
|
|
|
|
|
2018-09-07 19:36:16 -04:00
|
|
|
;;
|
2020-12-02 17:30:27 -05:00
|
|
|
;;; Packages
|
2018-09-07 19:36:16 -04:00
|
|
|
|
2019-10-10 20:34:52 +02:00
|
|
|
(after! company-files
|
2020-04-08 15:29:29 -04:00
|
|
|
(add-to-list 'company-files--regexps "file:\\(\\(?:\\.\\{1,2\\}/\\|~/\\|/\\)[^\]\n]*\\)"))
|
2019-10-10 20:34:52 +02:00
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! company-box
|
2019-11-07 12:49:30 -05:00
|
|
|
:when (featurep! +childframe)
|
2018-04-22 23:41:53 -04:00
|
|
|
:hook (company-mode . company-box-mode)
|
2017-02-20 20:43:22 -05:00
|
|
|
:config
|
2019-01-22 16:22:07 -05:00
|
|
|
(setq company-box-show-single-candidate t
|
|
|
|
company-box-backends-colors nil
|
2018-06-27 19:13:54 +02:00
|
|
|
company-box-max-candidates 50
|
2019-03-12 23:20:28 +10:00
|
|
|
company-box-icons-alist 'company-box-icons-all-the-icons
|
|
|
|
company-box-icons-functions
|
2020-01-13 00:08:59 -05:00
|
|
|
(cons #'+company-box-icons--elisp-fn
|
|
|
|
(delq 'company-box-icons--elisp
|
|
|
|
company-box-icons-functions))
|
2019-03-12 23:20:28 +10:00
|
|
|
company-box-icons-all-the-icons
|
2020-01-13 00:08:59 -05:00
|
|
|
(let ((all-the-icons-scale-factor 0.8))
|
|
|
|
`((Unknown . ,(all-the-icons-material "find_in_page" :face 'all-the-icons-purple))
|
|
|
|
(Text . ,(all-the-icons-material "text_fields" :face 'all-the-icons-green))
|
|
|
|
(Method . ,(all-the-icons-material "functions" :face 'all-the-icons-red))
|
|
|
|
(Function . ,(all-the-icons-material "functions" :face 'all-the-icons-red))
|
|
|
|
(Constructor . ,(all-the-icons-material "functions" :face 'all-the-icons-red))
|
|
|
|
(Field . ,(all-the-icons-material "functions" :face 'all-the-icons-red))
|
|
|
|
(Variable . ,(all-the-icons-material "adjust" :face 'all-the-icons-blue))
|
|
|
|
(Class . ,(all-the-icons-material "class" :face 'all-the-icons-red))
|
|
|
|
(Interface . ,(all-the-icons-material "settings_input_component" :face 'all-the-icons-red))
|
|
|
|
(Module . ,(all-the-icons-material "view_module" :face 'all-the-icons-red))
|
|
|
|
(Property . ,(all-the-icons-material "settings" :face 'all-the-icons-red))
|
|
|
|
(Unit . ,(all-the-icons-material "straighten" :face 'all-the-icons-red))
|
|
|
|
(Value . ,(all-the-icons-material "filter_1" :face 'all-the-icons-red))
|
|
|
|
(Enum . ,(all-the-icons-material "plus_one" :face 'all-the-icons-red))
|
|
|
|
(Keyword . ,(all-the-icons-material "filter_center_focus" :face 'all-the-icons-red))
|
|
|
|
(Snippet . ,(all-the-icons-material "short_text" :face 'all-the-icons-red))
|
|
|
|
(Color . ,(all-the-icons-material "color_lens" :face 'all-the-icons-red))
|
|
|
|
(File . ,(all-the-icons-material "insert_drive_file" :face 'all-the-icons-red))
|
|
|
|
(Reference . ,(all-the-icons-material "collections_bookmark" :face 'all-the-icons-red))
|
|
|
|
(Folder . ,(all-the-icons-material "folder" :face 'all-the-icons-red))
|
|
|
|
(EnumMember . ,(all-the-icons-material "people" :face 'all-the-icons-red))
|
|
|
|
(Constant . ,(all-the-icons-material "pause_circle_filled" :face 'all-the-icons-red))
|
|
|
|
(Struct . ,(all-the-icons-material "streetview" :face 'all-the-icons-red))
|
|
|
|
(Event . ,(all-the-icons-material "event" :face 'all-the-icons-red))
|
|
|
|
(Operator . ,(all-the-icons-material "control_point" :face 'all-the-icons-red))
|
|
|
|
(TypeParameter . ,(all-the-icons-material "class" :face 'all-the-icons-red))
|
|
|
|
(Template . ,(all-the-icons-material "short_text" :face 'all-the-icons-green))
|
|
|
|
(ElispFunction . ,(all-the-icons-material "functions" :face 'all-the-icons-red))
|
|
|
|
(ElispVariable . ,(all-the-icons-material "check_circle" :face 'all-the-icons-blue))
|
|
|
|
(ElispFeature . ,(all-the-icons-material "stars" :face 'all-the-icons-orange))
|
|
|
|
(ElispFace . ,(all-the-icons-material "format_paint" :face 'all-the-icons-pink)))))
|
2019-03-12 23:20:28 +10:00
|
|
|
|
2020-11-16 19:19:18 -05:00
|
|
|
;; HACK Fix oversized scrollbar in some odd cases
|
|
|
|
;; REVIEW `resize-mode' is deprecated and may stop working in the future.
|
|
|
|
;; TODO PR me upstream?
|
|
|
|
(setq x-gtk-resize-child-frames 'resize-mode)
|
|
|
|
|
2020-11-16 19:18:56 -05:00
|
|
|
;; Disable tab-bar in company-box child frames
|
|
|
|
;; TODO PR me upstream!
|
|
|
|
(add-to-list 'company-box-frame-parameters '(tab-bar-lines . 0))
|
|
|
|
|
|
|
|
;; Don't show documentation in echo area, because company-box displays its own
|
|
|
|
;; in a child frame.
|
2020-04-30 01:35:20 -04:00
|
|
|
(delq! 'company-echo-metadata-frontend company-frontends)
|
|
|
|
|
2019-07-23 12:30:47 +02:00
|
|
|
(defun +company-box-icons--elisp-fn (candidate)
|
2019-03-12 23:20:28 +10:00
|
|
|
(when (derived-mode-p 'emacs-lisp-mode)
|
|
|
|
(let ((sym (intern candidate)))
|
|
|
|
(cond ((fboundp sym) 'ElispFunction)
|
|
|
|
((boundp sym) 'ElispVariable)
|
|
|
|
((featurep sym) 'ElispFeature)
|
2020-01-13 00:08:59 -05:00
|
|
|
((facep sym) 'ElispFace)))))
|
|
|
|
|
2020-10-15 16:33:40 -04:00
|
|
|
;; `company-box' performs insufficient frame-live-p checks. Any command that
|
|
|
|
;; "cleans up the session" will break company-box.
|
|
|
|
;; TODO Fix this upstream.
|
|
|
|
(defadvice! +company-box-detect-deleted-frame-a (frame)
|
|
|
|
:filter-return #'company-box--get-frame
|
|
|
|
(if (frame-live-p frame) frame))
|
|
|
|
(defadvice! +company-box-detect-deleted-doc-frame-a (_selection frame)
|
|
|
|
:before #'company-box-doc
|
|
|
|
(and company-box-doc-enable
|
|
|
|
(frame-local-getq company-box-doc-frame frame)
|
|
|
|
(not (frame-live-p (frame-local-getq company-box-doc-frame frame)))
|
|
|
|
(frame-local-setq company-box-doc-frame nil frame))))
|
2017-02-20 20:43:22 -05:00
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! company-dict
|
2018-05-25 00:46:11 +02:00
|
|
|
:defer t
|
2017-03-02 18:17:40 -05:00
|
|
|
:config
|
2019-03-02 01:38:54 -05:00
|
|
|
(setq company-dict-dir (expand-file-name "dicts" doom-private-dir))
|
2019-07-28 14:52:59 +02:00
|
|
|
(add-hook! 'doom-project-hook
|
2019-07-23 12:30:47 +02:00
|
|
|
(defun +company-enable-project-dicts-h (mode &rest _)
|
2019-07-18 15:27:20 +02:00
|
|
|
"Enable per-project dictionaries."
|
|
|
|
(if (symbol-value mode)
|
|
|
|
(add-to-list 'company-dict-minor-mode-list mode nil #'eq)
|
|
|
|
(setq company-dict-minor-mode-list (delq mode company-dict-minor-mode-list))))))
|