doomemacs/modules/lang/php/config.el

98 lines
3.2 KiB
EmacsLisp
Raw Normal View History

;;; lang/php/config.el -*- lexical-binding: t; -*-
2015-06-15 09:06:10 +02:00
2018-07-18 19:27:13 +02:00
(defvar +php--company-backends nil)
(def-package! php-mode
2018-07-18 19:27:13 +02:00
:mode "\\.inc\\'"
2015-06-15 09:06:10 +02:00
:config
;; Disable HTML compatibility in php-mode. `web-mode' has superior support for
;; php+html. Use the .phtml
2017-02-19 18:57:16 -05:00
(setq php-template-compatibility nil)
(set-repl-handler! 'php-mode #'php-boris)
(set-lookup-handlers! 'php-mode :documentation #'php-search-documentation)
2017-05-23 21:33:03 +02:00
;; ac-php provides custom autocompletion, php-extras provides autocompletion
;; for built-in libraries
2018-07-18 19:27:13 +02:00
(when +php--company-backends
(set-company-backend! 'php-mode +php--company-backends))
2017-05-23 21:33:03 +02:00
2018-07-18 19:27:13 +02:00
;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance
(setq-hook! 'php-mode-hook sp-max-pair-length 6)
(sp-with-modes '(php-mode)
(sp-local-pair "<?" "?>" :post-handlers '(("| " "SPC" "=") ("||\n[i]" "RET") ("[d2]" "p")))
(sp-local-pair "<?php" "?>" :post-handlers '(("| " "SPC") ("||\n[i]" "RET"))))
2017-02-19 18:57:16 -05:00
(map! :map php-mode-map
2017-02-19 18:57:16 -05:00
: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)))
2017-02-19 18:57:16 -05:00
2015-06-15 09:06:10 +02:00
2018-07-29 02:46:18 +02:00
(def-package! hack-mode
:when (featurep! +hack)
:mode "\\.hh$")
2018-07-18 19:27:13 +02:00
(def-package! php-refactor-mode
:hook php-mode)
(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)
2017-05-23 21:33:03 +02:00
:config
(setq php-extras-eldoc-functions-file
(concat doom-etc-dir "php-extras-eldoc-functions"))
2017-02-19 18:57:16 -05:00
;; Make expensive php-extras generation async
2015-11-17 02:09:34 -05:00
(unless (file-exists-p (concat php-extras-eldoc-functions-file ".el"))
2017-05-23 21:33:03 +02:00
(message "Generating PHP eldoc files...")
(require 'async)
2018-07-18 19:27:13 +02:00
(async-start (lambda ()
,(async-inject-variables "\\`\\(load-path\\|php-extras-eldoc-functions-file\\)$")
(require 'php-extras-gen-eldoc)
(php-extras-generate-eldoc-1 t))
2015-11-17 02:09:34 -05:00
(lambda (_)
(load (concat php-extras-eldoc-functions-file ".el"))
(message "PHP eldoc updated!")))))
2016-03-28 21:39:13 -04:00
2016-05-19 03:18:57 -04:00
2017-05-23 21:33:03 +02:00
(def-package! company-php
:when (featurep! :completion company)
2018-07-18 19:27:13 +02:00
: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)
:config
(setq ac-php-tags-path (concat doom-cache-dir "ac-php/"))
;; prioritize phpctags in PATH
(when (file-in-directory-p ac-php-ctags-executable ac-php-root-directory)
(setq ac-php-ctags-executable
(or (executable-find "phpctags")
(if (file-exists-p ac-php-ctags-executable)
ac-php-ctags-executable)))))
2017-05-23 21:33:03 +02:00
2017-02-19 18:57:16 -05:00
;;
;; Projects
2016-04-16 21:36:24 -04:00
;;
2017-02-19 18:57:16 -05:00
2017-03-02 18:20:46 -05:00
(def-project-mode! +php-laravel-mode
:modes (php-mode yaml-mode web-mode nxml-mode js2-mode scss-mode)
:files (and "artisan" "server.php"))
(def-project-mode! +php-composer-mode
:modes (web-mode php-mode)
2018-06-01 02:20:00 +02:00
:files ("composer.json"))
2017-02-19 18:57:16 -05:00