diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-08-20 15:10:45 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-08-20 15:10:45 +0200 |
commit | 02859ac17f0b8305c1b8395d8bce4ccc0559aba8 (patch) | |
tree | 18f9c1196b8fe4e95899b8bab1f5135c97ff62ed /.config/emacs | |
parent | 7a9b2143a765ed5f8dbf86a1d80593d62e2ba273 (diff) |
emacs: Finish properly configuring ‘company-mode’
Diffstat (limited to '.config/emacs')
-rw-r--r-- | .config/emacs/config.org | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/.config/emacs/config.org b/.config/emacs/config.org index 7304c80..92e0255 100644 --- a/.config/emacs/config.org +++ b/.config/emacs/config.org @@ -526,20 +526,54 @@ that have components beginning with /foo/, /bar/, and /baz/ in that order. #+END_SRC -*** TODO Company +*** Company Company is a package to give me actual completion popups; it’s super useful for autocompleting code but has other uses too I guess. #+BEGIN_SRC elisp - ;; TODO: Properly configure ‘company’ + (defun mango--company-require-prefix (candidates) + "Transformer for ‘company-mode’ that requires that all candidates begin with + ‘company-prefix’." + (seq-filter (lambda (s) (string-prefix-p company-prefix s)) candidates)) + + (defun mango--company-select-candidate (pred) + "Select either the next or previous candidate in the candidate list based on + the comparison of the ‘company-pseudo-tooltip-overlay’ height and 0 using PRED." + (let ((ov company-pseudo-tooltip-overlay)) + (if (and ov (apply pred (list (overlay-get ov 'company-height) 0))) + (company-select-previous) + (company-select-next)))) + + (defun mango-company-next-candidate () + "Select the next available candidate, taking into account if the candidate + list is flipped or not." + (interactive) + (mango--company-select-candidate #'<)) + + (defun mango-company-previous-candidate () + "Select the previous available candidate, taking into account if the candidate + list is flipped or not." + (interactive) + (mango--company-select-candidate #'>)) (use-package company + :bind (:map company-active-map + ("C-j" . #'mango-company-next-candidate) + ("C-k" . #'mango-company-previous-candidate)) :hook ((conf-mode prog-mode) . company-mode) :custom (company-minimum-prefix-length 1) - (company-idle-delay 0.0)) + (company-idle-delay (lambda () (unless (company-in-string-or-comment) 0))) + (company-selection-wrap-around t) + (company-tooltip-align-annotations t) + (company-tooltip-flip-when-above t) + (company-frontends '(company-pseudo-tooltip-unless-just-one-frontend + company-preview-frontend + company-echo-metadata-frontend)) + (company-transformers '(mango--company-require-prefix + company-sort-by-backend-importance))) #+END_SRC |