diff options
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 94 |
1 files changed, 69 insertions, 25 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 70e7efc..dc9b738 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | (defconst php-mode-version-number "1.19.0" | 15 | (defconst php-mode-version-number "1.19.0" |
| 16 | "PHP Mode version number.") | 16 | "PHP Mode version number.") |
| 17 | 17 | ||
| 18 | (defconst php-mode-modified "2018-03-05" | 18 | (defconst php-mode-modified "2018-03-24" |
| 19 | "PHP Mode build date.") | 19 | "PHP Mode build date.") |
| 20 | 20 | ||
| 21 | ;; This file is free software; you can redistribute it and/or | 21 | ;; This file is free software; you can redistribute it and/or |
| @@ -83,6 +83,7 @@ | |||
| 83 | (require 'etags) | 83 | (require 'etags) |
| 84 | (require 'speedbar) | 84 | (require 'speedbar) |
| 85 | (require 'imenu) | 85 | (require 'imenu) |
| 86 | (require 'nadvice nil t) | ||
| 86 | (require 'php-project nil t) | 87 | (require 'php-project nil t) |
| 87 | 88 | ||
| 88 | (require 'cl-lib) | 89 | (require 'cl-lib) |
| @@ -385,6 +386,13 @@ If you want to suppress styles from being overwritten by directory / file | |||
| 385 | local variables, set NIL." | 386 | local variables, set NIL." |
| 386 | :type 'boolean) | 387 | :type 'boolean) |
| 387 | 388 | ||
| 389 | (defcustom php-mode-enable-backup-style-variables t | ||
| 390 | "When set to `T', back up values set by hook and buffer local variables. | ||
| 391 | |||
| 392 | This function may interfere with other hooks and other behaviors. | ||
| 393 | In that case set to `NIL'." | ||
| 394 | :type 'boolean) | ||
| 395 | |||
| 388 | (defun php-mode-version () | 396 | (defun php-mode-version () |
| 389 | "Display string describing the version of PHP Mode." | 397 | "Display string describing the version of PHP Mode." |
| 390 | (interactive) | 398 | (interactive) |
| @@ -1068,7 +1076,7 @@ this ^ lineup" | |||
| 1068 | "PHP Mode face used to highlight sigils($) of $this variable." | 1076 | "PHP Mode face used to highlight sigils($) of $this variable." |
| 1069 | :group 'php-faces) | 1077 | :group 'php-faces) |
| 1070 | 1078 | ||
| 1071 | (defface php-php-tag '((t (:inherit font-lock-constant-face))) | 1079 | (defface php-php-tag '((t (:inherit font-lock-preprocessor-face))) |
| 1072 | "PHP Mode face used to highlight PHP tags." | 1080 | "PHP Mode face used to highlight PHP tags." |
| 1073 | :group 'php-faces) | 1081 | :group 'php-faces) |
| 1074 | 1082 | ||
| @@ -1094,6 +1102,9 @@ this ^ lineup" | |||
| 1094 | 1102 | ||
| 1095 | (define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0") | 1103 | (define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0") |
| 1096 | 1104 | ||
| 1105 | (defvar php-mode--delayed-set-style nil) | ||
| 1106 | (make-variable-buffer-local 'php-mode--delayed-set-style) | ||
| 1107 | |||
| 1097 | (defun php-set-style (stylename &optional dont-override) | 1108 | (defun php-set-style (stylename &optional dont-override) |
| 1098 | "Set the current `php-mode' buffer to use the style STYLENAME. | 1109 | "Set the current `php-mode' buffer to use the style STYLENAME. |
| 1099 | STYLENAME is one of the names selectable in `php-mode-coding-style'. | 1110 | STYLENAME is one of the names selectable in `php-mode-coding-style'. |
| @@ -1110,7 +1121,21 @@ After setting the stylevars run hooks according to STYLENAME | |||
| 1110 | \"symfony2\" `php-mode-symfony2-hook' | 1121 | \"symfony2\" `php-mode-symfony2-hook' |
| 1111 | \"psr2\" `php-mode-psr2-hook'" | 1122 | \"psr2\" `php-mode-psr2-hook'" |
| 1112 | (interactive) | 1123 | (interactive) |
| 1113 | (c-set-style stylename dont-override) | 1124 | (php-mode--disable-delay-set-style) |
| 1125 | |||
| 1126 | ;; Back up manually set variables | ||
| 1127 | (let* (value | ||
| 1128 | (backup-vars | ||
| 1129 | (and php-mode-enable-backup-style-variables | ||
| 1130 | (cl-loop for name in c-style-variables | ||
| 1131 | do (setq value (symbol-value name)) | ||
| 1132 | if (and value (not (eq 'set-from-style value))) | ||
| 1133 | collect (cons name value))))) | ||
| 1134 | (c-set-style stylename dont-override) | ||
| 1135 | ;; Restore variables | ||
| 1136 | (cl-loop for (name . value) in backup-vars | ||
| 1137 | do (set (make-local-variable name) value))) | ||
| 1138 | |||
| 1114 | (if (eq (symbol-value 'php-style-delete-trailing-whitespace) t) | 1139 | (if (eq (symbol-value 'php-style-delete-trailing-whitespace) t) |
| 1115 | (add-hook 'before-save-hook 'delete-trailing-whitespace nil t) | 1140 | (add-hook 'before-save-hook 'delete-trailing-whitespace nil t) |
| 1116 | (remove-hook 'before-save-hook 'delete-trailing-whitespace t)) | 1141 | (remove-hook 'before-save-hook 'delete-trailing-whitespace t)) |
| @@ -1122,12 +1147,19 @@ After setting the stylevars run hooks according to STYLENAME | |||
| 1122 | 1147 | ||
| 1123 | (put 'php-set-style 'interactive-form (interactive-form 'c-set-style)) | 1148 | (put 'php-set-style 'interactive-form (interactive-form 'c-set-style)) |
| 1124 | 1149 | ||
| 1150 | (defun php-mode--disable-delay-set-style (&rest args) | ||
| 1151 | "Disable php-mode-set-style-delay on after hook. `ARGS' be ignore." | ||
| 1152 | (setq php-mode--delayed-set-style nil) | ||
| 1153 | (when (fboundp 'advice-remove) | ||
| 1154 | (advice-remove #'php-mode--disable-delay-set-style #'c-set-style))) | ||
| 1155 | |||
| 1125 | (defun php-mode-set-style-delay () | 1156 | (defun php-mode-set-style-delay () |
| 1126 | "Set the current `php-mode' buffer to use the style by custom or local variables." | 1157 | "Set the current `php-mode' buffer to use the style by custom or local variables." |
| 1127 | (let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style) | 1158 | (when php-mode--delayed-set-style |
| 1128 | php-mode-coding-style))) | 1159 | (let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style) |
| 1129 | (prog1 (php-set-style (symbol-name coding-style)) | 1160 | php-mode-coding-style))) |
| 1130 | (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay)))) | 1161 | (prog1 (php-set-style (symbol-name coding-style)) |
| 1162 | (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))) | ||
| 1131 | 1163 | ||
| 1132 | (defun php-mode-debug () | 1164 | (defun php-mode-debug () |
| 1133 | "Display informations useful for debugging PHP Mode." | 1165 | "Display informations useful for debugging PHP Mode." |
| @@ -1163,12 +1195,13 @@ After setting the stylevars run hooks according to STYLENAME | |||
| 1163 | (c-init-language-vars php-mode) | 1195 | (c-init-language-vars php-mode) |
| 1164 | (c-common-init 'php-mode) | 1196 | (c-common-init 'php-mode) |
| 1165 | 1197 | ||
| 1166 | (set (make-local-variable font-lock-string-face) 'php-string) | 1198 | (set (make-local-variable 'font-lock-string-face) 'php-string) |
| 1167 | (set (make-local-variable font-lock-keyword-face) 'php-keyword) | 1199 | (set (make-local-variable 'font-lock-keyword-face) 'php-keyword) |
| 1168 | (set (make-local-variable font-lock-builtin-face) 'php-builtin) | 1200 | (set (make-local-variable 'font-lock-builtin-face) 'php-builtin) |
| 1169 | (set (make-local-variable font-lock-function-name-face) 'php-function-name) | 1201 | (set (make-local-variable 'c-preprocessor-face-name) 'php-php-tag) |
| 1170 | (set (make-local-variable font-lock-variable-name-face) 'php-variable-name) | 1202 | (set (make-local-variable 'font-lock-function-name-face) 'php-function-name) |
| 1171 | (set (make-local-variable font-lock-constant-face) 'php-constant) | 1203 | (set (make-local-variable 'font-lock-variable-name-face) 'php-variable-name) |
| 1204 | (set (make-local-variable 'font-lock-constant-face) 'php-constant) | ||
| 1172 | 1205 | ||
| 1173 | (modify-syntax-entry ?_ "_" php-mode-syntax-table) | 1206 | (modify-syntax-entry ?_ "_" php-mode-syntax-table) |
| 1174 | (modify-syntax-entry ?` "\"" php-mode-syntax-table) | 1207 | (modify-syntax-entry ?` "\"" php-mode-syntax-table) |
| @@ -1190,7 +1223,11 @@ After setting the stylevars run hooks according to STYLENAME | |||
| 1190 | ;; Since it depends on the timing at which the file local variable is set. | 1223 | ;; Since it depends on the timing at which the file local variable is set. |
| 1191 | ;; File local variables are set after initialization of major mode except `run-hook' is complete. | 1224 | ;; File local variables are set after initialization of major mode except `run-hook' is complete. |
| 1192 | (if php-mode-enable-project-coding-style | 1225 | (if php-mode-enable-project-coding-style |
| 1193 | (add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t) | 1226 | (progn |
| 1227 | (add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t) | ||
| 1228 | (setq php-mode--delayed-set-style t) | ||
| 1229 | (when (fboundp 'advice-add) | ||
| 1230 | (advice-add #'c-set-style :after #'php-mode--disable-delay-set-style '(local)))) | ||
| 1194 | (php-set-style (symbol-name php-mode-coding-style))) | 1231 | (php-set-style (symbol-name php-mode-coding-style))) |
| 1195 | 1232 | ||
| 1196 | (when (or php-mode-force-pear | 1233 | (when (or php-mode-force-pear |
| @@ -1539,7 +1576,7 @@ a completion list." | |||
| 1539 | ;; php-mode patterns *before* cc-mode: | 1576 | ;; php-mode patterns *before* cc-mode: |
| 1540 | ;; only add patterns here if you want to prevent cc-mode from applying | 1577 | ;; only add patterns here if you want to prevent cc-mode from applying |
| 1541 | ;; a different face. | 1578 | ;; a different face. |
| 1542 | '( | 1579 | `( |
| 1543 | ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but | 1580 | ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but |
| 1544 | ;; not in $obj->var() | 1581 | ;; not in $obj->var() |
| 1545 | ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call)) | 1582 | ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call)) |
| @@ -1571,7 +1608,22 @@ a completion list." | |||
| 1571 | ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant) | 1608 | ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant) |
| 1572 | 1609 | ||
| 1573 | ;; Support the ::class constant in PHP5.6 | 1610 | ;; Support the ::class constant in PHP5.6 |
| 1574 | ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant))) | 1611 | ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant)) |
| 1612 | |||
| 1613 | ;; While c-opt-cpp-* highlights the <?php opening tags, it is not | ||
| 1614 | ;; possible to make it highlight short open tags and closing tags | ||
| 1615 | ;; as well. So we force the correct face on all cases that | ||
| 1616 | ;; c-opt-cpp-* lacks for this purpose. | ||
| 1617 | ;; | ||
| 1618 | ;; Note that starting a file with <% breaks indentation, a | ||
| 1619 | ;; limitation we can/should live with. | ||
| 1620 | (,(regexp-opt '("<?php" "<?=" "?>" | ||
| 1621 | "<?" ;; obsolete short open tag | ||
| 1622 | "<%" "%>" ;; obsolete ASP tag | ||
| 1623 | ;; Obsoleted tags were deleted in PHP 7. | ||
| 1624 | ;; @see http://php.net/manual/language.basic-syntax.phptags.php | ||
| 1625 | )) | ||
| 1626 | 0 'php-php-tag)) | ||
| 1575 | 1627 | ||
| 1576 | ;; cc-mode patterns | 1628 | ;; cc-mode patterns |
| 1577 | (c-lang-const c-matchers-3 php) | 1629 | (c-lang-const c-matchers-3 php) |
| @@ -1611,15 +1663,7 @@ a completion list." | |||
| 1611 | 1663 | ||
| 1612 | ;; Highlight class names used as nullable type hints | 1664 | ;; Highlight class names used as nullable type hints |
| 1613 | ("\\?\\(\\(:?\\sw\\|\\s_\\)+\\)\\s-+\\$" 1 font-lock-type-face) | 1665 | ("\\?\\(\\(:?\\sw\\|\\s_\\)+\\)\\s-+\\$" 1 font-lock-type-face) |
| 1614 | 1666 | )) | |
| 1615 | ;; While c-opt-cpp-* highlights the <?php opening tags, it is not | ||
| 1616 | ;; possible to make it highlight short open tags and closing tags | ||
| 1617 | ;; as well. So we force the correct face on all cases that | ||
| 1618 | ;; c-opt-cpp-* lacks for this purpose. | ||
| 1619 | ;; | ||
| 1620 | ;; Note that starting a file with <% breaks indentation, a | ||
| 1621 | ;; limitation we can/should live with. | ||
| 1622 | (,(regexp-opt '("?>" "<?" "<%" "%>")) 0 'php-php-tag))) | ||
| 1623 | "Detailed highlighting for PHP Mode.") | 1667 | "Detailed highlighting for PHP Mode.") |
| 1624 | 1668 | ||
| 1625 | (defvar php-font-lock-keywords php-font-lock-keywords-3 | 1669 | (defvar php-font-lock-keywords php-font-lock-keywords-3 |
