diff options
Diffstat (limited to '.emacs.d/lisp/php-mode.el')
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 104 |
1 files changed, 34 insertions, 70 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 629c974..2e23642 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -8,14 +8,14 @@ | |||
| 8 | ;; Maintainer: USAMI Kenta <tadsan@zonu.me> | 8 | ;; Maintainer: USAMI Kenta <tadsan@zonu.me> |
| 9 | ;; URL: https://github.com/ejmr/php-mode | 9 | ;; URL: https://github.com/ejmr/php-mode |
| 10 | ;; Keywords: languages php | 10 | ;; Keywords: languages php |
| 11 | ;; Version: 1.18.4 | 11 | ;; Version: 1.19.0 |
| 12 | ;; Package-Requires: ((emacs "24") (cl-lib "0.5")) | 12 | ;; Package-Requires: ((emacs "24") (cl-lib "0.5")) |
| 13 | ;; License: GPL-3.0-or-later | 13 | ;; License: GPL-3.0-or-later |
| 14 | 14 | ||
| 15 | (defconst php-mode-version-number "1.18.4" | 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-01-30" | 18 | (defconst php-mode-modified "2018-03-05" |
| 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,9 +83,11 @@ | |||
| 83 | (require 'etags) | 83 | (require 'etags) |
| 84 | (require 'speedbar) | 84 | (require 'speedbar) |
| 85 | (require 'imenu) | 85 | (require 'imenu) |
| 86 | (require 'php-project nil t) | ||
| 86 | 87 | ||
| 87 | (require 'cl-lib) | 88 | (require 'cl-lib) |
| 88 | (require 'mode-local) | 89 | (require 'mode-local) |
| 90 | (require 'php-project) | ||
| 89 | 91 | ||
| 90 | (eval-when-compile | 92 | (eval-when-compile |
| 91 | (require 'regexp-opt) | 93 | (require 'regexp-opt) |
| @@ -373,14 +375,15 @@ This variable can take one of the following symbol values: | |||
| 373 | (const :tag "WordPress" wordpress) | 375 | (const :tag "WordPress" wordpress) |
| 374 | (const :tag "Symfony2" symfony2) | 376 | (const :tag "Symfony2" symfony2) |
| 375 | (const :tag "PSR-2" psr2)) | 377 | (const :tag "PSR-2" psr2)) |
| 376 | :set 'php-mode-custom-coding-style-set | ||
| 377 | :initialize 'custom-initialize-default) | 378 | :initialize 'custom-initialize-default) |
| 378 | 379 | ||
| 379 | (defun php-mode-custom-coding-style-set (sym value) | 380 | |
| 380 | (when (eq major-mode 'php-mode) | 381 | (defcustom php-mode-enable-project-coding-style t |
| 381 | (set sym value) | 382 | "When set to true override php-mode-coding-style by php-project-coding-style. |
| 382 | (set-default sym value) | 383 | |
| 383 | (php-set-style (symbol-name value)))) | 384 | If you want to suppress styles from being overwritten by directory / file |
| 385 | local variables, set NIL." | ||
| 386 | :type 'boolean) | ||
| 384 | 387 | ||
| 385 | (defun php-mode-version () | 388 | (defun php-mode-version () |
| 386 | "Display string describing the version of PHP Mode." | 389 | "Display string describing the version of PHP Mode." |
| @@ -388,30 +391,8 @@ This variable can take one of the following symbol values: | |||
| 388 | (message "PHP Mode %s of %s" | 391 | (message "PHP Mode %s of %s" |
| 389 | php-mode-version-number php-mode-modified)) | 392 | php-mode-version-number php-mode-modified)) |
| 390 | 393 | ||
| 391 | (defvar php-available-project-root-files | ||
| 392 | '((projectile ".projectile") | ||
| 393 | (composer "composer.json" "composer.lock") | ||
| 394 | (git ".git") | ||
| 395 | (mercurial ".hg") | ||
| 396 | (subversion ".svn") | ||
| 397 | ;; NOTICE: This method does not detect the top level of .editorconfig | ||
| 398 | ;; However, we can integrate it by adding the editorconfig.el's API. | ||
| 399 | ;;(editorconfig . ".editorconfig") | ||
| 400 | )) | ||
| 401 | |||
| 402 | ;;;###autoload | 394 | ;;;###autoload |
| 403 | (progn | 395 | (define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0") |
| 404 | (defvar php-project-root 'auto | ||
| 405 | "Method of searching for the top level directory. | ||
| 406 | |||
| 407 | `auto' (default) | ||
| 408 | Try to search file in order of `php-available-project-root-files'. | ||
| 409 | |||
| 410 | SYMBOL | ||
| 411 | Key of `php-available-project-root-files'.") | ||
| 412 | (make-variable-buffer-local 'php-project-root) | ||
| 413 | (put 'php-project-root 'safe-local-variable | ||
| 414 | #'(lambda (v) (assq v php-available-project-root-files)))) | ||
| 415 | 396 | ||
| 416 | (defvar php-mode-map | 397 | (defvar php-mode-map |
| 417 | (let ((map (make-sparse-keymap))) | 398 | (let ((map (make-sparse-keymap))) |
| @@ -441,11 +422,8 @@ SYMBOL | |||
| 441 | ;; | 422 | ;; |
| 442 | ;; https://www.gnu.org/software/emacs/manual/html_node/ccmode/Subword-Movement.html | 423 | ;; https://www.gnu.org/software/emacs/manual/html_node/ccmode/Subword-Movement.html |
| 443 | ;; | 424 | ;; |
| 444 | ;; for more information about Submode Word. | 425 | ;; for more information about Subword mode. |
| 445 | (if (boundp 'subword-mode) | 426 | (define-key map (kbd "C-c C-w") 'subword-mode) |
| 446 | (if subword-mode | ||
| 447 | (subword-mode nil) | ||
| 448 | (subword-mode t))) | ||
| 449 | 427 | ||
| 450 | ;; We inherit c-beginning-of-defun and c-end-of-defun from CC Mode | 428 | ;; We inherit c-beginning-of-defun and c-end-of-defun from CC Mode |
| 451 | ;; but we have two replacement functions specifically for PHP. We | 429 | ;; but we have two replacement functions specifically for PHP. We |
| @@ -595,7 +573,6 @@ PHP does not have an \"enum\"-like keyword." | |||
| 595 | "iterable" | 573 | "iterable" |
| 596 | "as" | 574 | "as" |
| 597 | "break" | 575 | "break" |
| 598 | "catch all" | ||
| 599 | "catch" | 576 | "catch" |
| 600 | "clone" | 577 | "clone" |
| 601 | "default" | 578 | "default" |
| @@ -682,7 +659,6 @@ but only if the setting is enabled" | |||
| 682 | (indent-tabs-mode . nil) | 659 | (indent-tabs-mode . nil) |
| 683 | (tab-width . ,(default-value 'tab-width)) | 660 | (tab-width . ,(default-value 'tab-width)) |
| 684 | (fill-column . ,(default-value 'fill-column)) | 661 | (fill-column . ,(default-value 'fill-column)) |
| 685 | (require-final-newline . ,(default-value 'require-final-newline)) | ||
| 686 | (show-trailing-whitespace . ,(default-value 'show-trailing-whitespace)) | 662 | (show-trailing-whitespace . ,(default-value 'show-trailing-whitespace)) |
| 687 | (php-style-delete-trailing-whitespace . nil))) | 663 | (php-style-delete-trailing-whitespace . nil))) |
| 688 | 664 | ||
| @@ -736,8 +712,7 @@ but only if the setting is enabled" | |||
| 736 | '("php" | 712 | '("php" |
| 737 | (c-offsets-alist . ((statement-cont . php-lineup-hanging-semicolon))) | 713 | (c-offsets-alist . ((statement-cont . php-lineup-hanging-semicolon))) |
| 738 | (c-indent-comments-syntactically-p . t) | 714 | (c-indent-comments-syntactically-p . t) |
| 739 | (fill-column . 78) | 715 | (fill-column . 78))) |
| 740 | (require-final-newline . t))) | ||
| 741 | 716 | ||
| 742 | (defun php-enable-symfony2-coding-style () | 717 | (defun php-enable-symfony2-coding-style () |
| 743 | "Make php-mode use coding styles that are preferable for working with Symfony2." | 718 | "Make php-mode use coding styles that are preferable for working with Symfony2." |
| @@ -750,7 +725,6 @@ but only if the setting is enabled" | |||
| 750 | (c-offsets-alist . ((statement-cont . +))) | 725 | (c-offsets-alist . ((statement-cont . +))) |
| 751 | (c-indent-comments-syntactically-p . t) | 726 | (c-indent-comments-syntactically-p . t) |
| 752 | (fill-column . 78) | 727 | (fill-column . 78) |
| 753 | (require-final-newline . t) | ||
| 754 | (show-trailing-whitespace . t) | 728 | (show-trailing-whitespace . t) |
| 755 | (php-style-delete-trailing-whitespace . t))) | 729 | (php-style-delete-trailing-whitespace . t))) |
| 756 | 730 | ||
| @@ -1148,15 +1122,24 @@ After setting the stylevars run hooks according to STYLENAME | |||
| 1148 | 1122 | ||
| 1149 | (put 'php-set-style 'interactive-form (interactive-form 'c-set-style)) | 1123 | (put 'php-set-style 'interactive-form (interactive-form 'c-set-style)) |
| 1150 | 1124 | ||
| 1125 | (defun php-mode-set-style-delay () | ||
| 1126 | "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) | ||
| 1128 | php-mode-coding-style))) | ||
| 1129 | (prog1 (php-set-style (symbol-name coding-style)) | ||
| 1130 | (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay)))) | ||
| 1131 | |||
| 1151 | (defun php-mode-debug () | 1132 | (defun php-mode-debug () |
| 1152 | "Display informations useful for debugging PHP Mode." | 1133 | "Display informations useful for debugging PHP Mode." |
| 1153 | (interactive) | 1134 | (interactive) |
| 1154 | (message "--- PHP-MODE DEBUG BEGIN ---") | 1135 | (message "--- PHP-MODE DEBUG BEGIN ---") |
| 1155 | (message "versions: %s; %s" (emacs-version) (php-mode-version)) | 1136 | (message "versions: %s; %s" (emacs-version) (php-mode-version)) |
| 1156 | (message "major-mode: %s" major-mode) | 1137 | (message "major-mode: %s" major-mode) |
| 1157 | (message "minor-modes: %s" (cl-remove-if | 1138 | (message "minor-modes: %s" |
| 1158 | (lambda (s) (string-match-p "global" (symbol-name s))) | 1139 | (cl-loop for s in minor-mode-list |
| 1159 | minor-mode-list)) | 1140 | unless (string-match-p "global" (symbol-name s)) |
| 1141 | if (and (boundp s) (symbol-value s)) | ||
| 1142 | collect s)) | ||
| 1160 | (message "variables: %s" | 1143 | (message "variables: %s" |
| 1161 | (cl-loop for v in '(indent-tabs-mode tab-width) | 1144 | (cl-loop for v in '(indent-tabs-mode tab-width) |
| 1162 | collect (list v (symbol-value v)))) | 1145 | collect (list v (symbol-value v)))) |
| @@ -1203,13 +1186,12 @@ After setting the stylevars run hooks according to STYLENAME | |||
| 1203 | ;; PHP vars are case-sensitive | 1186 | ;; PHP vars are case-sensitive |
| 1204 | (setq case-fold-search t) | 1187 | (setq case-fold-search t) |
| 1205 | 1188 | ||
| 1206 | ;; Do not force newline at end of file. Such newlines can cause | 1189 | ;; When php-mode-enable-project-coding-style is set, it is delayed by hook. |
| 1207 | ;; trouble if the PHP file is included in another file before calls | 1190 | ;; Since it depends on the timing at which the file local variable is set. |
| 1208 | ;; to header() or cookie(). | 1191 | ;; File local variables are set after initialization of major mode except `run-hook' is complete. |
| 1209 | (set (make-local-variable 'require-final-newline) nil) | 1192 | (if php-mode-enable-project-coding-style |
| 1210 | (set (make-local-variable 'next-line-add-newlines) nil) | 1193 | (add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t) |
| 1211 | 1194 | (php-set-style (symbol-name php-mode-coding-style))) | |
| 1212 | (php-set-style (symbol-name php-mode-coding-style)) | ||
| 1213 | 1195 | ||
| 1214 | (when (or php-mode-force-pear | 1196 | (when (or php-mode-force-pear |
| 1215 | (and (stringp buffer-file-name) | 1197 | (and (stringp buffer-file-name) |
| @@ -1599,12 +1581,6 @@ a completion list." | |||
| 1599 | ;; already fontified by another pattern. Note that using OVERRIDE | 1581 | ;; already fontified by another pattern. Note that using OVERRIDE |
| 1600 | ;; is usually overkill. | 1582 | ;; is usually overkill. |
| 1601 | `( | 1583 | `( |
| 1602 | ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but | ||
| 1603 | ;; not in $obj->var() | ||
| 1604 | ("->\\(\\sw+\\)\\s-*(" 1 'php-method-call) | ||
| 1605 | |||
| 1606 | ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 'php-property-name) | ||
| 1607 | |||
| 1608 | ;; Highlight all upper-cased symbols as constant | 1584 | ;; Highlight all upper-cased symbols as constant |
| 1609 | ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant) | 1585 | ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant) |
| 1610 | 1586 | ||
| @@ -1753,18 +1729,6 @@ The output will appear in the buffer *PHP*." | |||
| 1753 | (match-string-no-properties 1)))) | 1729 | (match-string-no-properties 1)))) |
| 1754 | 1730 | ||
| 1755 | ;;;###autoload | 1731 | ;;;###autoload |
| 1756 | (defun php-project-get-root-dir () | ||
| 1757 | "Return path to current PHP project." | ||
| 1758 | (let ((detect-method (if (stringp php-project-root) | ||
| 1759 | (list php-project-root) | ||
| 1760 | (if (eq php-project-root 'auto) | ||
| 1761 | (cl-loop for m in php-available-project-root-files | ||
| 1762 | append (cdr m)) | ||
| 1763 | (cdr-safe (assq php-project-root php-available-project-root-files)))))) | ||
| 1764 | (cl-loop for m in detect-method | ||
| 1765 | thereis (locate-dominating-file default-directory m)))) | ||
| 1766 | |||
| 1767 | ;;;###autoload | ||
| 1768 | (defun php-current-class () | 1732 | (defun php-current-class () |
| 1769 | "Insert current class name if cursor in class context." | 1733 | "Insert current class name if cursor in class context." |
| 1770 | (interactive) | 1734 | (interactive) |
