lang/php: replace ac-php with phpactor.el
phpactor is superior to phpctags, though it requires more setup. phpactors.el is superior to ac-php, though it is in alpha.
This commit is contained in:
parent
e0f2c260a1
commit
9c4d1c3b02
3 changed files with 64 additions and 33 deletions
|
@ -2,6 +2,17 @@
|
|||
|
||||
(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
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
;;; lang/php/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +php--company-backends nil)
|
||||
|
||||
(def-package! php-mode
|
||||
:mode "\\.inc\\'"
|
||||
:config
|
||||
|
@ -12,13 +10,12 @@
|
|||
(set-repl-handler! 'php-mode #'php-boris)
|
||||
(set-lookup-handlers! 'php-mode :documentation #'php-search-documentation)
|
||||
|
||||
;; ac-php provides custom autocompletion, php-extras provides autocompletion
|
||||
;; for built-in libraries
|
||||
(when +php--company-backends
|
||||
(set-company-backend! 'php-mode +php--company-backends))
|
||||
;; `+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)
|
||||
|
||||
;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance
|
||||
(setq-hook! 'php-mode-hook sp-max-pair-length 6)
|
||||
(setq-hook! 'php-mode-hook sp-max-pair-length 5)
|
||||
|
||||
(sp-with-modes '(php-mode)
|
||||
(sp-local-pair "<?" "?>" :post-handlers '(("| " "SPC" "=") ("||\n[i]" "RET") ("[d2]" "p")))
|
||||
|
@ -26,34 +23,63 @@
|
|||
|
||||
(map! :map php-mode-map
|
||||
:localleader
|
||||
(:prefix "r"
|
||||
:n "cv" #'php-refactor--convert-local-to-instance-variable
|
||||
:n "u" #'php-refactor--optimize-use
|
||||
:v "xm" #'php-refactor--extract-method
|
||||
:n "rv" #'php-refactor--rename-local-variable)
|
||||
(:prefix "t"
|
||||
:n "r" #'phpunit-current-project
|
||||
:n "a" #'phpunit-current-class
|
||||
:n "s" #'phpunit-current-test)))
|
||||
:prefix "t"
|
||||
:n "r" #'phpunit-current-project
|
||||
:n "a" #'phpunit-current-class
|
||||
:n "s" #'phpunit-current-test))
|
||||
|
||||
|
||||
(def-package! hack-mode
|
||||
:when (featurep! +hack)
|
||||
:mode "\\.hh$")
|
||||
(def-package! phpactor
|
||||
:after php-mode
|
||||
:config
|
||||
(set-lookup-handlers! 'php-mode
|
||||
:definition #'phpactor-goto-definition)
|
||||
|
||||
;; TODO PR these for phpactor.el?
|
||||
;; company-phpactor breaks company if executable doesn't exist
|
||||
(defun +php*company-phpactor-fail-silently (orig-fn &rest args)
|
||||
(when (phpactor-find-executable)
|
||||
(apply orig-fn args)))
|
||||
(advice-add #'company-phpactor :around #'+php*company-phpactor-fail-silently)
|
||||
|
||||
;; `phpactor-get-working-dir' throws stringp errors if not in a project.
|
||||
(defun +php*project-root (&rest _)
|
||||
(setq phpactor-working-dir
|
||||
(or phpactor-working-dir
|
||||
(php-project-get-root-dir)
|
||||
(doom-project-root))))
|
||||
(advice-add #'phpactor-get-working-dir :before #'+php*project-root)
|
||||
|
||||
(map! :map php-mode-map
|
||||
:localleader
|
||||
:prefix "r"
|
||||
:n "cc" #'phpactor-copy-class
|
||||
:n "mc" #'phpactor-move-class
|
||||
:v "oi" #'phpactor-offset-info
|
||||
:n "t" #'phpactor-transform
|
||||
:n "ic" #'phpactor-import-class))
|
||||
|
||||
|
||||
(def-package! php-refactor-mode
|
||||
:hook php-mode)
|
||||
:hook php-mode
|
||||
:config
|
||||
(map! :map php-refactor-mode-map
|
||||
:localleader
|
||||
:prefix "r"
|
||||
:n "cv" #'php-refactor--convert-local-to-instance-variable
|
||||
:n "u" #'php-refactor--optimize-use
|
||||
:v "xm" #'php-refactor--extract-method
|
||||
:n "rv" #'php-refactor--rename-local-variable))
|
||||
|
||||
|
||||
(def-package! php-extras
|
||||
:after php-mode
|
||||
:preface (advice-add #'php-extras-company-setup :override #'ignore)
|
||||
:init (add-to-list '+php--company-backends 'php-extras-company nil #'eq)
|
||||
:preface
|
||||
;; We'll set up company support ourselves
|
||||
(advice-add #'php-extras-company-setup :override #'ignore)
|
||||
:config
|
||||
(setq php-extras-eldoc-functions-file
|
||||
(concat doom-etc-dir "php-extras-eldoc-functions"))
|
||||
|
||||
;; Make expensive php-extras generation async
|
||||
(unless (file-exists-p (concat php-extras-eldoc-functions-file ".el"))
|
||||
(message "Generating PHP eldoc files...")
|
||||
|
@ -67,13 +93,9 @@
|
|||
(message "PHP eldoc updated!")))))
|
||||
|
||||
|
||||
(def-package! company-php
|
||||
:when (featurep! :completion company)
|
||||
:commands (ac-php-remake-tags ac-php-remake-tags-all)
|
||||
:init
|
||||
(add-to-list '+php--company-backends 'company-ac-php-backend nil #'eq)
|
||||
(add-hook 'php-mode-hook #'+php|init-ac-php-core-eldoc)
|
||||
(setq ac-php-tags-path (concat doom-cache-dir "ac-php/")))
|
||||
(def-package! hack-mode
|
||||
:when (featurep! +hack)
|
||||
:mode "\\.hh$")
|
||||
|
||||
|
||||
;;
|
||||
|
|
|
@ -5,11 +5,9 @@
|
|||
(package! php-extras :recipe (:fetcher github :repo "arnested/php-extras"))
|
||||
(package! php-mode)
|
||||
(package! php-refactor-mode)
|
||||
(package! phpactor :recipe (:fetcher github :repo "emacs-php/phpactor.el" :files ("*.el")))
|
||||
(package! phpunit)
|
||||
|
||||
(when (featurep! :completion company)
|
||||
(package! company-php))
|
||||
|
||||
(when (featurep! +hack)
|
||||
(package! hack-mode :recipe (:fetcher github :repo "hhvm/hack-mode")))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue