summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/php.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/php.el')
-rw-r--r--.emacs.d/lisp/php.el98
1 files changed, 97 insertions, 1 deletions
diff --git a/.emacs.d/lisp/php.el b/.emacs.d/lisp/php.el
index db9e46d..13f2cef 100644
--- a/.emacs.d/lisp/php.el
+++ b/.emacs.d/lisp/php.el
@@ -4,7 +4,7 @@
4 4
5;; Author: USAMI Kenta <tadsan@zonu.me> 5;; Author: USAMI Kenta <tadsan@zonu.me>
6;; Created: 5 Dec 2018 6;; Created: 5 Dec 2018
7;; Version: 1.21.2 7;; Version: 1.21.3
8;; Keywords: languages, php 8;; Keywords: languages, php
9;; Homepage: https://github.com/emacs-php/php-mode 9;; Homepage: https://github.com/emacs-php/php-mode
10;; Package-Requires: ((emacs "24.3") (cl-lib "0.5")) 10;; Package-Requires: ((emacs "24.3") (cl-lib "0.5"))
@@ -29,6 +29,7 @@
29 29
30;;; Code: 30;;; Code:
31(require 'flymake) 31(require 'flymake)
32(require 'php-project)
32 33
33;;;###autoload 34;;;###autoload
34(defgroup php nil 35(defgroup php nil
@@ -40,17 +41,23 @@
40 41
41(defcustom php-executable (or (executable-find "php") "/usr/bin/php") 42(defcustom php-executable (or (executable-find "php") "/usr/bin/php")
42 "The location of the PHP executable." 43 "The location of the PHP executable."
44 :group 'php
45 :tag "PHP Executable"
43 :type 'string) 46 :type 'string)
44 47
45(defcustom php-site-url "https://php.net/" 48(defcustom php-site-url "https://php.net/"
46 "Default PHP.net site URL. 49 "Default PHP.net site URL.
47 50
48The URL to use open PHP manual and search word." 51The URL to use open PHP manual and search word."
52 :group 'php
53 :tag "PHP Site URL"
49 :type 'string) 54 :type 'string)
50 55
51(defcustom php-manual-url 'en 56(defcustom php-manual-url 'en
52 "URL at which to find PHP manual. 57 "URL at which to find PHP manual.
53You can replace \"en\" with your ISO language code." 58You can replace \"en\" with your ISO language code."
59 :group 'php
60 :tag "PHP Manual URL"
54 :type '(choice (const :tag "English" 'en) 61 :type '(choice (const :tag "English" 'en)
55 (const :tag "Brazilian Portuguese" 'pt_BR) 62 (const :tag "Brazilian Portuguese" 'pt_BR)
56 (const :tag "Chinese (Simplified)" 'zh) 63 (const :tag "Chinese (Simplified)" 'zh)
@@ -66,6 +73,7 @@ You can replace \"en\" with your ISO language code."
66(defcustom php-search-url nil 73(defcustom php-search-url nil
67 "URL at which to search for documentation on a word." 74 "URL at which to search for documentation on a word."
68 :group 'php 75 :group 'php
76 :tag "PHP Search URL"
69 :type '(choice (string :tag "URL to search PHP documentation") 77 :type '(choice (string :tag "URL to search PHP documentation")
70 (const :tag "Use `php-site-url' variable" nil))) 78 (const :tag "Use `php-site-url' variable" nil)))
71 79
@@ -78,6 +86,41 @@ You can replace \"en\" with your ISO language code."
78 "Suffix for inserted namespace." 86 "Suffix for inserted namespace."
79 :group 'php 87 :group 'php
80 :type 'string) 88 :type 'string)
89
90(defcustom php-default-major-mode 'php-mode
91 "Major mode for editing PHP script."
92 :group 'php
93 :tag "PHP Default Major Mode"
94 :type 'function)
95
96(defcustom php-html-template-major-mode 'web-mode
97 "Major mode for editing PHP-HTML template."
98 :group 'php
99 :tag "PHP-HTML Template Major Mode"
100 :type 'function)
101
102(defcustom php-blade-template-major-mode 'web-mode
103 "Major mode for editing Blade template."
104 :group 'php
105 :tag "PHP Blade Template Major Mode"
106 :type 'function)
107
108(defcustom php-template-mode-alist
109 `(("\\.blade" . ,php-blade-template-major-mode)
110 ("\\.phpt\\'" . ,(if (fboundp 'phpt-mode) 'phpt-mode php-html-template-major-mode))
111 ("\\.phtml\\'" . ,php-html-template-major-mode))
112 "Automatically use another MAJOR-MODE when open template file."
113 :group 'php
114 :tag "PHP Template Mode Alist"
115 :type '(alist :key-type regexp :value-type function)
116 :link '(url-link :tag "web-mode" "http://web-mode.org/")
117 :link '(url-link :tag "phpt-mode" "https://github.com/emacs-php/phpt-mode"))
118
119(defcustom php-mode-maybe-hook nil
120 "List of functions to be executed on entry to `php-mode-maybe'."
121 :group 'php
122 :tag "PHP Mode Maybe Hook"
123 :type 'hook)
81 124
82;;; PHP Keywords 125;;; PHP Keywords
83(defconst php-magical-constants 126(defconst php-magical-constants
@@ -101,6 +144,11 @@ it is the character that will terminate the string, or t if the string should be
101 "Return character address of start of comment or string; nil if not in one." 144 "Return character address of start of comment or string; nil if not in one."
102 (nth 8 (syntax-ppss))) 145 (nth 8 (syntax-ppss)))
103 146
147(defsubst php-in-poly-php-html-mode ()
148 "Return T if current buffer is in `poly-html-mode'."
149 (and (boundp 'poly-php-html-mode)
150 (symbol-value 'poly-php-html-mode)))
151
104(defun php-create-regexp-for-method (visibility) 152(defun php-create-regexp-for-method (visibility)
105 "Make a regular expression for methods with the given VISIBILITY. 153 "Make a regular expression for methods with the given VISIBILITY.
106 154
@@ -187,6 +235,54 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
187 'flymake-php-init))))) 235 'flymake-php-init)))))
188 (list php-executable (cdr init)))) 236 (list php-executable (cdr init))))
189 237
238(defconst php-re-detect-html-tag
239 (eval-when-compile
240 (rx (or (: string-start (* (in space))
241 "<!"
242 (or "DOCTYPE" "doctype")
243 (+ (in space))
244 (or "HTML" "html"))
245 (: (or line-start
246 (: "<" (? "/")
247 (* (in space)) (+ (in alpha "-")) (* (in space)) ">"))
248 (: "<" (* (in space)) (+ (in alpha "-")) (* (in space)) ">"))))))
249
250(defun php-buffer-has-html-tag ()
251 "Return position of HTML tag or NIL in current buffer."
252 (save-excursion
253 (save-restriction
254 (widen)
255 (goto-char (point-min))
256 (re-search-forward php-re-detect-html-tag nil t))))
257
258(defun php-derivation-major-mode ()
259 "Return major mode for PHP file by file-name and its content."
260 (let ((mode (assoc-default buffer-file-name
261 php-template-mode-alist
262 #'string-match-p))
263 type)
264 (when (and (null mode) buffer-file-name
265 php-project-php-file-as-template)
266 (setq type (php-project-get-file-html-template-type buffer-file-name))
267 (cond
268 ((eq t type) (setq mode php-html-template-major-mode))
269 ((eq 'auto type)
270 (when (php-buffer-has-html-tag)
271 (setq mode php-html-template-major-mode)))))
272 (when (and mode (not (fboundp mode)))
273 (if (string-match-p "\\.blade\\." buffer-file-name)
274 (warn "php-mode is NOT support blade template. %s"
275 "Please install `web-mode' package")
276 (setq mode nil)))
277 (or mode php-default-major-mode)))
278
279;;;###autoload
280(defun php-mode-maybe ()
281 "Select PHP mode or other major mode."
282 (interactive)
283 (run-hooks php-mode-maybe-hook)
284 (funcall (php-derivation-major-mode)))
285
190;;;###autoload 286;;;###autoload
191(defun php-current-class () 287(defun php-current-class ()
192 "Insert current class name if cursor in class context." 288 "Insert current class name if cursor in class context."