summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/php-mode.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/php-mode.el')
-rw-r--r--.emacs.d/lisp/php-mode.el225
1 files changed, 148 insertions, 77 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el
index 5cbc0d1..d568d90 100644
--- a/.emacs.d/lisp/php-mode.el
+++ b/.emacs.d/lisp/php-mode.el
@@ -5,18 +5,19 @@
5;; 2011, 2012, 2013, 2014, 2015, 2016, 2017 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;; Maintainer: USAMI Kenta <tadsan@zonu.me>
8;; URL: https://github.com/ejmr/php-mode 9;; URL: https://github.com/ejmr/php-mode
9;; Version: 1.18.3 10;; Keywords: languages php
11;; Version: 1.18.4
10;; Package-Requires: ((emacs "24") (cl-lib "0.5")) 12;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
13;; License: GPL-3.0-or-later
11 14
12(defconst php-mode-version-number "1.18.3" 15(defconst php-mode-version-number "1.18.4"
13 "PHP Mode version number.") 16 "PHP Mode version number.")
14 17
15(defconst php-mode-modified "2017-06-22" 18(defconst php-mode-modified "2018-01-30"
16 "PHP Mode build date.") 19 "PHP Mode build date.")
17 20
18;;; License
19
20;; This file is free software; you can redistribute it and/or 21;; This file is free software; you can redistribute it and/or
21;; modify it under the terms of the GNU General Public License 22;; modify it under the terms of the GNU General Public License
22;; as published by the Free Software Foundation; either version 3 23;; as published by the Free Software Foundation; either version 3
@@ -32,14 +33,24 @@
32;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 33;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
33;; 02110-1301, USA. 34;; 02110-1301, USA.
34 35
35;;; Usage 36;;; Commentary:
36 37
37;; Put this file in your Emacs lisp path (eg. site-lisp) and add to 38;; PHP Mode is a major mode for editing PHP source code. It's an
39;; extension of C mode; thus it inherits all C mode's navigation
40;; functionality. But it colors according to the PHP grammar and
41;; indents according to the PEAR coding guidelines. It also includes
42;; a couple handy IDE-type features such as documentation search and a
43;; source and class browser.
44
45;; ## Usage
46
47;; Put this file in your Emacs Lisp path (eg. site-lisp) and add to
38;; your .emacs file: 48;; your .emacs file:
39;; 49
40;; (require 'php-mode) 50;; (require 'php-mode)
41 51
42;; To use abbrev-mode, add lines like this: 52;; To use abbrev-mode, add lines like this:
53
43;; (add-hook 'php-mode-hook 54;; (add-hook 'php-mode-hook
44;; '(lambda () (define-abbrev php-mode-abbrev-table "ex" "extends"))) 55;; '(lambda () (define-abbrev php-mode-abbrev-table "ex" "extends")))
45 56
@@ -47,19 +58,10 @@
47 58
48;; Many options available under Help:Customize 59;; Many options available under Help:Customize
49;; Options specific to php-mode are in 60;; Options specific to php-mode are in
50;; Programming/Languages/Php 61;; Programming/Languages/PHP
51;; Since it inherits much functionality from c-mode, look there too 62;; Since it inherits much functionality from c-mode, look there too
52;; Programming/Languages/C 63;; Programming/Languages/C
53 64
54;;; Commentary:
55
56;; PHP Mode is a major mode for editing PHP source code. It's an
57;; extension of C mode; thus it inherits all C mode's navigation
58;; functionality. But it colors according to the PHP grammar and
59;; indents according to the PEAR coding guidelines. It also includes
60;; a couple handy IDE-type features such as documentation search and a
61;; source and class browser.
62
63;;; Code: 65;;; Code:
64 66
65(require 'cc-mode) 67(require 'cc-mode)
@@ -79,8 +81,10 @@
79(require 'flymake) 81(require 'flymake)
80(require 'etags) 82(require 'etags)
81(require 'speedbar) 83(require 'speedbar)
84(require 'imenu)
82 85
83(require 'cl-lib) 86(require 'cl-lib)
87(require 'mode-local)
84 88
85(eval-when-compile 89(eval-when-compile
86 (require 'regexp-opt) 90 (require 'regexp-opt)
@@ -114,7 +118,7 @@
114;; Local variables 118;; Local variables
115;;;###autoload 119;;;###autoload
116(defgroup php nil 120(defgroup php nil
117 "Major mode `php-mode' for editing PHP code." 121 "Major mode for editing PHP code."
118 :tag "PHP" 122 :tag "PHP"
119 :prefix "php-" 123 :prefix "php-"
120 :group 'languages 124 :group 'languages
@@ -171,7 +175,7 @@ Turning this on will open it whenever `php-mode' is loaded."
171 "\\)\\>[^_]?")) 175 "\\)\\>[^_]?"))
172 176
173(defun php-mode-extra-constants-set(sym value) 177(defun php-mode-extra-constants-set(sym value)
174 "Apply the list of extra constant keywords VALUE. 178 "Apply the list of extra constant keywords `VALUE'.
175 179
176This function is called when the custom variable php-extra-constants 180This function is called when the custom variable php-extra-constants
177is updated. The web-mode-extra-constants list is appended to the list 181is updated. The web-mode-extra-constants list is appended to the list
@@ -187,7 +191,7 @@ of constants when set."
187 (set sym value)) 191 (set sym value))
188 192
189(defcustom php-lineup-cascaded-calls nil 193(defcustom php-lineup-cascaded-calls nil
190 "Indent chained method calls to the previous line" 194 "Indent chained method calls to the previous line."
191 :type 'boolean) 195 :type 'boolean)
192 196
193;;;###autoload 197;;;###autoload
@@ -219,7 +223,7 @@ which will be the name of the method."
219 "\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(")) 223 "\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*("))
220 224
221(defun php-create-regexp-for-classlike (type) 225(defun php-create-regexp-for-classlike (type)
222 "Accepts a `type' of a 'classlike' object as a string, such as 226 "Accepts a `TYPE' of a 'classlike' object as a string, such as
223'class' or 'interface', and returns a regexp as a string which 227'class' or 'interface', and returns a regexp as a string which
224can be used to match against definitions for that classlike." 228can be used to match against definitions for that classlike."
225 (concat 229 (concat
@@ -255,15 +259,25 @@ can be used to match against definitions for that classlike."
255 "\\<\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*=\\s-*function\\s-*(" 1) 259 "\\<\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*=\\s-*function\\s-*(" 1)
256 ("Named Functions" 260 ("Named Functions"
257 "^\\s-*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1)) 261 "^\\s-*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1))
258 "Imenu generic expression for PHP Mode. See `imenu-generic-expression'.") 262 "Imenu generic expression for PHP Mode. See `imenu-generic-expression'.")
259 263
260(defcustom php-site-url "http://php.net/" 264(defcustom php-do-not-use-semantic-imenu t
265 "Customize `imenu-create-index-function' for `php-mode'.
266
267If using `semantic-mode' `imenu-create-index-function' will be
268set to `semantic-create-imenu-index' due to `c-mode' being its
269parent. Set this variable to t if you want to use
270`imenu-default-create-index-function' even with `semantic-mode'
271enabled."
272 :type 'boolean)
273
274(defcustom php-site-url "https://secure.php.net/"
261 "Default PHP.net site URL. 275 "Default PHP.net site URL.
262 276
263The URL to use open PHP manual and search word. 277The URL to use open PHP manual and search word.
264You can find a mirror site closer to you." 278You can find a mirror site closer to you."
265 :type 'string 279 :type 'string
266 :link '(url-link :tag "List of Mirror Sites" "http://php.net/mirrors.php")) 280 :link '(url-link :tag "List of Mirror Sites" "https://secure.php.net/mirrors.php"))
267 281
268(defcustom php-manual-url 'en 282(defcustom php-manual-url 'en
269 "URL at which to find PHP manual. 283 "URL at which to find PHP manual.
@@ -335,7 +349,7 @@ Turning this on will force PEAR rules on all PHP files."
335mumamo-mode turned on. Detects if there are any HTML tags in the 349mumamo-mode turned on. Detects if there are any HTML tags in the
336buffer before warning, but this is is not very smart; e.g. if you 350buffer before warning, but this is is not very smart; e.g. if you
337have any tags inside a PHP string, it will be fooled." 351have any tags inside a PHP string, it will be fooled."
338 :type '(choice (const :tag "Warg" t) (const "Don't warn" nil))) 352 :type '(choice (const :tag "Warn" t) (const "Don't warn" nil)))
339 353
340(defcustom php-mode-coding-style 'pear 354(defcustom php-mode-coding-style 'pear
341 "Select default coding style to use with php-mode. 355 "Select default coding style to use with php-mode.
@@ -373,6 +387,31 @@ This variable can take one of the following symbol values:
373 (message "PHP Mode %s of %s" 387 (message "PHP Mode %s of %s"
374 php-mode-version-number php-mode-modified)) 388 php-mode-version-number php-mode-modified))
375 389
390(defvar php-available-project-root-files
391 '((projectile ".projectile")
392 (composer "composer.json" "composer.lock")
393 (git ".git")
394 (mercurial ".hg")
395 (subversion ".svn")
396 ;; NOTICE: This method does not detect the top level of .editorconfig
397 ;; However, we can integrate it by adding the editorconfig.el's API.
398 ;;(editorconfig . ".editorconfig")
399 ))
400
401;;;###autoload
402(progn
403 (defvar php-project-root 'auto
404 "Method of searching for the top level directory.
405
406`auto' (default)
407 Try to search file in order of `php-available-project-root-files'.
408
409SYMBOL
410 Key of `php-available-project-root-files'.")
411 (make-variable-buffer-local 'php-project-root)
412 (put 'php-project-root 'safe-local-variable
413 #'(lambda (v) (assq v php-available-project-root-files))))
414
376(defvar php-mode-map 415(defvar php-mode-map
377 (let ((map (make-sparse-keymap))) 416 (let ((map (make-sparse-keymap)))
378 ;; (define-key map [menu-bar php] 417 ;; (define-key map [menu-bar php]
@@ -427,7 +466,7 @@ This variable can take one of the following symbol values:
427 ;; choice. 466 ;; choice.
428 (define-key map [tab] 'indent-for-tab-command) 467 (define-key map [tab] 'indent-for-tab-command)
429 map) 468 map)
430 "Keymap for `php-mode'") 469 "Keymap for `php-mode'.")
431 470
432(c-lang-defconst c-mode-menu 471(c-lang-defconst c-mode-menu
433 php (append '(["Complete function name" php-complete-function t] 472 php (append '(["Complete function name" php-complete-function t]
@@ -442,6 +481,16 @@ This variable can take one of the following symbol values:
442(c-lang-defconst c-vsemi-status-unknown-p-fn 481(c-lang-defconst c-vsemi-status-unknown-p-fn
443 php 'php-c-vsemi-status-unknown-p) 482 php 'php-c-vsemi-status-unknown-p)
444 483
484(c-lang-defconst c-get-state-before-change-functions
485 php nil)
486
487(c-lang-defconst c-before-font-lock-functions
488 php (let (functions)
489 (when (fboundp #'c-change-expand-fl-region)
490 (cl-pushnew 'c-change-expand-fl-region functions))
491 (when (fboundp #'c-depropertize-new-text)
492 (cl-pushnew 'c-depropertize-new-text functions))))
493
445;; Make php-mode recognize opening tags as preprocessor macro's. 494;; Make php-mode recognize opening tags as preprocessor macro's.
446;; 495;;
447;; This is a workaround, the tags must be recognized as something 496;; This is a workaround, the tags must be recognized as something
@@ -653,8 +702,7 @@ but only if the setting is enabled"
653 (tab-width . 4))) 702 (tab-width . 4)))
654 703
655(defun php-enable-pear-coding-style () 704(defun php-enable-pear-coding-style ()
656 "Sets up php-mode to use the coding styles preferred for PEAR 705 "Set up php-mode to use the coding styles preferred for PEAR code and modules."
657code and modules."
658 (interactive) 706 (interactive)
659 (php-set-style "pear")) 707 (php-set-style "pear"))
660 708
@@ -668,8 +716,7 @@ code and modules."
668 (php-style-delete-trailing-whitespace . t))) 716 (php-style-delete-trailing-whitespace . t)))
669 717
670(defun php-enable-drupal-coding-style () 718(defun php-enable-drupal-coding-style ()
671 "Makes php-mode use coding styles that are preferable for 719 "Make php-mode use coding styles that are preferable for working with Drupal."
672working with Drupal."
673 (interactive) 720 (interactive)
674 (php-set-style "drupal")) 721 (php-set-style "drupal"))
675 722
@@ -683,8 +730,7 @@ working with Drupal."
683 (fill-column . 78))) 730 (fill-column . 78)))
684 731
685(defun php-enable-wordpress-coding-style () 732(defun php-enable-wordpress-coding-style ()
686 "Makes php-mode use coding styles that are preferable for 733 "Make php-mode use coding styles that are preferable for working with Wordpress."
687working with Wordpress."
688 (interactive) 734 (interactive)
689 (php-set-style "wordpress")) 735 (php-set-style "wordpress"))
690 736
@@ -697,8 +743,7 @@ working with Wordpress."
697 (require-final-newline . t))) 743 (require-final-newline . t)))
698 744
699(defun php-enable-symfony2-coding-style () 745(defun php-enable-symfony2-coding-style ()
700 "Makes php-mode use coding styles that are preferable for 746 "Make php-mode use coding styles that are preferable for working with Symfony2."
701working with Symfony2."
702 (interactive) 747 (interactive)
703 (php-set-style "symfony2")) 748 (php-set-style "symfony2"))
704 749
@@ -713,7 +758,7 @@ working with Symfony2."
713 (php-style-delete-trailing-whitespace . t))) 758 (php-style-delete-trailing-whitespace . t)))
714 759
715(defun php-enable-psr2-coding-style () 760(defun php-enable-psr2-coding-style ()
716 "Makes php-mode comply to the PSR-2 coding style" 761 "Make php-mode comply to the PSR-2 coding style."
717 (interactive) 762 (interactive)
718 (php-set-style "psr2")) 763 (php-set-style "psr2"))
719 764
@@ -882,7 +927,7 @@ This is was done due to the problem reported here:
882 ) 927 )
883 928
884(defun php-lineup-string-cont (langelem) 929(defun php-lineup-string-cont (langelem)
885 "Line up string toward equal sign or dot 930 "Line up string toward equal sign or dot.
886e.g. 931e.g.
887$str = 'some' 932$str = 'some'
888 . 'string'; 933 . 'string';
@@ -916,22 +961,19 @@ this ^ lineup"
916 (beginning-of-line) 961 (beginning-of-line)
917 (if (looking-at-p "\\s-*;\\s-*$") 0 '+))) 962 (if (looking-at-p "\\s-*;\\s-*$") 0 '+)))
918 963
919(defconst php-heredoc-start-re 964(eval-and-compile
920 "<<<\\(?:\\w+\\|'\\w+'\\)$" 965 (defconst php-heredoc-start-re
921 "Regular expression for the start of a PHP heredoc.") 966 "<<<\\(?:\\w+\\|'\\w+'\\)$"
967 "Regular expression for the start of a PHP heredoc."))
922 968
923(defun php-heredoc-end-re (heredoc-start) 969(defun php-heredoc-end-re (heredoc-start)
924 "Build a regular expression for the end of a heredoc started by 970 "Build a regular expression for the end of a heredoc started by the string HEREDOC-START."
925the string HEREDOC-START."
926 ;; Extract just the identifier without <<< and quotes. 971 ;; Extract just the identifier without <<< and quotes.
927 (string-match "\\w+" heredoc-start) 972 (string-match "\\w+" heredoc-start)
928 (concat "^\\(" (match-string 0 heredoc-start) "\\)\\W")) 973 (concat "^\\(" (match-string 0 heredoc-start) "\\)\\W"))
929 974
930(defun php-syntax-propertize-function (start end) 975(defun php-syntax-propertize-function (start end)
931 "Apply propertize rules from START to END." 976 "Apply propertize rules from START to END."
932 ;; (defconst php-syntax-propertize-function
933 ;; (syntax-propertize-rules
934 ;; (php-heredoc-start-re (0 (ignore (php-heredoc-syntax))))))
935 (goto-char start) 977 (goto-char start)
936 (while (and (< (point) end) 978 (while (and (< (point) end)
937 (re-search-forward php-heredoc-start-re end t)) 979 (re-search-forward php-heredoc-start-re end t))
@@ -940,7 +982,12 @@ the string HEREDOC-START."
940 (while (re-search-forward "['\"]" end t) 982 (while (re-search-forward "['\"]" end t)
941 (when (php-in-comment-p) 983 (when (php-in-comment-p)
942 (c-put-char-property (match-beginning 0) 984 (c-put-char-property (match-beginning 0)
943 'syntax-table (string-to-syntax "_"))))) 985 'syntax-table (string-to-syntax "_"))))
986 (funcall
987 (syntax-propertize-rules
988 ("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\""))
989 ("\\('\\)\\(\\\\.\\|[^'\n\\]\\)*\\('\\)" (1 "\"") (3 "\"")))
990 start end))
944 991
945(defun php-heredoc-syntax () 992(defun php-heredoc-syntax ()
946 "Mark the boundaries of searched heredoc." 993 "Mark the boundaries of searched heredoc."
@@ -953,8 +1000,7 @@ the string HEREDOC-START."
953 (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "|"))) 1000 (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "|")))
954 1001
955(defun php-syntax-propertize-extend-region (start end) 1002(defun php-syntax-propertize-extend-region (start end)
956 "Extend the propertize region if START or END falls inside a 1003 "Extend the propertize region if START or END falls inside a PHP heredoc."
957PHP heredoc."
958 (let ((new-start) 1004 (let ((new-start)
959 (new-end)) 1005 (new-end))
960 (goto-char start) 1006 (goto-char start)
@@ -1105,6 +1151,28 @@ After setting the stylevars run hooks according to STYLENAME
1105 1151
1106(put 'php-set-style 'interactive-form (interactive-form 'c-set-style)) 1152(put 'php-set-style 'interactive-form (interactive-form 'c-set-style))
1107 1153
1154(defun php-mode-debug ()
1155 "Display informations useful for debugging PHP Mode."
1156 (interactive)
1157 (message "--- PHP-MODE DEBUG BEGIN ---")
1158 (message "versions: %s; %s" (emacs-version) (php-mode-version))
1159 (message "major-mode: %s" major-mode)
1160 (message "minor-modes: %s" (cl-remove-if
1161 (lambda (s) (string-match-p "global" (symbol-name s)))
1162 minor-mode-list))
1163 (message "variables: %s"
1164 (cl-loop for v in '(indent-tabs-mode tab-width)
1165 collect (list v (symbol-value v))))
1166 (message "custom variables: %s"
1167 (cl-loop for (v type) in (custom-group-members 'php nil)
1168 if (eq type 'custom-variable)
1169 collect (list v (symbol-value v))))
1170 (message "c-indentation-style: %s" c-indentation-style)
1171 (message "c-style-variables: %s" (c-get-style-variables c-indentation-style nil))
1172 (message "--- PHP-MODE DEBUG END ---")
1173 (switch-to-buffer "*Messages*")
1174 (goto-char (point-max)))
1175
1108;;;###autoload 1176;;;###autoload
1109(define-derived-mode php-mode c-mode "PHP" 1177(define-derived-mode php-mode c-mode "PHP"
1110 "Major mode for editing PHP code. 1178 "Major mode for editing PHP code.
@@ -1129,14 +1197,9 @@ After setting the stylevars run hooks according to STYLENAME
1129 (modify-syntax-entry ?\n "> b" php-mode-syntax-table) 1197 (modify-syntax-entry ?\n "> b" php-mode-syntax-table)
1130 (modify-syntax-entry ?$ "'" php-mode-syntax-table) 1198 (modify-syntax-entry ?$ "'" php-mode-syntax-table)
1131 1199
1132 (set (make-local-variable 'syntax-propertize-via-font-lock) 1200 (set (make-local-variable 'syntax-propertize-function) #'php-syntax-propertize-function)
1133 '(("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\""))
1134 ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\""))))
1135
1136 (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) 1201 (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions)
1137 #'php-syntax-propertize-extend-region) 1202 #'php-syntax-propertize-extend-region)
1138 (set (make-local-variable 'syntax-propertize-function)
1139 #'php-syntax-propertize-function)
1140 1203
1141 (setq imenu-generic-expression php-imenu-generic-expression) 1204 (setq imenu-generic-expression php-imenu-generic-expression)
1142 1205
@@ -1151,11 +1214,10 @@ After setting the stylevars run hooks according to STYLENAME
1151 1214
1152 (php-set-style (symbol-name php-mode-coding-style)) 1215 (php-set-style (symbol-name php-mode-coding-style))
1153 1216
1154 (if (or php-mode-force-pear 1217 (when (or php-mode-force-pear
1155 (and (stringp buffer-file-name) 1218 (and (stringp buffer-file-name)
1156 (string-match "PEAR\\|pear" 1219 (string-match "PEAR\\|pear" buffer-file-name)
1157 (buffer-file-name)) 1220 (string-match "\\.php\\'" buffer-file-name)))
1158 (string-match "\\.php$" (buffer-file-name))))
1159 (php-set-style "pear")) 1221 (php-set-style "pear"))
1160 1222
1161 (setq indent-line-function 'php-cautious-indent-line) 1223 (setq indent-line-function 'php-cautious-indent-line)
@@ -1191,6 +1253,13 @@ After setting the stylevars run hooks according to STYLENAME
1191 (save-excursion 1253 (save-excursion
1192 (php-syntax-propertize-function (point-min) (point-max)))))) 1254 (php-syntax-propertize-function (point-min) (point-max))))))
1193 1255
1256(defvar-mode-local php-mode imenu-create-index-function
1257 (if php-do-not-use-semantic-imenu
1258 #'imenu-default-create-index-function
1259 (require 'semantic/imenu)
1260 #'semantic-create-imenu-index)
1261 "Imenu index function for PHP.")
1262
1194 1263
1195;; Define function name completion function 1264;; Define function name completion function
1196(defvar php-completion-table nil 1265(defvar php-completion-table nil
@@ -1476,8 +1545,8 @@ a completion list."
1476 1545
1477(defvar php-phpdoc-font-lock-keywords 1546(defvar php-phpdoc-font-lock-keywords
1478 `((,(lambda (limit) 1547 `((,(lambda (limit)
1479 (c-font-lock-doc-comments "/\\*\\*" limit 1548 (c-font-lock-doc-comments "/\\*\\*" limit
1480 php-phpdoc-font-lock-doc-comments))))) 1549 php-phpdoc-font-lock-doc-comments)))))
1481 1550
1482(defconst php-font-lock-keywords-1 (c-lang-const c-matchers-1 php) 1551(defconst php-font-lock-keywords-1 (c-lang-const c-matchers-1 php)
1483 "Basic highlighting for PHP Mode.") 1552 "Basic highlighting for PHP Mode.")
@@ -1515,9 +1584,13 @@ a completion list."
1515 ;; - when used as a type hint 1584 ;; - when used as a type hint
1516 ;; - when used as a return type 1585 ;; - when used as a return type
1517 ("(\\(array\\))" 1 font-lock-type-face) 1586 ("(\\(array\\))" 1 font-lock-type-face)
1518 ("\\b\\(array\\)\\s-+\\$" 1 font-lock-type-face) 1587 ("\\b\\(array\\)\\s-+&?\\$" 1 font-lock-type-face)
1519 (")\\s-*:\\s-*\\??\\(array\\)\\b" 1 font-lock-type-face) 1588 (")\\s-*:\\s-*\\??\\(array\\)\\b" 1 font-lock-type-face)
1520 1589
1590 ;; namespaces
1591 ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face)
1592 ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant)
1593
1521 ;; Support the ::class constant in PHP5.6 1594 ;; Support the ::class constant in PHP5.6
1522 ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant))) 1595 ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant)))
1523 1596
@@ -1610,7 +1683,7 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
1610 1683
1611 1684
1612(defun php-send-region (start end) 1685(defun php-send-region (start end)
1613 "Send the region between `start' and `end' to PHP for execution. 1686 "Send the region between `START' and `END' to PHP for execution.
1614The output will appear in the buffer *PHP*." 1687The output will appear in the buffer *PHP*."
1615 (interactive "r") 1688 (interactive "r")
1616 (let ((php-buffer (get-buffer-create "*PHP*")) 1689 (let ((php-buffer (get-buffer-create "*PHP*"))
@@ -1658,20 +1731,6 @@ The output will appear in the buffer *PHP*."
1658 (delete-char 1)))) 1731 (delete-char 1))))
1659 1732
1660(ad-activate 'fixup-whitespace) 1733(ad-activate 'fixup-whitespace)
1661
1662;; Advice `font-lock-fontify-keywords-region' to support namespace
1663;; separators in class names. Use word syntax for backslashes when
1664;; doing keyword fontification, but not when doing syntactic
1665;; fontification because that breaks \ as escape character in strings.
1666;;
1667;; Special care is taken to restore the original syntax, because we
1668;; want \ not to be word for functions like forward-word.
1669(defadvice font-lock-fontify-keywords-region (around backslash-as-word activate)
1670 "Fontify keywords with backslash as word character."
1671 (let ((old-syntax (string (char-syntax ?\\))))
1672 (modify-syntax-entry ?\\ "w")
1673 ad-do-it
1674 (modify-syntax-entry ?\\ old-syntax)))
1675 1734
1676 1735
1677(defcustom php-class-suffix-when-insert "::" 1736(defcustom php-class-suffix-when-insert "::"
@@ -1697,6 +1756,18 @@ The output will appear in the buffer *PHP*."
1697 (match-string-no-properties 1)))) 1756 (match-string-no-properties 1))))
1698 1757
1699;;;###autoload 1758;;;###autoload
1759(defun php-project-get-root-dir ()
1760 "Return path to current PHP project."
1761 (let ((detect-method (if (stringp php-project-root)
1762 (list php-project-root)
1763 (if (eq php-project-root 'auto)
1764 (cl-loop for m in php-available-project-root-files
1765 append (cdr m))
1766 (cdr-safe (assq php-project-root php-available-project-root-files))))))
1767 (cl-loop for m in detect-method
1768 thereis (locate-dominating-file default-directory m))))
1769
1770;;;###autoload
1700(defun php-current-class () 1771(defun php-current-class ()
1701 "Insert current class name if cursor in class context." 1772 "Insert current class name if cursor in class context."
1702 (interactive) 1773 (interactive)