From 56cba7828c295acafbbd0e14938f62dd23080a3d Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 27 Feb 2020 23:27:28 -0500 Subject: [PATCH] lang/php: refactor company init --- modules/lang/php/autoload.el | 11 ----------- modules/lang/php/config.el | 12 +++++++++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/lang/php/autoload.el b/modules/lang/php/autoload.el index 5da10009b..edba22ea0 100644 --- a/modules/lang/php/autoload.el +++ b/modules/lang/php/autoload.el @@ -2,17 +2,6 @@ (defvar +php-composer-conf (make-hash-table :test 'equal)) -;;;###autoload -(defun +php-company-backend (command &optional arg &rest _ignored) - "A delegating company-backend that uses `company-phpactor' if phpactor is -available and installed, or `php-extras-company' otherwise." - (cond ((and (require 'company-phpactor nil t) - (ignore-errors (phpactor-find-executable))) - (company-phpactor command arg)) - ((and (require 'php-extras nil t) - (file-exists-p (concat php-extras-eldoc-functions-file ".el"))) - (php-extras-company command arg)))) - ;;;###autoload (defun +php-composer-conf (&optional project-root refresh-p) "Retrieve the contents of composer.json as an alist. If REFRESH-P is non-nil diff --git a/modules/lang/php/config.el b/modules/lang/php/config.el index d3b34bd35..a141306d7 100644 --- a/modules/lang/php/config.el +++ b/modules/lang/php/config.el @@ -1,5 +1,8 @@ ;;; lang/php/config.el -*- lexical-binding: t; -*- +(defvar +php--company-backends nil + "List of company backends to use in `php-mode'.") + (after! projectile (add-to-list 'projectile-project-root-files "composer.json")) @@ -23,7 +26,10 @@ (add-hook 'php-mode-local-vars-hook #'lsp!) ;; `+php-company-backend' uses `company-phpactor', `php-extras-company' or ;; `company-dabbrev-code', in that order. - (set-company-backend! 'php-mode '+php-company-backend 'company-dabbrev-code)) + (when +php--company-backends + (set-company-backend! 'php-mode + (cons :separate +php--company-backends) + 'company-dabbrev-code))) ;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance (setq-hook! 'php-mode-hook sp-max-pair-length 5) @@ -43,6 +49,8 @@ (use-package! phpactor :unless (featurep! +lsp) :after php-mode + :init + (add-to-list '+php--company-backends #'company-phpactor nil 'eq) :config (set-lookup-handlers! 'php-mode :definition #'phpactor-goto-definition) @@ -74,6 +82,8 @@ :preface ;; We'll set up company support ourselves (advice-add #'php-extras-company-setup :override #'ignore) + :init + (add-to-list '+php--company-backends #'php-extras-company) :config (setq php-extras-eldoc-functions-file (concat doom-etc-dir "php-extras-eldoc-functions"))