Moving to Doom Emacs!

This commit is contained in:
Derek Taylor
2019-12-16 20:21:19 -06:00
parent d9f2f456f1
commit d4b4c33550
683 changed files with 51877 additions and 100 deletions
+67
View File
@@ -0,0 +1,67 @@
#+TITLE: :lang php
This module adds support for PHP 5.3+ (including PHP7).
+ ctags-based code completion (~company-php~ and ~phpctags~)
+ eldoc support (~ac-php~ and ~php-extras~)
+ REPL (~php-boris~)
+ Code refactoring commands (~php-refactor-mode~)
+ Unit-test commands (~phpunit~)
+ Support for ~laravel~ and ~composer~ projects (with project-specific snippets)
+ [[../../editor/file-templates/templates/php-mode][File templates]]
+ [[https://github.com/hlissner/doom-snippets/tree/master/php-mode][Snippets]]
#+begin_quote
PHP was the first programming language I got paid to code in, back in the Cretaceous period (2003). My sincerest apologies go out to all the programmers who inherited my earliest PHP work. I know you're out there, writhing in your straitjackets.
Save a programmer today. Stop a friend from choosing PHP as their first language.
#+end_quote
* Table of Contents :TOC:
- [[#install][Install]]
- [[#php][PHP]]
- [[#dependencies][Dependencies]]
* Install
** PHP
To get started with PHP, you'll need ~php~ (5.3+) and ~composer~:
*** MacOS
PHP 5.5 comes prepackaged with newer versions of MacOS. These instructions are provided for reference:
#+BEGIN_SRC sh :tangle (if (doom-system-os 'macos) "yes")
brew tap homebrew/homebrew-php
brew install php71 # or php53, php54, php55
brew install composer
#+END_SRC
*** Arch Linux
#+BEGIN_SRC sh :dir /sudo:: :tangle (if (doom-system-os 'arch) "yes")
sudo pacman --needed --noconfirm -S php composer # or php53, php54, php55
#+END_SRC
*** openSUSE
#+BEGIN_SRC sh :dir /sudo::
sudo zypper install php-composer
#+END_SRC
** Dependencies
The features in this module optionally depend on the following php packages:
+ ~boris~ (REPL)
+ ~phpctags~ (better code completion)
+ ~phpunit~ (unit test commands)
#+BEGIN_SRC sh
composer global require \
d11wtq/boris \
phpunit/phpunit \
techlivezheng/phpctags
#+END_SRC
Ensure that ~\~/.composer/vendor/bin~ is in ~PATH~:
#+BEGIN_SRC sh
# place this in your profile file, like ~/.bash_profile or ~/.zshenv
export PATH="~/.composer/vendor/bin:$PATH"
#+END_SRC
+26
View File
@@ -0,0 +1,26 @@
;;; lang/php/autoload.el -*- lexical-binding: t; -*-
(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
ignore the cache."
(let ((project-root (or project-root (doom-project-root))))
(or (and (not refresh-p) (gethash project-root +php-composer-conf))
(let ((package-file (expand-file-name "composer.json" project-root)))
(when-let (data (and (file-exists-p package-file)
(require 'json)
(json-read-file package-file)))
(puthash project-root data +php-composer-conf))))))
+111
View File
@@ -0,0 +1,111 @@
;;; lang/php/config.el -*- lexical-binding: t; -*-
(after! projectile
(add-to-list 'projectile-project-root-files "composer.json"))
;;
;;; Packages
(use-package! php-mode
:mode "\\.inc\\'"
:config
;; Disable HTML compatibility in php-mode. `web-mode' has superior support for
;; php+html. Use the .phtml
(setq php-template-compatibility nil)
(set-docsets! 'php-mode "PHP" "PHPUnit" "Laravel" "CakePHP" "CodeIgniter" "Doctrine_ORM")
(set-repl-handler! 'php-mode #'php-boris)
(set-lookup-handlers! 'php-mode :documentation #'php-search-documentation)
(set-formatter! 'php-mode #'php-cs-fixer-fix)
(if (featurep! +lsp)
(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))
;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance
(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")))
(sp-local-pair "<?php" "?>" :post-handlers '(("| " "SPC") ("||\n[i]" "RET"))))
(map! :localleader
:map php-mode-map
:prefix ("t" . "test")
"r" #'phpunit-current-project
"a" #'phpunit-current-class
"s" #'phpunit-current-test))
(use-package! phpactor
:unless (featurep! +lsp)
:after php-mode
:config
(set-lookup-handlers! 'php-mode
:definition #'phpactor-goto-definition)
(map! :localleader
:map php-mode-map
:prefix ("r" . "refactor")
"cc" #'phpactor-copy-class
"mc" #'phpactor-move-class
"oi" #'phpactor-offset-info
"t" #'phpactor-transform
"ic" #'phpactor-import-class))
(use-package! php-refactor-mode
:hook php-mode
:config
(map! :localleader
:map php-refactor-mode-map
:prefix "r"
"cv" #'php-refactor--convert-local-to-instance-variable
"u" #'php-refactor--optimize-use
"xm" #'php-refactor--extract-method
"rv" #'php-refactor--rename-local-variable))
(use-package! php-extras
:after php-mode
: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"))
;; Silence warning if `php-extras-eldoc-functions-file' hasn't finished
;; generating yet.
(defun php-extras-load-eldoc ()
(require 'php-extras-eldoc-functions php-extras-eldoc-functions-file t))
;; Make expensive php-extras generation async
(unless (file-exists-p (concat php-extras-eldoc-functions-file ".el"))
(message "Generating PHP eldoc files...")
(require 'async)
(async-start `(lambda ()
,(async-inject-variables "\\`\\(load-path\\|php-extras-eldoc-functions-file\\)$")
(require 'php-extras-gen-eldoc)
(php-extras-generate-eldoc-1 t))
(lambda (_)
(load (concat php-extras-eldoc-functions-file ".el"))
(message "PHP eldoc updated!")))))
(use-package! hack-mode
:when (featurep! +hack)
:mode "\\.hh$")
;;
;; Projects
(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)
:files ("composer.json"))
+6
View File
@@ -0,0 +1,6 @@
;; -*- lexical-binding: t; no-byte-compile: t; -*-
;;; lang/php/doctor.el
(assert! (or (not (featurep! +lsp))
(featurep! :tools lsp))
"This module requires (:tools lsp)")
+19
View File
@@ -0,0 +1,19 @@
;; -*- no-byte-compile: t; -*-
;;; lang/php/packages.el
(package! php-boris)
(package! php-extras :recipe (:host github :repo "arnested/php-extras"))
(package! php-mode)
(package! php-refactor-mode)
(package! phpunit)
(when (featurep! +hack)
(package! hack-mode :recipe (:host github :repo "hhvm/hack-mode")))
(unless (featurep! +lsp)
(package! phpactor)
(when (featurep! :completion company)
(package! company-phpactor)))
(when (featurep! :editor format)
(package! php-cs-fixer))