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))
|
(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
|
;;;###autoload
|
||||||
(defun +php-composer-conf (&optional project-root refresh-p)
|
(defun +php-composer-conf (&optional project-root refresh-p)
|
||||||
"Retrieve the contents of composer.json as an alist. If REFRESH-P is non-nil
|
"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; -*-
|
;;; lang/php/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(defvar +php--company-backends nil)
|
|
||||||
|
|
||||||
(def-package! php-mode
|
(def-package! php-mode
|
||||||
:mode "\\.inc\\'"
|
:mode "\\.inc\\'"
|
||||||
:config
|
:config
|
||||||
|
@ -12,13 +10,12 @@
|
||||||
(set-repl-handler! 'php-mode #'php-boris)
|
(set-repl-handler! 'php-mode #'php-boris)
|
||||||
(set-lookup-handlers! 'php-mode :documentation #'php-search-documentation)
|
(set-lookup-handlers! 'php-mode :documentation #'php-search-documentation)
|
||||||
|
|
||||||
;; ac-php provides custom autocompletion, php-extras provides autocompletion
|
;; `+php-company-backend' uses `company-phpactor', `php-extras-company' or
|
||||||
;; for built-in libraries
|
;; `company-dabbrev-code', in that order.
|
||||||
(when +php--company-backends
|
(set-company-backend! 'php-mode '+php-company-backend 'company-dabbrev-code)
|
||||||
(set-company-backend! 'php-mode +php--company-backends))
|
|
||||||
|
|
||||||
;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance
|
;; 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-with-modes '(php-mode)
|
||||||
(sp-local-pair "<?" "?>" :post-handlers '(("| " "SPC" "=") ("||\n[i]" "RET") ("[d2]" "p")))
|
(sp-local-pair "<?" "?>" :post-handlers '(("| " "SPC" "=") ("||\n[i]" "RET") ("[d2]" "p")))
|
||||||
|
@ -26,34 +23,63 @@
|
||||||
|
|
||||||
(map! :map php-mode-map
|
(map! :map php-mode-map
|
||||||
:localleader
|
:localleader
|
||||||
(:prefix "r"
|
:prefix "t"
|
||||||
:n "cv" #'php-refactor--convert-local-to-instance-variable
|
:n "r" #'phpunit-current-project
|
||||||
:n "u" #'php-refactor--optimize-use
|
:n "a" #'phpunit-current-class
|
||||||
:v "xm" #'php-refactor--extract-method
|
:n "s" #'phpunit-current-test))
|
||||||
:n "rv" #'php-refactor--rename-local-variable)
|
|
||||||
(:prefix "t"
|
|
||||||
:n "r" #'phpunit-current-project
|
|
||||||
:n "a" #'phpunit-current-class
|
|
||||||
:n "s" #'phpunit-current-test)))
|
|
||||||
|
|
||||||
|
|
||||||
(def-package! hack-mode
|
(def-package! phpactor
|
||||||
:when (featurep! +hack)
|
:after php-mode
|
||||||
:mode "\\.hh$")
|
: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
|
(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
|
(def-package! php-extras
|
||||||
:after php-mode
|
:after php-mode
|
||||||
:preface (advice-add #'php-extras-company-setup :override #'ignore)
|
:preface
|
||||||
:init (add-to-list '+php--company-backends 'php-extras-company nil #'eq)
|
;; We'll set up company support ourselves
|
||||||
|
(advice-add #'php-extras-company-setup :override #'ignore)
|
||||||
:config
|
:config
|
||||||
(setq php-extras-eldoc-functions-file
|
(setq php-extras-eldoc-functions-file
|
||||||
(concat doom-etc-dir "php-extras-eldoc-functions"))
|
(concat doom-etc-dir "php-extras-eldoc-functions"))
|
||||||
|
|
||||||
;; Make expensive php-extras generation async
|
;; Make expensive php-extras generation async
|
||||||
(unless (file-exists-p (concat php-extras-eldoc-functions-file ".el"))
|
(unless (file-exists-p (concat php-extras-eldoc-functions-file ".el"))
|
||||||
(message "Generating PHP eldoc files...")
|
(message "Generating PHP eldoc files...")
|
||||||
|
@ -67,13 +93,9 @@
|
||||||
(message "PHP eldoc updated!")))))
|
(message "PHP eldoc updated!")))))
|
||||||
|
|
||||||
|
|
||||||
(def-package! company-php
|
(def-package! hack-mode
|
||||||
:when (featurep! :completion company)
|
:when (featurep! +hack)
|
||||||
:commands (ac-php-remake-tags ac-php-remake-tags-all)
|
:mode "\\.hh$")
|
||||||
: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/")))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -5,11 +5,9 @@
|
||||||
(package! php-extras :recipe (:fetcher github :repo "arnested/php-extras"))
|
(package! php-extras :recipe (:fetcher github :repo "arnested/php-extras"))
|
||||||
(package! php-mode)
|
(package! php-mode)
|
||||||
(package! php-refactor-mode)
|
(package! php-refactor-mode)
|
||||||
|
(package! phpactor :recipe (:fetcher github :repo "emacs-php/phpactor.el" :files ("*.el")))
|
||||||
(package! phpunit)
|
(package! phpunit)
|
||||||
|
|
||||||
(when (featurep! :completion company)
|
|
||||||
(package! company-php))
|
|
||||||
|
|
||||||
(when (featurep! +hack)
|
(when (featurep! +hack)
|
||||||
(package! hack-mode :recipe (:fetcher github :repo "hhvm/hack-mode")))
|
(package! hack-mode :recipe (:fetcher github :repo "hhvm/hack-mode")))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue