summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/php-mode.el
diff options
context:
space:
mode:
authorSimeon Simeonov2017-04-24 12:23:56 +0200
committerSimeon Simeonov2017-04-24 12:23:56 +0200
commit633aa066a900607361b85b110db9ac387b5f258b (patch)
tree2617f1f46d1d19a70eee2731e8970e19e1d107c0 /.emacs.d/lisp/php-mode.el
parent489e9034087868a46dc9a3f6c4298090cb4395ea (diff)
php-mode yasnippet upgrade
Diffstat (limited to '.emacs.d/lisp/php-mode.el')
-rw-r--r--.emacs.d/lisp/php-mode.el158
1 files changed, 102 insertions, 56 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el
index 9498d4d..12aa8c0 100644
--- a/.emacs.d/lisp/php-mode.el
+++ b/.emacs.d/lisp/php-mode.el
@@ -12,7 +12,7 @@
12(defconst php-mode-version-number "1.18.3" 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-04-04" 15(defconst php-mode-modified "2017-04-19"
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 php-constant-face)))) 182 'php-mode `((,(php-mode-extra-constants-create-regexp php-extra-constants) 1 'php-constant))))
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 php-constant-face)))) 186 'php-mode `((,(php-mode-extra-constants-create-regexp value) 1 'php-constant))))
187 (set sym value)) 187 (set sym value))
188 188
189(defcustom php-lineup-cascaded-calls nil 189(defcustom php-lineup-cascaded-calls nil
@@ -490,7 +490,7 @@ This variable can take one of the following symbol values:
490 490
491(c-lang-defconst c-primitive-type-kwds 491(c-lang-defconst c-primitive-type-kwds
492 php '("int" "integer" "bool" "boolean" "float" "double" "real" 492 php '("int" "integer" "bool" "boolean" "float" "double" "real"
493 "string" "object")) 493 "string" "object" "void"))
494 494
495(c-lang-defconst c-class-decl-kwds 495(c-lang-defconst c-class-decl-kwds
496 "Keywords introducing declarations where the following block (if any) 496 "Keywords introducing declarations where the following block (if any)
@@ -552,7 +552,6 @@ PHP does not have an \"enum\"-like keyword."
552 "array" 552 "array"
553 "callable" 553 "callable"
554 "iterable" 554 "iterable"
555 "void"
556 "as" 555 "as"
557 "break" 556 "break"
558 "catch all" 557 "catch all"
@@ -1006,58 +1005,95 @@ PHP heredoc."
1006 :group 'php 1005 :group 'php
1007 :group 'faces) 1006 :group 'faces)
1008 1007
1009(defvar php-string-face 'php-string-face) 1008(defface php-string '((t (:inherit font-lock-string-face)))
1010(defvar php-keyword-face 'php-keyword-face)
1011(defvar php-builtin-face 'php-builtin-face)
1012(defvar php-function-name-face 'php-function-name-face)
1013(defvar php-variable-name-face 'php-variable-name-face)
1014(defvar php-type-face 'php-type-face)
1015(defvar php-constant-face 'php-constant-face)
1016(defvar php-php-tag-face 'php-php-tag-face)
1017(defvar php-doc-annotation-tag-face 'php-doc-annotation-tag-face)
1018(defvar php-doc-class-name-face 'php-doc-class-name-face)
1019
1020(defface php-string-face '((t (:inherit font-lock-string-face)))
1021 "PHP Mode face used to highlight string literals." 1009 "PHP Mode face used to highlight string literals."
1022 :group 'php-faces) 1010 :group 'php-faces)
1023 1011
1024(defface php-keyword-face '((t (:inherit font-lock-keyword-face))) 1012(defface php-keyword '((t (:inherit font-lock-keyword-face)))
1025 "PHP Mode face used to highlight keywords." 1013 "PHP Mode face used to highlight keywords."
1026 :group 'php-faces) 1014 :group 'php-faces)
1027 1015
1028(defface php-builtin-face '((t (:inherit font-lock-builtin-face))) 1016(defface php-builtin '((t (:inherit font-lock-builtin-face)))
1029 "PHP Mode face used to highlight builtins." 1017 "PHP Mode face used to highlight builtins."
1030 :group 'php-faces) 1018 :group 'php-faces)
1031 1019
1032(defface php-function-name-face '((t (:inherit font-lock-function-name-face))) 1020(defface php-function-name '((t (:inherit font-lock-function-name-face)))
1033 "PHP Mode face used to highlight function names." 1021 "PHP Mode face used to highlight function names."
1034 :group 'php-faces) 1022 :group 'php-faces)
1035 1023
1036(defface php-variable-name-face '((t (:inherit font-lock-variable-name-face))) 1024(defface php-function-call '((t (:inherit default)))
1025 "PHP Mode face used to highlight function names in calles."
1026 :group 'php-faces)
1027
1028(defface php-method-call '((t (:inherit php-function-call)))
1029 "PHP Mode face used to highlight method names in calles."
1030 :group 'php-faces)
1031
1032(defface php-static-method-call '((t (:inherit php-method-call)))
1033 "PHP Mode face used to highlight static method names in calles."
1034 :group 'php-faces)
1035
1036(defface php-variable-name '((t (:inherit font-lock-variable-name-face)))
1037 "PHP Mode face used to highlight variable names." 1037 "PHP Mode face used to highlight variable names."
1038 :group 'php-faces) 1038 :group 'php-faces)
1039 1039
1040(defface php-type-face '((t (:inherit font-lock-type-face))) 1040(defface php-property-name '((t (:inherit php-variable-name-face)))
1041 "PHP Mode face used to highlight property names."
1042 :group 'php-faces)
1043
1044(defface php-variable-sigil '((t (:inherit default)))
1045 "PHP Mode face used to highlight variable sigils ($)."
1046 :group 'php-faces)
1047
1048(defface php-object-op '((t (:inherit default)))
1049 "PHP Mode face used to object operators (->)."
1050 :group 'php-faces)
1051
1052(defface php-paamayim-nekudotayim '((t (:inherit default)))
1053 "PHP Mode face used to highlight \"Paamayim Nekudotayim\" scope resolution operators (::)."
1054 :group 'php-faces)
1055
1056(defface php-type '((t (:inherit font-lock-type-face)))
1041 "PHP Mode face used to highlight types." 1057 "PHP Mode face used to highlight types."
1042 :group 'php-faces) 1058 :group 'php-faces)
1043 1059
1044(defface php-constant-face '((t (:inherit font-lock-constant-face))) 1060(defface php-constant '((t (:inherit font-lock-constant-face)))
1045 "PHP Mode face used to highlight constants." 1061 "PHP Mode face used to highlight constants."
1046 :group 'php-faces) 1062 :group 'php-faces)
1047 1063
1048(defface php-php-tag-face '((t (:inherit font-lock-constant-face))) 1064(defface php-$this '((t (:inherit php-constant)))
1065 "PHP Mode face used to highlight $this variables."
1066 :group 'php-faces)
1067
1068(defface php-$this-sigil '((t (:inherit php-constant)))
1069 "PHP Mode face used to highlight sigils($) of $this variable."
1070 :group 'php-faces)
1071
1072(defface php-php-tag '((t (:inherit font-lock-constant-face)))
1049 "PHP Mode face used to highlight PHP tags." 1073 "PHP Mode face used to highlight PHP tags."
1050 :group 'php-faces) 1074 :group 'php-faces)
1051 1075
1052(defface php-doc-annotation-tag-face '((t . (:inherit font-lock-constant-face))) 1076(defface php-doc-annotation-tag '((t . (:inherit font-lock-constant-face)))
1053 "Face used to highlight annotation tags in doc-comment." 1077 "Face used to highlight annotation tags in doc-comment."
1054 :group 'php-faces) 1078 :group 'php-faces)
1055 1079
1056(defface php-doc-class-name-face '((t (:inherit php-string-face))) 1080(defface php-doc-variable-sigil '((t (:inherit font-lock-variable-name-face)))
1081 "PHP Mode face used to highlight variable sigils($)."
1082 :group 'php-faces)
1083
1084(defface php-doc-$this '((t (:inherit php-type)))
1085 "PHP Mode face used to highlight $this variable in doc-comment."
1086 :group 'php-faces)
1087
1088(defface php-doc-$this-sigil '((t (:inherit php-type)))
1089 "PHP Mode face used to highlight sigil of $this variable in doc-comment."
1090 :group 'php-faces)
1091
1092(defface php-doc-class-name '((t (:inherit php-string)))
1057 "Face used to class names in doc-comment." 1093 "Face used to class names in doc-comment."
1058 :group 'php-faces) 1094 :group 'php-faces)
1059 1095
1060(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag-face "1.19.0") 1096(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0")
1061 1097
1062 1098
1063;;;###autoload 1099;;;###autoload
@@ -1070,12 +1106,12 @@ PHP heredoc."
1070 (c-init-language-vars php-mode) 1106 (c-init-language-vars php-mode)
1071 (c-common-init 'php-mode) 1107 (c-common-init 'php-mode)
1072 1108
1073 (set (make-local-variable font-lock-string-face) php-string-face) 1109 (set (make-local-variable font-lock-string-face) 'php-string)
1074 (set (make-local-variable font-lock-keyword-face) php-keyword-face) 1110 (set (make-local-variable font-lock-keyword-face) 'php-keyword)
1075 (set (make-local-variable font-lock-builtin-face) php-builtin-face) 1111 (set (make-local-variable font-lock-builtin-face) 'php-builtin)
1076 (set (make-local-variable font-lock-function-name-face) php-function-name-face) 1112 (set (make-local-variable font-lock-function-name-face) 'php-function-name)
1077 (set (make-local-variable font-lock-variable-name-face) php-variable-name-face) 1113 (set (make-local-variable font-lock-variable-name-face) 'php-variable-name)
1078 (set (make-local-variable font-lock-constant-face) php-constant-face) 1114 (set (make-local-variable font-lock-constant-face) 'php-constant)
1079 1115
1080 (modify-syntax-entry ?_ "_" php-mode-syntax-table) 1116 (modify-syntax-entry ?_ "_" php-mode-syntax-table)
1081 (modify-syntax-entry ?` "\"" php-mode-syntax-table) 1117 (modify-syntax-entry ?` "\"" php-mode-syntax-table)
@@ -1435,7 +1471,7 @@ a completion list."
1435;; Font Lock 1471;; Font Lock
1436(defconst php-phpdoc-type-keywords 1472(defconst php-phpdoc-type-keywords
1437 (list "string" "integer" "int" "boolean" "bool" "float" 1473 (list "string" "integer" "int" "boolean" "bool" "float"
1438 "double" "object" "mixed" "array" "resource" "$this" 1474 "double" "object" "mixed" "array" "resource"
1439 "void" "null" "false" "true" "self" "static" 1475 "void" "null" "false" "true" "self" "static"
1440 "callable" "iterable" "number")) 1476 "callable" "iterable" "number"))
1441 1477
@@ -1444,13 +1480,15 @@ a completion list."
1444 1480
1445(defconst php-phpdoc-font-lock-doc-comments 1481(defconst php-phpdoc-font-lock-doc-comments
1446 `(("{@[-[:alpha:]]+\\s-\\([^}]*\\)}" ; "{@foo ...}" markup. 1482 `(("{@[-[:alpha:]]+\\s-\\([^}]*\\)}" ; "{@foo ...}" markup.
1447 (0 php-doc-annotation-tag-face prepend nil) 1483 (0 'php-doc-annotation-tag prepend nil)
1448 (1 php-string-face prepend nil)) 1484 (1 'php-string prepend nil))
1449 (,(rx "$" (in "A-Za-z_") (* (in "0-9A-Za-z_"))) 1485 (,(rx (group "$") (group (in "A-Za-z_") (* (in "0-9A-Za-z_"))))
1450 0 php-variable-name-face prepend nil) 1486 (1 'php-doc-variable-sigil prepend nil)
1487 (2 'php-variable-name prepend nil))
1488 ("\\(\\$\\)\\(this\\)\\>" (1 'php-doc-$this-sigil prepend nil) (2 'php-doc-$this prepend nil))
1451 (,(concat "\\s-@" (regexp-opt php-phpdoc-type-tags) "\\s-+" 1489 (,(concat "\\s-@" (regexp-opt php-phpdoc-type-tags) "\\s-+"
1452 "\\(" (rx (+ (? "?") (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+") 1490 "\\(" (rx (+ (? "?") (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+")
1453 1 php-string-face prepend nil) 1491 1 'php-string prepend nil)
1454 (,(concat "\\(?:|\\|\\?\\|\\s-\\)\\(" 1492 (,(concat "\\(?:|\\|\\?\\|\\s-\\)\\("
1455 (regexp-opt php-phpdoc-type-keywords 'words) 1493 (regexp-opt php-phpdoc-type-keywords 'words)
1456 "\\)") 1494 "\\)")
@@ -1458,7 +1496,7 @@ a completion list."
1458 ("https?://[^\n\t ]+" 1496 ("https?://[^\n\t ]+"
1459 0 'link prepend nil) 1497 0 'link prepend nil)
1460 ("^\\(?:/\\*\\)?\\(?:\\s \\|\\*\\)*\\(@[[:alpha:]][-[:alpha:]\\]*\\)" ; "@foo ..." markup. 1498 ("^\\(?:/\\*\\)?\\(?:\\s \\|\\*\\)*\\(@[[:alpha:]][-[:alpha:]\\]*\\)" ; "@foo ..." markup.
1461 1 php-doc-annotation-tag-face prepend nil))) 1499 1 'php-doc-annotation-tag prepend nil)))
1462 1500
1463(defvar php-phpdoc-font-lock-keywords 1501(defvar php-phpdoc-font-lock-keywords
1464 `((,(lambda (limit) 1502 `((,(lambda (limit)
@@ -1480,27 +1518,32 @@ a completion list."
1480 '( 1518 '(
1481 ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but 1519 ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but
1482 ;; not in $obj->var() 1520 ;; not in $obj->var()
1483 ("->\\(\\sw+\\)\\s-*(" 1 'default) 1521 ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call))
1484 1522
1485 ;; Highlight special variables 1523 ;; Highlight special variables
1486 ("\\$\\(this\\|that\\)\\_>" 1 php-constant-face) 1524 ("\\(\\$\\)\\(this\\|that\\)\\_>" (1 'php-$this-sigil) (2 'php-$this))
1487 ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 php-variable-name-face) 1525 ("\\(\\$\\)\\([a-zA-Z0-9_]+\\)" (1 'php-variable-sigil) (2 'php-variable-name))
1526 ("\\(->\\)\\([a-zA-Z0-9_]+\\)" (1 'php-object-op) (2 'php-property-name))
1488 1527
1489 ;; Highlight function/method names 1528 ;; Highlight function/method names
1490 ("\\<function\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1 php-function-name-face) 1529 ("\\<function\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1 'php-function-name)
1491 1530
1492 ;; The dollar sign should not get a variable-name face, below 1531 ;; The dollar sign should not get a variable-name face, below
1493 ;; pattern resets the face to default in case cc-mode sets the 1532 ;; pattern resets the face to default in case cc-mode sets the
1494 ;; variable-name face (cc-mode does this for variables prefixed 1533 ;; variable-name face (cc-mode does this for variables prefixed
1495 ;; with type, like in arglist) 1534 ;; with type, like in arglist)
1496 ("\\(\\$\\)\\(\\sw+\\)" 1 'default) 1535 ("\\(\\$\\)\\(\\sw+\\)" 1 'php-variable-sigil)
1497 1536
1498 ;; Array is a keyword, except when used as cast, so that (int) 1537 ;; Array is a keyword, except in the following situations:
1499 ;; and (array) look the same 1538 ;; - when used as cast, so that (int) and (array) look the same
1539 ;; - when used as a type hint
1540 ;; - when used as a return type
1500 ("(\\(array\\))" 1 font-lock-type-face) 1541 ("(\\(array\\))" 1 font-lock-type-face)
1542 ("\\b\\(array\\)\\s-+\\$" 1 font-lock-type-face)
1543 (")\\s-*:\\s-*\\??\\(array\\)\\b" 1 font-lock-type-face)
1501 1544
1502 ;; Support the ::class constant in PHP5.6 1545 ;; Support the ::class constant in PHP5.6
1503 ("\\sw+::\\(class\\)" 1 php-constant-face)) 1546 ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant)))
1504 1547
1505 ;; cc-mode patterns 1548 ;; cc-mode patterns
1506 (c-lang-const c-matchers-3 php) 1549 (c-lang-const c-matchers-3 php)
@@ -1512,17 +1555,17 @@ a completion list."
1512 `( 1555 `(
1513 ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but 1556 ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but
1514 ;; not in $obj->var() 1557 ;; not in $obj->var()
1515 ("->\\(\\sw+\\)\\s-*(" 1 'default) 1558 ("->\\(\\sw+\\)\\s-*(" 1 'php-method-call)
1516 1559
1517 ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 php-variable-name-face) 1560 ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 'php-property-name)
1518 1561
1519 ;; Highlight all upper-cased symbols as constant 1562 ;; Highlight all upper-cased symbols as constant
1520 ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 php-constant-face) 1563 ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant)
1521 1564
1522 ;; Highlight all statically accessed class names as constant, 1565 ;; Highlight all statically accessed class names as constant,
1523 ;; another valid option would be using type-face, but using 1566 ;; another valid option would be using type-face, but using
1524 ;; constant-face because this is how it works in c++-mode. 1567 ;; constant-face because this is how it works in c++-mode.
1525 ("\\(\\sw+\\)::" 1 php-constant-face) 1568 ("\\(\\sw+\\)\\(::\\)" (1 'php-constant) (2 'php-paamayim-nekudotayim))
1526 1569
1527 ;; Highlight class name after "use .. as" 1570 ;; Highlight class name after "use .. as"
1528 ("\\<as\\s-+\\(\\sw+\\)" 1 font-lock-type-face) 1571 ("\\<as\\s-+\\(\\sw+\\)" 1 font-lock-type-face)
@@ -1541,7 +1584,10 @@ a completion list."
1541 1 font-lock-type-face) 1584 1 font-lock-type-face)
1542 1585
1543 ;; Highlight return types in functions and methods. 1586 ;; Highlight return types in functions and methods.
1544 ("function.+:\\s-?\\(\\(?:\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face) 1587 ("function.+:\\s-?\\??\\(\\(?:\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face)
1588
1589 ;; Highlight class names used as nullable type hints
1590 ("\\?\\(\\(:?\\sw\\|\\s_\\)+\\)\\s-+\\$" 1 font-lock-type-face)
1545 1591
1546 ;; While c-opt-cpp-* highlights the <?php opening tags, it is not 1592 ;; While c-opt-cpp-* highlights the <?php opening tags, it is not
1547 ;; possible to make it highlight short open tags and closing tags 1593 ;; possible to make it highlight short open tags and closing tags
@@ -1550,7 +1596,7 @@ a completion list."
1550 ;; 1596 ;;
1551 ;; Note that starting a file with <% breaks indentation, a 1597 ;; Note that starting a file with <% breaks indentation, a
1552 ;; limitation we can/should live with. 1598 ;; limitation we can/should live with.
1553 (,(regexp-opt '("?>" "<?" "<%" "%>")) 0 php-php-tag-face))) 1599 (,(regexp-opt '("?>" "<?" "<%" "%>")) 0 'php-php-tag)))
1554 "Detailed highlighting for PHP mode.") 1600 "Detailed highlighting for PHP mode.")
1555 1601
1556(defvar php-font-lock-keywords php-font-lock-keywords-3 1602(defvar php-font-lock-keywords php-font-lock-keywords-3
@@ -1600,7 +1646,7 @@ The output will appear in the buffer *PHP*."
1600 (let ((quoted-stuff (nth 3 (syntax-ppss)))) 1646 (let ((quoted-stuff (nth 3 (syntax-ppss))))
1601 (when (and quoted-stuff (member quoted-stuff '(?\" ?`))) 1647 (when (and quoted-stuff (member quoted-stuff '(?\" ?`)))
1602 (put-text-property (match-beginning 0) (match-end 0) 1648 (put-text-property (match-beginning 0) (match-end 0)
1603 'face 'php-variable-name-face)))) 1649 'face 'php-variable-name))))
1604 nil) 1650 nil)
1605 1651
1606(eval-after-load 'php-mode 1652(eval-after-load 'php-mode
@@ -1635,7 +1681,7 @@ The output will appear in the buffer *PHP*."
1635;; Special care is taken to restore the original syntax, because we 1681;; Special care is taken to restore the original syntax, because we
1636;; want \ not to be word for functions like forward-word. 1682;; want \ not to be word for functions like forward-word.
1637(defadvice font-lock-fontify-keywords-region (around backslash-as-word activate) 1683(defadvice font-lock-fontify-keywords-region (around backslash-as-word activate)
1638 "Fontify keywords with backslash as word character" 1684 "Fontify keywords with backslash as word character."
1639 (let ((old-syntax (string (char-syntax ?\\)))) 1685 (let ((old-syntax (string (char-syntax ?\\))))
1640 (modify-syntax-entry ?\\ "w") 1686 (modify-syntax-entry ?\\ "w")
1641 ad-do-it 1687 ad-do-it