diff options
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 124 |
1 files changed, 96 insertions, 28 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index da5da0a..d18443d 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -2,17 +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, 2016 Eric James Michael Ritz | 5 | ;; 2011, 2012, 2013, 2014, 2015, 2016, 2017 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.18.2 | 9 | ;; Version: 1.18.2 |
| 10 | ;; Package-Requires: ((emacs "24") (cl-lib "0.5")) | 10 | ;; Package-Requires: ((emacs "24") (cl-lib "0.5")) |
| 11 | 11 | ||
| 12 | (defconst php-mode-version-number "1.18.2" | 12 | (defconst php-mode-version-number "1.18.3" |
| 13 | "PHP Mode version number.") | 13 | "PHP Mode version number.") |
| 14 | 14 | ||
| 15 | (defconst php-mode-modified "2017-02-20" | 15 | (defconst php-mode-modified "2017-04-04" |
| 16 | "PHP Mode build date.") | 16 | "PHP Mode build date.") |
| 17 | 17 | ||
| 18 | ;;; License | 18 | ;;; License |
| @@ -179,11 +179,11 @@ of constants when set." | |||
| 179 | ;; remove old keywords | 179 | ;; remove old keywords |
| 180 | (when (boundp 'php-extra-constants) | 180 | (when (boundp 'php-extra-constants) |
| 181 | (font-lock-remove-keywords | 181 | (font-lock-remove-keywords |
| 182 | 'php-mode `((,(php-mode-extra-constants-create-regexp php-extra-constants) 1 font-lock-constant-face)))) | 182 | 'php-mode `((,(php-mode-extra-constants-create-regexp php-extra-constants) 1 php-constant-face)))) |
| 183 | ;; add new keywords | 183 | ;; add new keywords |
| 184 | (when value | 184 | (when value |
| 185 | (font-lock-add-keywords | 185 | (font-lock-add-keywords |
| 186 | 'php-mode `((,(php-mode-extra-constants-create-regexp value) 1 font-lock-constant-face)))) | 186 | 'php-mode `((,(php-mode-extra-constants-create-regexp value) 1 php-constant-face)))) |
| 187 | (set sym value)) | 187 | (set sym value)) |
| 188 | 188 | ||
| 189 | (defcustom php-lineup-cascaded-calls nil | 189 | (defcustom php-lineup-cascaded-calls nil |
| @@ -508,8 +508,7 @@ PHP does not have an \"enum\"-like keyword." | |||
| 508 | php (append (c-lang-const c-class-decl-kwds) '("function"))) | 508 | php (append (c-lang-const c-class-decl-kwds) '("function"))) |
| 509 | 509 | ||
| 510 | (c-lang-defconst c-modifier-kwds | 510 | (c-lang-defconst c-modifier-kwds |
| 511 | php '("abstract" "const" "final" "native" "static" "strictfp" | 511 | php '("abstract" "const" "final" "static")) |
| 512 | "synchronized" "transient" "volatile")) | ||
| 513 | 512 | ||
| 514 | (c-lang-defconst c-protection-kwds | 513 | (c-lang-defconst c-protection-kwds |
| 515 | "Access protection label keywords in classes." | 514 | "Access protection label keywords in classes." |
| @@ -997,6 +996,67 @@ PHP heredoc." | |||
| 997 | (easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands" | 996 | (easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands" |
| 998 | (cons "PHP" (c-lang-const c-mode-menu php))) | 997 | (cons "PHP" (c-lang-const c-mode-menu php))) |
| 999 | 998 | ||
| 999 | |||
| 1000 | ;;; Faces | ||
| 1001 | (defgroup php-faces nil | ||
| 1002 | "Faces used in PHP Mode" | ||
| 1003 | :group 'php | ||
| 1004 | :group 'faces) | ||
| 1005 | |||
| 1006 | (defvar php-string-face 'php-string-face) | ||
| 1007 | (defvar php-keyword-face 'php-keyword-face) | ||
| 1008 | (defvar php-builtin-face 'php-builtin-face) | ||
| 1009 | (defvar php-function-name-face 'php-function-name-face) | ||
| 1010 | (defvar php-variable-name-face 'php-variable-name-face) | ||
| 1011 | (defvar php-type-face 'php-type-face) | ||
| 1012 | (defvar php-constant-face 'php-constant-face) | ||
| 1013 | (defvar php-php-tag-face 'php-php-tag-face) | ||
| 1014 | (defvar php-doc-annotation-tag-face 'php-doc-annotation-tag-face) | ||
| 1015 | (defvar php-doc-class-name-face 'php-doc-class-name-face) | ||
| 1016 | |||
| 1017 | (defface php-string-face '((t (:inherit font-lock-string-face))) | ||
| 1018 | "PHP Mode face used to highlight string literals." | ||
| 1019 | :group 'php-faces) | ||
| 1020 | |||
| 1021 | (defface php-keyword-face '((t (:inherit font-lock-keyword-face))) | ||
| 1022 | "PHP Mode face used to highlight keywords." | ||
| 1023 | :group 'php-faces) | ||
| 1024 | |||
| 1025 | (defface php-builtin-face '((t (:inherit font-lock-builtin-face))) | ||
| 1026 | "PHP Mode face used to highlight builtins." | ||
| 1027 | :group 'php-faces) | ||
| 1028 | |||
| 1029 | (defface php-function-name-face '((t (:inherit font-lock-function-name-face))) | ||
| 1030 | "PHP Mode face used to highlight function names." | ||
| 1031 | :group 'php-faces) | ||
| 1032 | |||
| 1033 | (defface php-variable-name-face '((t (:inherit font-lock-variable-name-face))) | ||
| 1034 | "PHP Mode face used to highlight variable names." | ||
| 1035 | :group 'php-faces) | ||
| 1036 | |||
| 1037 | (defface php-type-face '((t (:inherit font-lock-type-face))) | ||
| 1038 | "PHP Mode face used to highlight types." | ||
| 1039 | :group 'php-faces) | ||
| 1040 | |||
| 1041 | (defface php-constant-face '((t (:inherit font-lock-constant-face))) | ||
| 1042 | "PHP Mode face used to highlight constants." | ||
| 1043 | :group 'php-faces) | ||
| 1044 | |||
| 1045 | (defface php-php-tag-face '((t (:inherit font-lock-constant-face))) | ||
| 1046 | "PHP Mode face used to highlight PHP tags." | ||
| 1047 | :group 'php-faces) | ||
| 1048 | |||
| 1049 | (defface php-doc-annotation-tag-face '((t . (:inherit font-lock-constant-face))) | ||
| 1050 | "Face used to highlight annotation tags in doc-comment." | ||
| 1051 | :group 'php-faces) | ||
| 1052 | |||
| 1053 | (defface php-doc-class-name-face '((t (:inherit php-string-face))) | ||
| 1054 | "Face used to class names in doc-comment." | ||
| 1055 | :group 'php-faces) | ||
| 1056 | |||
| 1057 | (define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag-face "1.19.0") | ||
| 1058 | |||
| 1059 | |||
| 1000 | ;;;###autoload | 1060 | ;;;###autoload |
| 1001 | (define-derived-mode php-mode c-mode "PHP" | 1061 | (define-derived-mode php-mode c-mode "PHP" |
| 1002 | "Major mode for editing PHP code. | 1062 | "Major mode for editing PHP code. |
| @@ -1007,6 +1067,13 @@ PHP heredoc." | |||
| 1007 | (c-init-language-vars php-mode) | 1067 | (c-init-language-vars php-mode) |
| 1008 | (c-common-init 'php-mode) | 1068 | (c-common-init 'php-mode) |
| 1009 | 1069 | ||
| 1070 | (set (make-local-variable font-lock-string-face) php-string-face) | ||
| 1071 | (set (make-local-variable font-lock-keyword-face) php-keyword-face) | ||
| 1072 | (set (make-local-variable font-lock-builtin-face) php-builtin-face) | ||
| 1073 | (set (make-local-variable font-lock-function-name-face) php-function-name-face) | ||
| 1074 | (set (make-local-variable font-lock-variable-name-face) php-variable-name-face) | ||
| 1075 | (set (make-local-variable font-lock-constant-face) php-constant-face) | ||
| 1076 | |||
| 1010 | (modify-syntax-entry ?_ "_" php-mode-syntax-table) | 1077 | (modify-syntax-entry ?_ "_" php-mode-syntax-table) |
| 1011 | (modify-syntax-entry ?` "\"" php-mode-syntax-table) | 1078 | (modify-syntax-entry ?` "\"" php-mode-syntax-table) |
| 1012 | (modify-syntax-entry ?\" "\"" php-mode-syntax-table) | 1079 | (modify-syntax-entry ?\" "\"" php-mode-syntax-table) |
| @@ -1082,8 +1149,10 @@ PHP heredoc." | |||
| 1082 | (setq c-at-vsemi-p-fn 'php-c-at-vsemi-p) | 1149 | (setq c-at-vsemi-p-fn 'php-c-at-vsemi-p) |
| 1083 | (setq c-vsemi-status-unknown-p 'php-c-vsemi-status-unknown-p) | 1150 | (setq c-vsemi-status-unknown-p 'php-c-vsemi-status-unknown-p) |
| 1084 | 1151 | ||
| 1085 | (set (make-local-variable 'syntax-begin-function) | 1152 | ;; syntax-begin-function is obsolete in Emacs 25.1 |
| 1086 | 'c-beginning-of-syntax) | 1153 | (with-no-warnings |
| 1154 | (set (make-local-variable 'syntax-begin-function) | ||
| 1155 | 'c-beginning-of-syntax)) | ||
| 1087 | 1156 | ||
| 1088 | ;; We map the php-{beginning,end}-of-defun functions so that they | 1157 | ;; We map the php-{beginning,end}-of-defun functions so that they |
| 1089 | ;; replace the similar commands that we inherit from CC Mode. | 1158 | ;; replace the similar commands that we inherit from CC Mode. |
| @@ -1358,6 +1427,8 @@ a completion list." | |||
| 1358 | php-manual-url | 1427 | php-manual-url |
| 1359 | (format "%smanual/%s/" php-site-url php-manual-url)))) | 1428 | (format "%smanual/%s/" php-site-url php-manual-url)))) |
| 1360 | 1429 | ||
| 1430 | |||
| 1431 | ;;; Font Lock | ||
| 1361 | (defconst php-phpdoc-type-keywords | 1432 | (defconst php-phpdoc-type-keywords |
| 1362 | (list "string" "integer" "int" "boolean" "bool" "float" | 1433 | (list "string" "integer" "int" "boolean" "bool" "float" |
| 1363 | "double" "object" "mixed" "array" "resource" "$this" | 1434 | "double" "object" "mixed" "array" "resource" "$this" |
| @@ -1369,21 +1440,21 @@ a completion list." | |||
| 1369 | 1440 | ||
| 1370 | (defconst php-phpdoc-font-lock-doc-comments | 1441 | (defconst php-phpdoc-font-lock-doc-comments |
| 1371 | `(("{@[-[:alpha:]]+\\s-\\([^}]*\\)}" ; "{@foo ...}" markup. | 1442 | `(("{@[-[:alpha:]]+\\s-\\([^}]*\\)}" ; "{@foo ...}" markup. |
| 1372 | (0 'php-annotations-annotation-face prepend nil) | 1443 | (0 php-doc-annotation-tag-face prepend nil) |
| 1373 | (1 'font-lock-string-face prepend nil)) | 1444 | (1 php-string-face prepend nil)) |
| 1374 | (,(rx "$" (in "A-Za-z_") (* (in "0-9A-Za-z_"))) | 1445 | (,(rx "$" (in "A-Za-z_") (* (in "0-9A-Za-z_"))) |
| 1375 | 0 font-lock-variable-name-face prepend nil) | 1446 | 0 php-variable-name-face prepend nil) |
| 1376 | (,(concat "\\s-@" (regexp-opt php-phpdoc-type-tags) "\\s-+" | 1447 | (,(concat "\\s-@" (regexp-opt php-phpdoc-type-tags) "\\s-+" |
| 1377 | "\\(" (rx (+ (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+") | 1448 | "\\(" (rx (+ (? "?") (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+") |
| 1378 | 1 font-lock-string-face prepend nil) | 1449 | 1 php-string-face prepend nil) |
| 1379 | (,(concat "\\(?:|\\|\\s-\\)\\(" | 1450 | (,(concat "\\(?:|\\|\\?\\|\\s-\\)\\(" |
| 1380 | (regexp-opt php-phpdoc-type-keywords 'words) | 1451 | (regexp-opt php-phpdoc-type-keywords 'words) |
| 1381 | "\\)") | 1452 | "\\)") |
| 1382 | 1 font-lock-type-face prepend nil) | 1453 | 1 font-lock-type-face prepend nil) |
| 1383 | ("https?://[^\n\t ]+" | 1454 | ("https?://[^\n\t ]+" |
| 1384 | 0 'link prepend nil) | 1455 | 0 'link prepend nil) |
| 1385 | ("^\\(?:/\\*\\)?\\(?:\\s \\|\\*\\)*\\(@[[:alpha:]][-[:alpha:]\\]*\\)" ; "@foo ..." markup. | 1456 | ("^\\(?:/\\*\\)?\\(?:\\s \\|\\*\\)*\\(@[[:alpha:]][-[:alpha:]\\]*\\)" ; "@foo ..." markup. |
| 1386 | 1 'php-annotations-annotation-face prepend nil))) | 1457 | 1 php-doc-annotation-tag-face prepend nil))) |
| 1387 | 1458 | ||
| 1388 | (defvar php-phpdoc-font-lock-keywords | 1459 | (defvar php-phpdoc-font-lock-keywords |
| 1389 | `((,(lambda (limit) | 1460 | `((,(lambda (limit) |
| @@ -1408,11 +1479,11 @@ a completion list." | |||
| 1408 | ("->\\(\\sw+\\)\\s-*(" 1 'default) | 1479 | ("->\\(\\sw+\\)\\s-*(" 1 'default) |
| 1409 | 1480 | ||
| 1410 | ;; Highlight special variables | 1481 | ;; Highlight special variables |
| 1411 | ("\\$\\(this\\|that\\)\\_>" 1 font-lock-constant-face) | 1482 | ("\\$\\(this\\|that\\)\\_>" 1 php-constant-face) |
| 1412 | ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 font-lock-variable-name-face) | 1483 | ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 php-variable-name-face) |
| 1413 | 1484 | ||
| 1414 | ;; Highlight function/method names | 1485 | ;; Highlight function/method names |
| 1415 | ("\\<function\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1 font-lock-function-name-face) | 1486 | ("\\<function\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1 php-function-name-face) |
| 1416 | 1487 | ||
| 1417 | ;; The dollar sign should not get a variable-name face, below | 1488 | ;; The dollar sign should not get a variable-name face, below |
| 1418 | ;; pattern resets the face to default in case cc-mode sets the | 1489 | ;; pattern resets the face to default in case cc-mode sets the |
| @@ -1425,7 +1496,7 @@ a completion list." | |||
| 1425 | ("(\\(array\\))" 1 font-lock-type-face) | 1496 | ("(\\(array\\))" 1 font-lock-type-face) |
| 1426 | 1497 | ||
| 1427 | ;; Support the ::class constant in PHP5.6 | 1498 | ;; Support the ::class constant in PHP5.6 |
| 1428 | ("\\sw+::\\(class\\)" 1 font-lock-constant-face)) | 1499 | ("\\sw+::\\(class\\)" 1 php-constant-face)) |
| 1429 | 1500 | ||
| 1430 | ;; cc-mode patterns | 1501 | ;; cc-mode patterns |
| 1431 | (c-lang-const c-matchers-3 php) | 1502 | (c-lang-const c-matchers-3 php) |
| @@ -1439,15 +1510,15 @@ a completion list." | |||
| 1439 | ;; not in $obj->var() | 1510 | ;; not in $obj->var() |
| 1440 | ("->\\(\\sw+\\)\\s-*(" 1 'default) | 1511 | ("->\\(\\sw+\\)\\s-*(" 1 'default) |
| 1441 | 1512 | ||
| 1442 | ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 font-lock-variable-name-face) | 1513 | ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 php-variable-name-face) |
| 1443 | 1514 | ||
| 1444 | ;; Highlight all upper-cased symbols as constant | 1515 | ;; Highlight all upper-cased symbols as constant |
| 1445 | ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 font-lock-constant-face) | 1516 | ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 php-constant-face) |
| 1446 | 1517 | ||
| 1447 | ;; Highlight all statically accessed class names as constant, | 1518 | ;; Highlight all statically accessed class names as constant, |
| 1448 | ;; another valid option would be using type-face, but using | 1519 | ;; another valid option would be using type-face, but using |
| 1449 | ;; constant-face because this is how it works in c++-mode. | 1520 | ;; constant-face because this is how it works in c++-mode. |
| 1450 | ("\\(\\sw+\\)::" 1 font-lock-constant-face) | 1521 | ("\\(\\sw+\\)::" 1 php-constant-face) |
| 1451 | 1522 | ||
| 1452 | ;; Highlight class name after "use .. as" | 1523 | ;; Highlight class name after "use .. as" |
| 1453 | ("\\<as\\s-+\\(\\sw+\\)" 1 font-lock-type-face) | 1524 | ("\\<as\\s-+\\(\\sw+\\)" 1 font-lock-type-face) |
| @@ -1475,7 +1546,7 @@ a completion list." | |||
| 1475 | ;; | 1546 | ;; |
| 1476 | ;; Note that starting a file with <% breaks indentation, a | 1547 | ;; Note that starting a file with <% breaks indentation, a |
| 1477 | ;; limitation we can/should live with. | 1548 | ;; limitation we can/should live with. |
| 1478 | (,(regexp-opt '("?>" "<?" "<%" "%>")) 0 font-lock-preprocessor-face))) | 1549 | (,(regexp-opt '("?>" "<?" "<%" "%>")) 0 php-php-tag-face))) |
| 1479 | "Detailed highlighting for PHP mode.") | 1550 | "Detailed highlighting for PHP mode.") |
| 1480 | 1551 | ||
| 1481 | (defvar php-font-lock-keywords php-font-lock-keywords-3 | 1552 | (defvar php-font-lock-keywords php-font-lock-keywords-3 |
| @@ -1517,9 +1588,6 @@ The output will appear in the buffer *PHP*." | |||
| 1517 | (call-process php-executable nil php-buffer nil "-r" cleaned-php-code)))) | 1588 | (call-process php-executable nil php-buffer nil "-r" cleaned-php-code)))) |
| 1518 | 1589 | ||
| 1519 | 1590 | ||
| 1520 | (defface php-annotations-annotation-face '((t . (:inherit font-lock-constant-face))) | ||
| 1521 | "Face used to highlight annotations.") | ||
| 1522 | |||
| 1523 | (defconst php-string-interpolated-variable-regexp | 1591 | (defconst php-string-interpolated-variable-regexp |
| 1524 | "{\\$[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}\\|\\${\\sw+}\\|\\$\\sw+") | 1592 | "{\\$[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}\\|\\${\\sw+}\\|\\$\\sw+") |
| 1525 | 1593 | ||
| @@ -1528,7 +1596,7 @@ The output will appear in the buffer *PHP*." | |||
| 1528 | (let ((quoted-stuff (nth 3 (syntax-ppss)))) | 1596 | (let ((quoted-stuff (nth 3 (syntax-ppss)))) |
| 1529 | (when (and quoted-stuff (member quoted-stuff '(?\" ?`))) | 1597 | (when (and quoted-stuff (member quoted-stuff '(?\" ?`))) |
| 1530 | (put-text-property (match-beginning 0) (match-end 0) | 1598 | (put-text-property (match-beginning 0) (match-end 0) |
| 1531 | 'face 'font-lock-variable-name-face)))) | 1599 | 'face 'php-variable-name-face)))) |
| 1532 | nil) | 1600 | nil) |
| 1533 | 1601 | ||
| 1534 | (eval-after-load 'php-mode | 1602 | (eval-after-load 'php-mode |
