all repos — nixfiles @ 637c2437f01775fa0f10b5bac451e3b949d47077

System and user configuration, managed by nix and home-manager

Emacs: enable company-tide as secondary backend for typescript

use a macro to set up secondary company backend s by mode
Alan Pearce alan@alanpearce.eu
Sun, 28 Mar 2021 20:01:45 +0200
commit

637c2437f01775fa0f10b5bac451e3b949d47077

parent

113c154ed21e88dab5d28fe51c5d9c3f07c2842b

1 files changed, 15 insertions(+), 0 deletions(-)

jump to
M user/emacs/init.eluser/emacs/init.el
@@ -516,6 +516,18 @@ (use-package all-the-icons
   :config (setq all-the-icons-color-icons nil))
 
+(defmacro company-set-secondary-backend-for-mode (mode backend)
+  (let ((hook-fn-name (intern (concat "ap/set-local-backend-" (symbol-name mode)))))
+    `(progn
+       (defun ,hook-fn-name ()
+         (make-local-variable 'company-backends)
+         (setq company-backends (append
+                                 (list
+                                  'company-tabnine
+                                  ,backend)
+                                 (copy-tree (remq 'company-tabnine company-backends)))))
+       (add-hook ',(derived-mode-hook-name mode) #',hook-fn-name))))
+
 (use-package company-tabnine
   :commands (company-tabnine)
   :after (company)
@@ -945,6 +957,9 @@ (use-package tide
   :after (typescript-mode company flycheck)
   :ghook ('typescript-mode-hook #'tide-setup)
+  :init (progn
+          (setq tide-completion-setup-company-backend nil)
+          (company-set-secondary-backend-for-mode typescript-mode 'company-tide))
   :config (progn
             ;; loading this package has the annoying effect of breaking my company configuration
             ;; upstream fix: https://github.com/ananthakumaran/tide/pull/384