From d949935628ee1ab621384a08056c6b7928bdb06d Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 23 May 2017 21:33:03 +0200 Subject: [PATCH] lang/php: refactor + add company-php --- modules/lang/php/config.el | 28 ++++++++++++++++++++-------- modules/lang/php/packages.el | 3 +++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/lang/php/config.el b/modules/lang/php/config.el index 35e7fbae4..6d8a6c0c6 100644 --- a/modules/lang/php/config.el +++ b/modules/lang/php/config.el @@ -9,13 +9,18 @@ (def-package! php-mode :mode ("\\.php[s345]?$" "\\.inc$") :interpreter "php" - :init - (add-hook 'php-mode-hook #'flycheck-mode) :config + (add-hook! 'php-mode-hook + #'(ac-php-core-eldoc-setup flycheck-mode)) + (setq php-template-compatibility nil) (set! :repl 'php-mode #'php-boris) + ;; ac-php provides custom autocompletion, php-extras provides autocompletion + ;; for built-in libraries + (set! :company-backend 'php-mode '(company-ac-php-backend php-extras-company)) + ;; default is 10; this optimizes `smartparens' performance, but limits sp ;; pairs to 6 characters. (add-hook! php-mode (setq-local sp-max-pair-length 6)) @@ -44,17 +49,14 @@ (def-package! php-extras :after php-mode :init - (add-hook 'php-mode-hook #'eldoc-mode) + ;; company will set up itself + (advice-add #'php-extras-company-setup :override #'ignore) :config (setq php-extras-eldoc-functions-file (concat doom-etc-dir "php-extras-eldoc-functions")) - (set! :company-bakend 'php-mode '(php-extras-company company-yasnippet)) - - ;; company will set up itself - (advice-add #'php-extras-company-setup :override #'ignore) - ;; Make expensive php-extras generation async (unless (file-exists-p (concat php-extras-eldoc-functions-file ".el")) + (message "Generating PHP eldoc files...") (async-start `(lambda () ,(async-inject-variables "\\`\\(load-path\\|php-extras-eldoc-functions-file\\)$") (require 'php-extras-gen-eldoc) @@ -76,6 +78,16 @@ (def-package! php-boris :commands php-boris) +(def-package! company-php + :when (featurep! :completion company) + :commands (company-ac-php-backend ac-php-remake-tags ac-php-remake-tags-all ac-php-core-eldoc-setup) + :config + (unless (executable-find "phpctags") + (warn "php-mode: phpctags isn't installed, auto-completion will be gimped")) + + (setq ac-php-tags-path (concat doom-cache-dir "ac-php/"))) + + ;; ;; Projects ;; diff --git a/modules/lang/php/packages.el b/modules/lang/php/packages.el index 7ae4a781a..5db18500f 100644 --- a/modules/lang/php/packages.el +++ b/modules/lang/php/packages.el @@ -7,6 +7,9 @@ (package! php-refactor-mode) (package! phpunit) +(when (featurep! :completion company) + (package! company-php)) + ;; (package! hack-mode ;; :recipe ;; (:fetcher url :url "https://raw.githubusercontent.com/facebook/hhvm/master/hphp/hack/editor-plugins/emacs/hack-mode.el"))