diff options
| author | Simeon Simeonov | 2019-12-19 14:30:16 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2019-12-19 14:30:16 +0100 |
| commit | 447890a7ea96da048fa720d313b32860c995e8bb (patch) | |
| tree | a5dbe162bbec074c5f0b9b637279bf5e772de1b6 /.emacs.d/lisp/php-mode.el | |
| parent | f781cd3408b85b321ad5bc78945a7f44fc3ec751 (diff) | |
Many changes...
Diffstat (limited to '.emacs.d/lisp/php-mode.el')
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 108 |
1 files changed, 77 insertions, 31 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index a339e17..9be3b55 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -444,8 +444,32 @@ In that case set to `NIL'." | |||
| 444 | (prefix "\\" "::"))) | 444 | (prefix "\\" "::"))) |
| 445 | 445 | ||
| 446 | (c-lang-defconst c-operators | 446 | (c-lang-defconst c-operators |
| 447 | php (delete '(postfix-if-paren "<" ">") | 447 | php `((prefix "new" "clone") |
| 448 | (c-lang-const c-operators))) | 448 | ,@(c-lang-const c-identifier-ops) |
| 449 | (postfix "->") | ||
| 450 | (postfix "++" "--" "[" "]" "(" ")") | ||
| 451 | (right-assoc "**") | ||
| 452 | (prefix "++" "--" "+" "-" "~" "(" ")" "@") | ||
| 453 | (prefix "instanceof") | ||
| 454 | (prefix "!") | ||
| 455 | (left-assoc "*" "/" "%") | ||
| 456 | (left-assoc "+" "-" ".") | ||
| 457 | (left-assoc "<<" ">>") | ||
| 458 | (left-assoc "<" ">" "<=" ">=") | ||
| 459 | (left-assoc "==" "!=" "===" "!==" "<>" "<=>") | ||
| 460 | (left-assoc "&") | ||
| 461 | (left-assoc "^") | ||
| 462 | (left-assoc "|") | ||
| 463 | (left-assoc "&&") | ||
| 464 | (left-assoc "||") | ||
| 465 | (right-assoc "??") | ||
| 466 | (left-assoc "?:") | ||
| 467 | (right-assoc-sequence "?" ":") | ||
| 468 | (right-assoc ,@(c-lang-const c-assignment-operators)) | ||
| 469 | (left-assoc "and") | ||
| 470 | (left-assoc "xor") | ||
| 471 | (left-assoc "or") | ||
| 472 | (left-assoc ","))) | ||
| 449 | 473 | ||
| 450 | ;; Allow '\' when scanning from open brace back to defining | 474 | ;; Allow '\' when scanning from open brace back to defining |
| 451 | ;; construct like class | 475 | ;; construct like class |
| @@ -950,31 +974,43 @@ this ^ lineup" | |||
| 950 | (goto-char (point-max))) | 974 | (goto-char (point-max))) |
| 951 | (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "|"))) | 975 | (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "|"))) |
| 952 | 976 | ||
| 977 | (defvar-local php-mode--propertize-extend-region-current nil | ||
| 978 | "Prevent undesirable recursion in PHP-SYNTAX-PROPERTIZE-EXTEND-REGION") | ||
| 979 | |||
| 953 | (defun php-syntax-propertize-extend-region (start end) | 980 | (defun php-syntax-propertize-extend-region (start end) |
| 954 | "Extend the propertize region if START or END falls inside a PHP heredoc." | 981 | "Extend the propertize region if START or END falls inside a PHP heredoc." |
| 955 | (let ((new-start) | 982 | (let ((pair (cons start end))) |
| 956 | (new-end)) | 983 | (when (not (member pair php-mode--propertize-extend-region-current)) |
| 957 | (goto-char start) | 984 | ;; re-search functions may trigger |
| 958 | (when (re-search-backward php-heredoc-start-re nil t) | 985 | ;; syntax-propertize-extend-region-functions to be called again, which in |
| 959 | (let ((maybe (point))) | 986 | ;; turn call this to be called again. |
| 960 | (when (and (re-search-forward | 987 | (push pair php-mode--propertize-extend-region-current) |
| 961 | (php-heredoc-end-re (match-string 0)) nil t) | 988 | (unwind-protect |
| 962 | (> (point) start)) | 989 | (let ((new-start) |
| 963 | (setq new-start maybe)))) | 990 | (new-end)) |
| 964 | (goto-char end) | 991 | (goto-char start) |
| 965 | (when (re-search-backward php-heredoc-start-re nil t) | 992 | (when (re-search-backward php-heredoc-start-re nil t) |
| 966 | (if (re-search-forward | 993 | (let ((maybe (point))) |
| 967 | (php-heredoc-end-re (match-string 0)) nil t) | 994 | (when (and (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) |
| 968 | (when (> (point) end) | 995 | (> (point) start)) |
| 969 | (setq new-end (point))) | 996 | (setq new-start maybe)))) |
| 970 | (setq new-end (point-max)))) | 997 | (goto-char end) |
| 971 | (when (or new-start new-end) | 998 | (when (re-search-backward php-heredoc-start-re nil t) |
| 972 | (cons (or new-start start) (or new-end end))))) | 999 | (if (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) |
| 1000 | (when (> (point) end) | ||
| 1001 | (setq new-end (point))) | ||
| 1002 | (setq new-end (point-max)))) | ||
| 1003 | (when (or new-start new-end) | ||
| 1004 | (cons (or new-start start) (or new-end end)))) | ||
| 1005 | ;; Cleanup | ||
| 1006 | (setq php-mode--propertize-extend-region-current | ||
| 1007 | (delete pair php-mode--propertize-extend-region-current)))))) | ||
| 973 | 1008 | ||
| 974 | (easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands" | 1009 | (easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands" |
| 975 | (cons "PHP" (c-lang-const c-mode-menu php))) | 1010 | (cons "PHP" (c-lang-const c-mode-menu php))) |
| 976 | 1011 | ||
| 977 | (defvar-local php-mode--delayed-set-style nil) | 1012 | (defvar-local php-mode--delayed-set-style nil) |
| 1013 | (defvar-local php-style-delete-trailing-whitespace nil) | ||
| 978 | 1014 | ||
| 979 | (defun php-set-style (stylename &optional dont-override) | 1015 | (defun php-set-style (stylename &optional dont-override) |
| 980 | "Set the current `php-mode' buffer to use the style STYLENAME. | 1016 | "Set the current `php-mode' buffer to use the style STYLENAME. |
| @@ -1029,7 +1065,8 @@ After setting the stylevars run hooks according to STYLENAME | |||
| 1029 | (when php-mode--delayed-set-style | 1065 | (when php-mode--delayed-set-style |
| 1030 | (let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style) | 1066 | (let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style) |
| 1031 | php-mode-coding-style))) | 1067 | php-mode-coding-style))) |
| 1032 | (prog1 (php-set-style (symbol-name coding-style)) | 1068 | (prog1 (when coding-style |
| 1069 | (php-set-style (symbol-name coding-style))) | ||
| 1033 | (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))) | 1070 | (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))) |
| 1034 | 1071 | ||
| 1035 | (defvar php-mode-syntax-table | 1072 | (defvar php-mode-syntax-table |
| @@ -1077,8 +1114,8 @@ After setting the stylevars run hooks according to STYLENAME | |||
| 1077 | (setq-local font-lock-constant-face 'php-constant) | 1114 | (setq-local font-lock-constant-face 'php-constant) |
| 1078 | 1115 | ||
| 1079 | (setq-local syntax-propertize-function #'php-syntax-propertize-function) | 1116 | (setq-local syntax-propertize-function #'php-syntax-propertize-function) |
| 1080 | (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) | 1117 | (add-hook 'syntax-propertize-extend-region-functions |
| 1081 | #'php-syntax-propertize-extend-region) | 1118 | #'php-syntax-propertize-extend-region t t) |
| 1082 | 1119 | ||
| 1083 | (setq imenu-generic-expression php-imenu-generic-expression) | 1120 | (setq imenu-generic-expression php-imenu-generic-expression) |
| 1084 | 1121 | ||
| @@ -1250,20 +1287,22 @@ current `tags-file-name'." | |||
| 1250 | nil))) | 1287 | nil))) |
| 1251 | 1288 | ||
| 1252 | (defun php-show-arglist () | 1289 | (defun php-show-arglist () |
| 1290 | "Show function arguments at cursor position." | ||
| 1253 | (interactive) | 1291 | (interactive) |
| 1254 | (let* ((tagname (php-get-pattern)) | 1292 | (let* ((tagname (php-get-pattern)) |
| 1255 | (buf (find-tag-noselect tagname nil nil)) | 1293 | (buf (find-tag-noselect tagname nil nil)) |
| 1256 | arglist) | 1294 | arglist) |
| 1257 | (with-current-buffer buf | 1295 | (with-current-buffer buf |
| 1258 | (goto-char (point-min)) | 1296 | (save-excursion |
| 1259 | (when (re-search-forward | 1297 | (goto-char (point-min)) |
| 1260 | (format "function\\s-+%s\\s-*(\\([^{]*\\))" tagname) | 1298 | (when (re-search-forward |
| 1261 | nil t) | 1299 | (format "function\\s-+%s\\s-*(\\([^{]*\\))" tagname) |
| 1262 | (setq arglist (buffer-substring-no-properties | 1300 | nil t) |
| 1263 | (match-beginning 1) (match-end 1))))) | 1301 | (setq arglist (buffer-substring-no-properties |
| 1302 | (match-beginning 1) (match-end 1)))))) | ||
| 1264 | (if arglist | 1303 | (if arglist |
| 1265 | (message "Arglist for %s: %s" tagname arglist) | 1304 | (message "Arglist for %s: %s" tagname arglist) |
| 1266 | (message "Unknown function: %s" tagname)))) | 1305 | (message "Unknown function: %s" tagname)))) |
| 1267 | 1306 | ||
| 1268 | (defcustom php-search-documentation-browser-function nil | 1307 | (defcustom php-search-documentation-browser-function nil |
| 1269 | "Function to display PHP documentation in a WWW browser. | 1308 | "Function to display PHP documentation in a WWW browser. |
| @@ -1464,7 +1503,14 @@ a completion list." | |||
| 1464 | ;; namespaces | 1503 | ;; namespaces |
| 1465 | ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face) | 1504 | ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face) |
| 1466 | ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant) | 1505 | ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant) |
| 1467 | 1506 | (,(eval-when-compile | |
| 1507 | (rx bol (* (syntax whitespace)) | ||
| 1508 | (or "private" "protected" "public") | ||
| 1509 | (+ (syntax whitespace)) | ||
| 1510 | (group (? "?") (+ (or "\\" (syntax word) (syntax symbol)))) | ||
| 1511 | (+ (syntax whitespace)) | ||
| 1512 | (: "$" (+ (or (syntax word) (syntax symbol)))))) | ||
| 1513 | 1 'php-class) | ||
| 1468 | ;; Support the ::class constant in PHP5.6 | 1514 | ;; Support the ::class constant in PHP5.6 |
| 1469 | ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-magical-constant)) | 1515 | ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-magical-constant)) |
| 1470 | 1516 | ||
