diff options
Diffstat (limited to '.emacs.d/lisp/php-mode.el')
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 142 |
1 files changed, 60 insertions, 82 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 6979e8c..a7c1985 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -2,16 +2,17 @@ | |||
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad | 3 | ;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad |
| 4 | ;; 2008 Aaron S. Hawley | 4 | ;; 2008 Aaron S. Hawley |
| 5 | ;; 2011, 2012, 2013, 2014, 2015 Eric James Michael Ritz | 5 | ;; 2011, 2012, 2013, 2014, 2015, 2016 Eric James Michael Ritz |
| 6 | 6 | ||
| 7 | ;;; Author: Eric James Michael Ritz | 7 | ;; Author: Eric James Michael Ritz |
| 8 | ;;; URL: https://github.com/ejmr/php-mode | 8 | ;; URL: https://github.com/ejmr/php-mode |
| 9 | ;;; Version: 1.17.0 | 9 | ;; Version: 1.17.0 |
| 10 | ;; Package-Requires: ((emacs "24") (cl-lib "0.5")) | ||
| 10 | 11 | ||
| 11 | (defconst php-mode-version-number "1.17.0" | 12 | (defconst php-mode-version-number "1.17.0" |
| 12 | "PHP Mode version number.") | 13 | "PHP Mode version number.") |
| 13 | 14 | ||
| 14 | (defconst php-mode-modified "2015-10-02" | 15 | (defconst php-mode-modified "2016-03-06" |
| 15 | "PHP Mode build date.") | 16 | "PHP Mode build date.") |
| 16 | 17 | ||
| 17 | ;;; License | 18 | ;;; License |
| @@ -78,9 +79,10 @@ | |||
| 78 | (require 'flymake) | 79 | (require 'flymake) |
| 79 | (require 'etags) | 80 | (require 'etags) |
| 80 | (require 'speedbar) | 81 | (require 'speedbar) |
| 82 | |||
| 83 | (require 'cl-lib) | ||
| 84 | |||
| 81 | (eval-when-compile | 85 | (eval-when-compile |
| 82 | (unless (require 'cl-lib nil t) | ||
| 83 | (require 'cl)) | ||
| 84 | (require 'regexp-opt) | 86 | (require 'regexp-opt) |
| 85 | (defvar c-vsemi-status-unknown-p) | 87 | (defvar c-vsemi-status-unknown-p) |
| 86 | (defvar syntax-propertize-via-font-lock)) | 88 | (defvar syntax-propertize-via-font-lock)) |
| @@ -91,12 +93,6 @@ | |||
| 91 | (if (and (= emacs-major-version 24) (>= emacs-minor-version 4)) | 93 | (if (and (= emacs-major-version 24) (>= emacs-minor-version 4)) |
| 92 | (require 'cl))) | 94 | (require 'cl))) |
| 93 | 95 | ||
| 94 | ;; Use the recommended cl functions in php-mode but alias them to the | ||
| 95 | ;; old names when we detect emacs < 24.3 | ||
| 96 | (if (and (= emacs-major-version 24) (< emacs-minor-version 3)) | ||
| 97 | (unless (fboundp 'cl-set-difference) | ||
| 98 | (defalias 'cl-set-difference 'set-difference))) | ||
| 99 | |||
| 100 | 96 | ||
| 101 | ;; Local variables | 97 | ;; Local variables |
| 102 | ;;;###autoload | 98 | ;;;###autoload |
| @@ -110,13 +106,11 @@ | |||
| 110 | (defcustom php-executable (or (executable-find "php") | 106 | (defcustom php-executable (or (executable-find "php") |
| 111 | "/usr/bin/php") | 107 | "/usr/bin/php") |
| 112 | "The location of the PHP executable." | 108 | "The location of the PHP executable." |
| 113 | :type 'string | 109 | :type 'string) |
| 114 | :group 'php) | ||
| 115 | 110 | ||
| 116 | (defcustom php-default-face 'default | 111 | (defcustom php-default-face 'default |
| 117 | "Default face in `php-mode' buffers." | 112 | "Default face in `php-mode' buffers." |
| 118 | :type 'face | 113 | :type 'face) |
| 119 | :group 'php) | ||
| 120 | 114 | ||
| 121 | (defcustom php-speedbar-config t | 115 | (defcustom php-speedbar-config t |
| 122 | "When set to true automatically configures Speedbar to observe PHP files. | 116 | "When set to true automatically configures Speedbar to observe PHP files. |
| @@ -126,8 +120,7 @@ Ignores php-file patterns option; fixed to expression \"\\.\\(inc\\|php[s345]?\\ | |||
| 126 | (set-default sym val) | 120 | (set-default sym val) |
| 127 | (when val | 121 | (when val |
| 128 | (speedbar-add-supported-extension | 122 | (speedbar-add-supported-extension |
| 129 | "\\.\\(inc\\|php[s345]?\\|phtml\\)"))) | 123 | "\\.\\(inc\\|php[s345]?\\|phtml\\)")))) |
| 130 | :group 'php) | ||
| 131 | 124 | ||
| 132 | (defcustom php-mode-speedbar-open nil | 125 | (defcustom php-mode-speedbar-open nil |
| 133 | "Normally `php-mode' starts with the speedbar closed. | 126 | "Normally `php-mode' starts with the speedbar closed. |
| @@ -136,13 +129,20 @@ Turning this on will open it whenever `php-mode' is loaded." | |||
| 136 | :set (lambda (sym val) | 129 | :set (lambda (sym val) |
| 137 | (set-default sym val) | 130 | (set-default sym val) |
| 138 | (when val | 131 | (when val |
| 139 | (speedbar 1))) | 132 | (speedbar 1)))) |
| 140 | :group 'php) | ||
| 141 | 133 | ||
| 142 | (defcustom php-template-compatibility t | 134 | (defcustom php-template-compatibility t |
| 143 | "Should detect presence of html tags." | 135 | "Should detect presence of html tags." |
| 144 | :type 'boolean | 136 | :type 'boolean) |
| 145 | :group 'php) | 137 | |
| 138 | (defsubst php-in-string-p () | ||
| 139 | (nth 3 (syntax-ppss))) | ||
| 140 | |||
| 141 | (defsubst php-in-comment-p () | ||
| 142 | (nth 4 (syntax-ppss))) | ||
| 143 | |||
| 144 | (defsubst php-in-string-or-comment-p () | ||
| 145 | (nth 8 (syntax-ppss))) | ||
| 146 | 146 | ||
| 147 | (defun php-mode-extra-constants-create-regexp(kwds) | 147 | (defun php-mode-extra-constants-create-regexp(kwds) |
| 148 | "Create regexp for the list of extra constant keywords KWDS." | 148 | "Create regexp for the list of extra constant keywords KWDS." |
| @@ -170,15 +170,13 @@ of constants when set." | |||
| 170 | 170 | ||
| 171 | (defcustom php-lineup-cascaded-calls nil | 171 | (defcustom php-lineup-cascaded-calls nil |
| 172 | "Indent chained method calls to the previous line" | 172 | "Indent chained method calls to the previous line" |
| 173 | :type 'boolean | 173 | :type 'boolean) |
| 174 | :group 'php) | ||
| 175 | 174 | ||
| 176 | ;;;###autoload | 175 | ;;;###autoload |
| 177 | (defcustom php-extra-constants '() | 176 | (defcustom php-extra-constants '() |
| 178 | "A list of additional strings to treat as PHP constants." | 177 | "A list of additional strings to treat as PHP constants." |
| 179 | :type 'list | 178 | :type 'list |
| 180 | :set 'php-mode-extra-constants-set | 179 | :set 'php-mode-extra-constants-set) |
| 181 | :group 'php) | ||
| 182 | 180 | ||
| 183 | (defun php-create-regexp-for-method (visibility) | 181 | (defun php-create-regexp-for-method (visibility) |
| 184 | "Make a regular expression for methods with the given VISIBILITY. | 182 | "Make a regular expression for methods with the given VISIBILITY. |
| @@ -244,70 +242,58 @@ can be used to match against definitions for that classlike." | |||
| 244 | (defcustom php-manual-url "http://www.php.net/manual/en/" | 242 | (defcustom php-manual-url "http://www.php.net/manual/en/" |
| 245 | "URL at which to find PHP manual. | 243 | "URL at which to find PHP manual. |
| 246 | You can replace \"en\" with your ISO language code." | 244 | You can replace \"en\" with your ISO language code." |
| 247 | :type 'string | 245 | :type 'string) |
| 248 | :group 'php) | ||
| 249 | 246 | ||
| 250 | (defcustom php-search-url "http://www.php.net/" | 247 | (defcustom php-search-url "http://www.php.net/" |
| 251 | "URL at which to search for documentation on a word." | 248 | "URL at which to search for documentation on a word." |
| 252 | :type 'string | 249 | :type 'string) |
| 253 | :group 'php) | ||
| 254 | 250 | ||
| 255 | (defcustom php-completion-file "" | 251 | (defcustom php-completion-file "" |
| 256 | "Path to the file which contains the function names known to PHP." | 252 | "Path to the file which contains the function names known to PHP." |
| 257 | :type 'string | 253 | :type 'string) |
| 258 | :group 'php) | ||
| 259 | 254 | ||
| 260 | (defcustom php-manual-path "" | 255 | (defcustom php-manual-path "" |
| 261 | "Path to the directory which contains the PHP manual." | 256 | "Path to the directory which contains the PHP manual." |
| 262 | :type 'string | 257 | :type 'string) |
| 263 | :group 'php) | ||
| 264 | 258 | ||
| 265 | ;;;###autoload | 259 | ;;;###autoload |
| 266 | (add-to-list 'interpreter-mode-alist (cons "php" 'php-mode)) | 260 | (add-to-list 'interpreter-mode-alist (cons "php" 'php-mode)) |
| 267 | 261 | ||
| 268 | (defcustom php-mode-hook nil | 262 | (defcustom php-mode-hook nil |
| 269 | "List of functions to be executed on entry to `php-mode'." | 263 | "List of functions to be executed on entry to `php-mode'." |
| 270 | :type 'hook | 264 | :type 'hook) |
| 271 | :group 'php) | ||
| 272 | 265 | ||
| 273 | (defcustom php-mode-pear-hook nil | 266 | (defcustom php-mode-pear-hook nil |
| 274 | "Hook called when a PHP PEAR file is opened with `php-mode'." | 267 | "Hook called when a PHP PEAR file is opened with `php-mode'." |
| 275 | :type 'hook | 268 | :type 'hook) |
| 276 | :group 'php) | ||
| 277 | 269 | ||
| 278 | (defcustom php-mode-drupal-hook nil | 270 | (defcustom php-mode-drupal-hook nil |
| 279 | "Hook called when a Drupal file is opened with `php-mode'." | 271 | "Hook called when a Drupal file is opened with `php-mode'." |
| 280 | :type 'hook | 272 | :type 'hook) |
| 281 | :group 'php) | ||
| 282 | 273 | ||
| 283 | (defcustom php-mode-wordpress-hook nil | 274 | (defcustom php-mode-wordpress-hook nil |
| 284 | "Hook called when a WordPress file is opened with `php-mode'." | 275 | "Hook called when a WordPress file is opened with `php-mode'." |
| 285 | :type 'hook | 276 | :type 'hook) |
| 286 | :group 'php) | ||
| 287 | 277 | ||
| 288 | (defcustom php-mode-symfony2-hook nil | 278 | (defcustom php-mode-symfony2-hook nil |
| 289 | "Hook called when a Symfony2 file is opened with `php-mode'." | 279 | "Hook called when a Symfony2 file is opened with `php-mode'." |
| 290 | :type 'hook | 280 | :type 'hook) |
| 291 | :group 'php) | ||
| 292 | 281 | ||
| 293 | (defcustom php-mode-psr2-hook nil | 282 | (defcustom php-mode-psr2-hook nil |
| 294 | "Hook called when a PSR-2 file is opened with `php-mode'." | 283 | "Hook called when a PSR-2 file is opened with `php-mode'." |
| 295 | :type 'hook | 284 | :type 'hook) |
| 296 | :group 'php) | ||
| 297 | 285 | ||
| 298 | (defcustom php-mode-force-pear nil | 286 | (defcustom php-mode-force-pear nil |
| 299 | "Normally PEAR coding rules are enforced only when the filename contains \"PEAR.\" | 287 | "Normally PEAR coding rules are enforced only when the filename contains \"PEAR.\" |
| 300 | Turning this on will force PEAR rules on all PHP files." | 288 | Turning this on will force PEAR rules on all PHP files." |
| 301 | :type 'boolean | 289 | :type 'boolean) |
| 302 | :group 'php) | ||
| 303 | 290 | ||
| 304 | (defcustom php-mode-warn-if-mumamo-off t | 291 | (defcustom php-mode-warn-if-mumamo-off t |
| 305 | "Warn once per buffer if you try to indent a buffer without | 292 | "Warn once per buffer if you try to indent a buffer without |
| 306 | mumamo-mode turned on. Detects if there are any HTML tags in the | 293 | mumamo-mode turned on. Detects if there are any HTML tags in the |
| 307 | buffer before warning, but this is is not very smart; e.g. if you | 294 | buffer before warning, but this is is not very smart; e.g. if you |
| 308 | have any tags inside a PHP string, it will be fooled." | 295 | have any tags inside a PHP string, it will be fooled." |
| 309 | :type '(choice (const :tag "Warg" t) (const "Don't warn" nil)) | 296 | :type '(choice (const :tag "Warg" t) (const "Don't warn" nil))) |
| 310 | :group 'php) | ||
| 311 | 297 | ||
| 312 | (defcustom php-mode-coding-style 'pear | 298 | (defcustom php-mode-coding-style 'pear |
| 313 | "Select default coding style to use with php-mode. | 299 | "Select default coding style to use with php-mode. |
| @@ -330,7 +316,6 @@ This variable can take one of the following symbol values: | |||
| 330 | (const :tag "WordPress" wordpress) | 316 | (const :tag "WordPress" wordpress) |
| 331 | (const :tag "Symfony2" symfony2) | 317 | (const :tag "Symfony2" symfony2) |
| 332 | (const :tag "PSR-2" psr2)) | 318 | (const :tag "PSR-2" psr2)) |
| 333 | :group 'php | ||
| 334 | :set 'php-mode-custom-coding-style-set | 319 | :set 'php-mode-custom-coding-style-set |
| 335 | :initialize 'custom-initialize-default) | 320 | :initialize 'custom-initialize-default) |
| 336 | 321 | ||
| @@ -808,7 +793,7 @@ example `html-mode'. Known such libraries are:\n\t" | |||
| 808 | '(available-names . 1) | 793 | '(available-names . 1) |
| 809 | ))) | 794 | ))) |
| 810 | (mode (when name | 795 | (mode (when name |
| 811 | (caddr (assoc name available-multi-libs))))) | 796 | (cl-caddr (assoc name available-multi-libs))))) |
| 812 | (when mode | 797 | (when mode |
| 813 | ;; Minibuffer window is more than one line, fix that first: | 798 | ;; Minibuffer window is more than one line, fix that first: |
| 814 | (message "") | 799 | (message "") |
| @@ -874,15 +859,6 @@ This is was done due to the problem reported here: | |||
| 874 | "See `php-c-at-vsemi-p'." | 859 | "See `php-c-at-vsemi-p'." |
| 875 | ) | 860 | ) |
| 876 | 861 | ||
| 877 | (defsubst php-in-string-p () | ||
| 878 | (nth 3 (syntax-ppss))) | ||
| 879 | |||
| 880 | (defsubst php-in-comment-p () | ||
| 881 | (nth 4 (syntax-ppss))) | ||
| 882 | |||
| 883 | (defsubst php-in-string-or-comment-p () | ||
| 884 | (nth 8 (syntax-ppss))) | ||
| 885 | |||
| 886 | (defun php-lineup-string-cont (langelem) | 862 | (defun php-lineup-string-cont (langelem) |
| 887 | "Line up string toward equal sign or dot | 863 | "Line up string toward equal sign or dot |
| 888 | e.g. | 864 | e.g. |
| @@ -908,12 +884,12 @@ this ^ lineup" | |||
| 908 | (goto-char (cdr langelem)) | 884 | (goto-char (cdr langelem)) |
| 909 | (vector (current-column)))) | 885 | (vector (current-column)))) |
| 910 | 886 | ||
| 911 | (defun php-lineup-arglist (langelem) | 887 | (defun php-lineup-arglist (_langelem) |
| 912 | (save-excursion | 888 | (save-excursion |
| 913 | (beginning-of-line) | 889 | (beginning-of-line) |
| 914 | (if (looking-at-p "\\s-*->") '+ 0))) | 890 | (if (looking-at-p "\\s-*->") '+ 0))) |
| 915 | 891 | ||
| 916 | (defun php-lineup-hanging-semicolon (langelem) | 892 | (defun php-lineup-hanging-semicolon (_langelem) |
| 917 | (save-excursion | 893 | (save-excursion |
| 918 | (beginning-of-line) | 894 | (beginning-of-line) |
| 919 | (if (looking-at-p "\\s-*;\\s-*$") 0 '+))) | 895 | (if (looking-at-p "\\s-*;\\s-*$") 0 '+))) |
| @@ -999,11 +975,10 @@ PHP heredoc." | |||
| 999 | '(("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) | 975 | '(("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) |
| 1000 | ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\"")))) | 976 | ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\"")))) |
| 1001 | 977 | ||
| 1002 | (when (boundp 'syntax-propertize-function) | 978 | (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) |
| 1003 | (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) | 979 | #'php-syntax-propertize-extend-region) |
| 1004 | #'php-syntax-propertize-extend-region) | 980 | (set (make-local-variable 'syntax-propertize-function) |
| 1005 | (set (make-local-variable 'syntax-propertize-function) | 981 | #'php-syntax-propertize-function) |
| 1006 | #'php-syntax-propertize-function)) | ||
| 1007 | 982 | ||
| 1008 | (setq imenu-generic-expression php-imenu-generic-expression) | 983 | (setq imenu-generic-expression php-imenu-generic-expression) |
| 1009 | 984 | ||
| @@ -1083,7 +1058,11 @@ PHP heredoc." | |||
| 1083 | (set (make-local-variable 'defun-prompt-regexp) | 1058 | (set (make-local-variable 'defun-prompt-regexp) |
| 1084 | "^\\s-*function\\s-+&?\\s-*\\(\\(\\sw\\|\\s_\\)+\\)\\s-*") | 1059 | "^\\s-*function\\s-+&?\\s-*\\(\\(\\sw\\|\\s_\\)+\\)\\s-*") |
| 1085 | (set (make-local-variable 'add-log-current-defun-header-regexp) | 1060 | (set (make-local-variable 'add-log-current-defun-header-regexp) |
| 1086 | php-beginning-of-defun-regexp)) | 1061 | php-beginning-of-defun-regexp) |
| 1062 | |||
| 1063 | (when (>= emacs-major-version 25) | ||
| 1064 | (php-syntax-propertize-function (point-min) (point-max)))) | ||
| 1065 | |||
| 1087 | 1066 | ||
| 1088 | ;; Define function name completion function | 1067 | ;; Define function name completion function |
| 1089 | (defvar php-completion-table nil | 1068 | (defvar php-completion-table nil |
| @@ -1219,8 +1198,7 @@ current `tags-file-name'." | |||
| 1219 | If non-nil, this shadows the value of `browse-url-browser-function' when | 1198 | If non-nil, this shadows the value of `browse-url-browser-function' when |
| 1220 | calling `php-search-documentation' or `php-search-local-documentation'." | 1199 | calling `php-search-documentation' or `php-search-local-documentation'." |
| 1221 | :type '(choice (const :tag "default" nil) function) | 1200 | :type '(choice (const :tag "default" nil) function) |
| 1222 | :link '(variable-link browse-url-browser-function) | 1201 | :link '(variable-link browse-url-browser-function)) |
| 1223 | :group 'php) | ||
| 1224 | 1202 | ||
| 1225 | (defun php-browse-documentation-url (url) | 1203 | (defun php-browse-documentation-url (url) |
| 1226 | "Browse a documentation URL using the configured browser function. | 1204 | "Browse a documentation URL using the configured browser function. |
| @@ -1289,14 +1267,14 @@ exists, and nil otherwise. | |||
| 1289 | With a prefix argument, prompt (with completion) for a word to search for." | 1267 | With a prefix argument, prompt (with completion) for a word to search for." |
| 1290 | (interactive (php--search-documentation-read-arg)) | 1268 | (interactive (php--search-documentation-read-arg)) |
| 1291 | (let ((file (catch 'found | 1269 | (let ((file (catch 'found |
| 1292 | (loop for type in php-search-local-documentation-types do | 1270 | (cl-loop for type in php-search-local-documentation-types do |
| 1293 | (let* ((doc-html (format "%s.%s.html" | 1271 | (let* ((doc-html (format "%s.%s.html" |
| 1294 | type | 1272 | type |
| 1295 | (replace-regexp-in-string | 1273 | (replace-regexp-in-string |
| 1296 | "_" "-" (downcase word)))) | 1274 | "_" "-" (downcase word)))) |
| 1297 | (file (expand-file-name doc-html php-manual-path))) | 1275 | (file (expand-file-name doc-html php-manual-path))) |
| 1298 | (when (file-exists-p file) | 1276 | (when (file-exists-p file) |
| 1299 | (throw 'found file))))))) | 1277 | (throw 'found file))))))) |
| 1300 | (when file | 1278 | (when file |
| 1301 | (let ((file-url (if (string-prefix-p "file://" file) | 1279 | (let ((file-url (if (string-prefix-p "file://" file) |
| 1302 | file | 1280 | file |
| @@ -1462,7 +1440,7 @@ The output will appear in the buffer *PHP*." | |||
| 1462 | (defface php-annotations-annotation-face '((t . (:inherit font-lock-constant-face))) | 1440 | (defface php-annotations-annotation-face '((t . (:inherit font-lock-constant-face))) |
| 1463 | "Face used to highlight annotations.") | 1441 | "Face used to highlight annotations.") |
| 1464 | 1442 | ||
| 1465 | (defconst php-annotations-re "\\(\\s-\\|{\\)\\(@[[:alpha:]]+\\)") | 1443 | (defconst php-annotations-re "\\(\\s-\\|{\\)\\(@[-\\[:alpha:]]+\\)") |
| 1466 | 1444 | ||
| 1467 | (defmacro php-annotations-inside-comment-p (pos) | 1445 | (defmacro php-annotations-inside-comment-p (pos) |
| 1468 | "Return non-nil if POS is inside a comment." | 1446 | "Return non-nil if POS is inside a comment." |
| @@ -1535,7 +1513,7 @@ The output will appear in the buffer *PHP*." | |||
| 1535 | 1513 | ||
| 1536 | 1514 | ||
| 1537 | ;;;###autoload | 1515 | ;;;###autoload |
| 1538 | (dolist (pattern '("\\.php[s345t]?\\'" "\\.phtml\\'" "Amkfile" "\\.amk$")) | 1516 | (dolist (pattern '("\\.php[s345t]?\\'" "\\.phtml\\'" "/Amkfile\\'" "\\.amk\\'")) |
| 1539 | (add-to-list 'auto-mode-alist `(,pattern . php-mode) t)) | 1517 | (add-to-list 'auto-mode-alist `(,pattern . php-mode) t)) |
| 1540 | 1518 | ||
| 1541 | (provide 'php-mode) | 1519 | (provide 'php-mode) |
