summaryrefslogtreecommitdiff
path: root/.emacs.d
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d')
-rw-r--r--.emacs.d/lisp/lua-mode.el251
-rw-r--r--.emacs.d/lisp/php-face.el47
-rw-r--r--.emacs.d/lisp/php-mode.el154
-rw-r--r--.emacs.d/lisp/php-project.el35
-rw-r--r--.emacs.d/lisp/php-util-buffer.el135
-rw-r--r--.emacs.d/lisp/php.el207
-rw-r--r--.emacs.d/lisp/yasnippet.el14
7 files changed, 635 insertions, 208 deletions
diff --git a/.emacs.d/lisp/lua-mode.el b/.emacs.d/lisp/lua-mode.el
index af94a13..640e490 100644
--- a/.emacs.d/lisp/lua-mode.el
+++ b/.emacs.d/lisp/lua-mode.el
@@ -1,4 +1,4 @@
1;;; lua-mode.el --- a major-mode for editing Lua scripts 1;;; lua-mode.el --- a major-mode for editing Lua scripts -*- lexical-binding: t -*-
2 2
3;; Author: 2011-2013 immerrr <immerrr+lua@gmail.com> 3;; Author: 2011-2013 immerrr <immerrr+lua@gmail.com>
4;; 2010-2011 Reuben Thomas <rrt@sc3d.org> 4;; 2010-2011 Reuben Thomas <rrt@sc3d.org>
@@ -13,6 +13,7 @@
13;; 13;;
14;; URL: http://immerrr.github.com/lua-mode 14;; URL: http://immerrr.github.com/lua-mode
15;; Version: 20151025 15;; Version: 20151025
16;; Package-Requires: ((emacs "24.3"))
16;; 17;;
17;; This file is NOT part of Emacs. 18;; This file is NOT part of Emacs.
18;; 19;;
@@ -40,7 +41,7 @@
40 41
41;;; Commentary: 42;;; Commentary:
42 43
43;; lua-mode provides support for editing Lua, including automatical 44;; lua-mode provides support for editing Lua, including automatic
44;; indentation, syntactical font-locking, running interactive shell, 45;; indentation, syntactical font-locking, running interactive shell,
45;; interacting with `hs-minor-mode' and online documentation lookup. 46;; interacting with `hs-minor-mode' and online documentation lookup.
46 47
@@ -86,7 +87,7 @@
86 87
87;;; Code: 88;;; Code:
88(eval-when-compile 89(eval-when-compile
89 (require 'cl)) 90 (require 'cl-lib))
90 91
91(require 'comint) 92(require 'comint)
92(require 'newcomment) 93(require 'newcomment)
@@ -101,80 +102,120 @@
101 (require 'compile)) 102 (require 'compile))
102 103
103(eval-and-compile 104(eval-and-compile
104 (defvar lua-rx-constituents) 105 (if (fboundp #'rx-let)
105 (defvar rx-parent) 106 (progn
107 ;; Emacs 27+ way of customizing rx
108 (defvar lua--rx-bindings)
109
110 (setq
111 lua--rx-bindings
112 '((symbol (&rest x) (seq symbol-start (or x) symbol-end))
113 (ws (* (any " \t")))
114 (ws+ (+ (any " \t")))
115
116 (lua-name (symbol (seq (+ (any alpha "_")) (* (any alnum "_")))))
117 (lua-funcname (seq lua-name (* ws "." ws lua-name)
118 (opt ws ":" ws lua-name)))
119 (lua-funcheader
120 ;; Outer (seq ...) is here to shy-group the definition
121 (seq (or (seq (symbol "function") ws (group-n 1 lua-funcname))
122 (seq (group-n 1 lua-funcname) ws "=" ws
123 (symbol "function")))))
124 (lua-number
125 (seq (or (seq (+ digit) (opt ".") (* digit))
126 (seq (* digit) (opt ".") (+ digit)))
127 (opt (regexp "[eE][+-]?[0-9]+"))))
128 (lua-assignment-op (seq "=" (or buffer-end (not (any "=")))))
129 (lua-token (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
130 ">" "=" ";" ":" "," "." ".." "..."))
131 (lua-keyword
132 (symbol "and" "break" "do" "else" "elseif" "end" "for" "function"
133 "goto" "if" "in" "local" "not" "or" "repeat" "return"
134 "then" "until" "while"))))
135
136 (defmacro lua-rx (&rest regexps)
137 (eval `(rx-let ,lua--rx-bindings
138 (rx ,@regexps))))
106 139
107 (defun lua-rx-to-string (form &optional no-group) 140 (defun lua-rx-to-string (form &optional no-group)
108 "Lua-specific replacement for `rx-to-string'. 141 (rx-let-eval lua--rx-bindings
142 (rx-to-string form no-group))))
143 (progn
144 ;; Pre-Emacs 27 way of customizing rx
145 (defvar lua-rx-constituents)
146 (defvar rx-parent)
147
148 (defun lua-rx-to-string (form &optional no-group)
149 "Lua-specific replacement for `rx-to-string'.
109 150
110See `rx-to-string' documentation for more information FORM and 151See `rx-to-string' documentation for more information FORM and
111NO-GROUP arguments." 152NO-GROUP arguments."
112 (let ((rx-constituents lua-rx-constituents)) 153 (let ((rx-constituents lua-rx-constituents))
113 (rx-to-string form no-group))) 154 (rx-to-string form no-group)))
114 155
115 (defmacro lua-rx (&rest regexps) 156 (defmacro lua-rx (&rest regexps)
116 "Lua-specific replacement for `rx'. 157 "Lua-specific replacement for `rx'.
117 158
118See `rx' documentation for more information about REGEXPS param." 159See `rx' documentation for more information about REGEXPS param."
119 (cond ((null regexps) 160 (cond ((null regexps)
120 (error "No regexp")) 161 (error "No regexp"))
121 ((cdr regexps) 162 ((cdr regexps)
122 (lua-rx-to-string `(and ,@regexps) t)) 163 (lua-rx-to-string `(and ,@regexps) t))
123 (t 164 (t
124 (lua-rx-to-string (car regexps) t)))) 165 (lua-rx-to-string (car regexps) t))))
125 166
126 (defun lua--new-rx-form (form) 167 (defun lua--new-rx-form (form)
127 "Add FORM definition to `lua-rx' macro. 168 "Add FORM definition to `lua-rx' macro.
128 169
129FORM is a cons (NAME . DEFN), see more in `rx-constituents' doc. 170FORM is a cons (NAME . DEFN), see more in `rx-constituents' doc.
130This function enables specifying new definitions using old ones: 171This function enables specifying new definitions using old ones:
131if DEFN is a list that starts with `:rx' symbol its second 172if DEFN is a list that starts with `:rx' symbol its second
132element is itself expanded with `lua-rx-to-string'. " 173element is itself expanded with `lua-rx-to-string'. "
133 (let ((name (car form)) 174 (let ((form-definition (cdr form)))
134 (form-definition (cdr form))) 175 (when (and (listp form-definition) (eq ':rx (car form-definition)))
135 (when (and (listp form-definition) (eq ':rx (car form-definition))) 176 (setcdr form (lua-rx-to-string (cadr form-definition) 'nogroup)))
136 (setcdr form (lua-rx-to-string (cadr form-definition) 'nogroup))) 177 (push form lua-rx-constituents)))
137 (push form lua-rx-constituents)))
138 178
139 (defun lua--rx-symbol (form) 179 (defun lua--rx-symbol (form)
140 ;; form is a list (symbol XXX ...) 180 ;; form is a list (symbol XXX ...)
141 ;; Skip initial 'symbol 181 ;; Skip initial 'symbol
142 (setq form (cdr form)) 182 (setq form (cdr form))
143 ;; If there's only one element, take it from the list, otherwise wrap the 183 ;; If there's only one element, take it from the list, otherwise wrap the
144 ;; whole list into `(or XXX ...)' form. 184 ;; whole list into `(or XXX ...)' form.
145 (setq form (if (eq 1 (length form)) 185 (setq form (if (eq 1 (length form))
146 (car form) 186 (car form)
147 (append '(or) form))) 187 (append '(or) form)))
148 (rx-form `(seq symbol-start ,form symbol-end) rx-parent)) 188 (and (fboundp 'rx-form) ; Silence Emacs 27's byte-compiler.
189 (rx-form `(seq symbol-start ,form symbol-end) rx-parent)))
149 190
150 (setq lua-rx-constituents (copy-sequence rx-constituents)) 191 (setq lua-rx-constituents (copy-sequence rx-constituents))
151 192
152 (mapc #'lua--new-rx-form 193 (mapc 'lua--new-rx-form
153 `((symbol lua--rx-symbol 1 nil) 194 `((symbol lua--rx-symbol 1 nil)
154 (ws . "[ \t]*") (ws+ . "[ \t]+") 195 (ws . "[ \t]*") (ws+ . "[ \t]+")
155 (lua-name :rx (symbol (regexp "[[:alpha:]_]+[[:alnum:]_]*"))) 196 (lua-name :rx (symbol (regexp "[[:alpha:]_]+[[:alnum:]_]*")))
156 (lua-funcname 197 (lua-funcname
157 :rx (seq lua-name (* ws "." ws lua-name) 198 :rx (seq lua-name (* ws "." ws lua-name)
158 (opt ws ":" ws lua-name))) 199 (opt ws ":" ws lua-name)))
159 (lua-funcheader 200 (lua-funcheader
160 ;; Outer (seq ...) is here to shy-group the definition 201 ;; Outer (seq ...) is here to shy-group the definition
161 :rx (seq (or (seq (symbol "function") ws (group-n 1 lua-funcname)) 202 :rx (seq (or (seq (symbol "function") ws (group-n 1 lua-funcname))
162 (seq (group-n 1 lua-funcname) ws "=" ws 203 (seq (group-n 1 lua-funcname) ws "=" ws
163 (symbol "function"))))) 204 (symbol "function")))))
164 (lua-number 205 (lua-number
165 :rx (seq (or (seq (+ digit) (opt ".") (* digit)) 206 :rx (seq (or (seq (+ digit) (opt ".") (* digit))
166 (seq (* digit) (opt ".") (+ digit))) 207 (seq (* digit) (opt ".") (+ digit)))
167 (opt (regexp "[eE][+-]?[0-9]+")))) 208 (opt (regexp "[eE][+-]?[0-9]+"))))
168 (lua-assignment-op 209 (lua-assignment-op
169 :rx (seq "=" (or buffer-end (not (any "="))))) 210 :rx (seq "=" (or buffer-end (not (any "=")))))
170 (lua-token 211 (lua-token
171 :rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<" 212 :rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
172 ">" "=" ";" ":" "," "." ".." "...")) 213 ">" "=" ";" ":" "," "." ".." "..."))
173 (lua-keyword 214 (lua-keyword
174 :rx (symbol "and" "break" "do" "else" "elseif" "end" "for" "function" 215 :rx (symbol "and" "break" "do" "else" "elseif" "end" "for" "function"
175 "goto" "if" "in" "local" "not" "or" "repeat" "return" 216 "goto" "if" "in" "local" "not" "or" "repeat" "return"
176 "then" "until" "while"))) 217 "then" "until" "while")))
177 )) 218 ))))
178 219
179 220
180;; Local variables 221;; Local variables
@@ -277,8 +318,7 @@ If the latter is nil, the keymap translates into `lua-mode-map' verbatim.")
277 318
278 319
279(defvar lua-mode-map 320(defvar lua-mode-map
280 (let ((result-map (make-sparse-keymap)) 321 (let ((result-map (make-sparse-keymap)))
281 prefix-key)
282 (unless (boundp 'electric-indent-chars) 322 (unless (boundp 'electric-indent-chars)
283 (mapc (lambda (electric-char) 323 (mapc (lambda (electric-char)
284 (define-key result-map 324 (define-key result-map
@@ -488,7 +528,7 @@ groups set according to next matched token:
488 528
489Blanks & comments between tokens are silently skipped. 529Blanks & comments between tokens are silently skipped.
490Groups 6-9 can be used in any of argument regexps." 530Groups 6-9 can be used in any of argument regexps."
491 (lexical-let* 531 (let*
492 ((delimited-matcher-re-template 532 ((delimited-matcher-re-template
493 "\\=\\(?2:.*?\\)\\(?:\\(?%s:\\(?4:%s\\)\\|\\(?5:%s\\)\\)\\|\\(?%s:\\(?1:%s\\)\\)\\)") 533 "\\=\\(?2:.*?\\)\\(?:\\(?%s:\\(?4:%s\\)\\|\\(?5:%s\\)\\)\\|\\(?%s:\\(?1:%s\\)\\)\\)")
494 ;; There's some magic to this regexp. It works as follows: 534 ;; There's some magic to this regexp. It works as follows:
@@ -515,7 +555,6 @@ Groups 6-9 can be used in any of argument regexps."
515 555
516 (lambda (end) 556 (lambda (end)
517 (let* ((prev-elt-p (match-beginning 1)) 557 (let* ((prev-elt-p (match-beginning 1))
518 (prev-sep-p (match-beginning 4))
519 (prev-end-p (match-beginning 5)) 558 (prev-end-p (match-beginning 5))
520 559
521 (regexp (if prev-elt-p sep-or-end-expected-re elt-expected-re)) 560 (regexp (if prev-elt-p sep-or-end-expected-re elt-expected-re))
@@ -567,7 +606,7 @@ Groups 6-9 can be used in any of argument regexps."
567 (,(lua-rx "::" ws lua-name ws "::") 606 (,(lua-rx "::" ws lua-name ws "::")
568 . font-lock-constant-face) 607 . font-lock-constant-face)
569 608
570 ;; Hightlights the name of the label in the "goto" statement like 609 ;; Highlights the name of the label in the "goto" statement like
571 ;; "goto label" 610 ;; "goto label"
572 (,(lua-rx (symbol (seq "goto" ws+ (group-n 1 lua-name)))) 611 (,(lua-rx (symbol (seq "goto" ws+ (group-n 1 lua-name))))
573 (1 font-lock-constant-face)) 612 (1 font-lock-constant-face))
@@ -669,9 +708,6 @@ Groups 6-9 can be used in any of argument regexps."
669 :abbrev-table lua-mode-abbrev-table 708 :abbrev-table lua-mode-abbrev-table
670 :syntax-table lua-mode-syntax-table 709 :syntax-table lua-mode-syntax-table
671 :group 'lua 710 :group 'lua
672 (setq comint-prompt-regexp lua-prompt-regexp)
673
674
675 (setq-local font-lock-defaults '(lua-font-lock-keywords ;; keywords 711 (setq-local font-lock-defaults '(lua-font-lock-keywords ;; keywords
676 nil ;; keywords-only 712 nil ;; keywords-only
677 nil ;; case-fold 713 nil ;; case-fold
@@ -900,7 +936,7 @@ Return the amount the indentation changed by."
900 (back-to-indentation) 936 (back-to-indentation)
901 (if (lua-comment-or-string-p) 937 (if (lua-comment-or-string-p)
902 (setq indent (lua-calculate-string-or-comment-indentation)) ;; just restore point position 938 (setq indent (lua-calculate-string-or-comment-indentation)) ;; just restore point position
903 (setq indent (max 0 (lua-calculate-indentation nil)))) 939 (setq indent (max 0 (lua-calculate-indentation))))
904 940
905 (when (not (equal indent (current-column))) 941 (when (not (equal indent (current-column)))
906 (delete-region (line-beginning-position) (point)) 942 (delete-region (line-beginning-position) (point))
@@ -981,8 +1017,8 @@ ignored, nil otherwise."
981Each token information entry is of the form: 1017Each token information entry is of the form:
982 KEYWORD FORWARD-MATCH-REGEXP BACKWARDS-MATCH-REGEXP TOKEN-TYPE 1018 KEYWORD FORWARD-MATCH-REGEXP BACKWARDS-MATCH-REGEXP TOKEN-TYPE
983KEYWORD is the token. 1019KEYWORD is the token.
984FORWARD-MATCH-REGEXP is a regexp that matches all possble tokens when going forward. 1020FORWARD-MATCH-REGEXP is a regexp that matches all possible tokens when going forward.
985BACKWARDS-MATCH-REGEXP is a regexp that matches all possble tokens when going backwards. 1021BACKWARDS-MATCH-REGEXP is a regexp that matches all possible tokens when going backwards.
986TOKEN-TYPE determines where the token occurs on a statement. open indicates that the token appears at start, close indicates that it appears at end, middle indicates that it is a middle type token, and middle-or-open indicates that it can appear both as a middle or an open type.") 1022TOKEN-TYPE determines where the token occurs on a statement. open indicates that the token appears at start, close indicates that it appears at end, middle indicates that it is a middle type token, and middle-or-open indicates that it can appear both as a middle or an open type.")
987 1023
988(defconst lua-indentation-modifier-regexp 1024(defconst lua-indentation-modifier-regexp
@@ -1009,12 +1045,12 @@ TOKEN-TYPE determines where the token occurs on a statement. open indicates that
1009 "Returns the relevant match regexp from token info" 1045 "Returns the relevant match regexp from token info"
1010 (cond 1046 (cond
1011 ((eq direction 'forward) (cadr token-info)) 1047 ((eq direction 'forward) (cadr token-info))
1012 ((eq direction 'backward) (caddr token-info)) 1048 ((eq direction 'backward) (nth 2 token-info))
1013 (t nil))) 1049 (t nil)))
1014 1050
1015(defun lua-get-token-type (token-info) 1051(defun lua-get-token-type (token-info)
1016 "Returns the relevant match regexp from token info" 1052 "Returns the relevant match regexp from token info"
1017 (cadddr token-info)) 1053 (nth 3 token-info))
1018 1054
1019(defun lua-backwards-to-block-begin-or-end () 1055(defun lua-backwards-to-block-begin-or-end ()
1020 "Move backwards to nearest block begin or end. Returns nil if not successful." 1056 "Move backwards to nearest block begin or end. Returns nil if not successful."
@@ -1101,8 +1137,11 @@ DIRECTION has to be either 'forward or 'backward."
1101(defun lua-goto-matching-block-token (&optional parse-start direction) 1137(defun lua-goto-matching-block-token (&optional parse-start direction)
1102 "Find block begion/end token matching the one at the point. 1138 "Find block begion/end token matching the one at the point.
1103This function moves the point to the token that matches the one 1139This function moves the point to the token that matches the one
1104at the current point. Returns the point position of the first character of 1140at the current point. Returns the point position of the first character of
1105the matching token if successful, nil otherwise." 1141the matching token if successful, nil otherwise.
1142
1143Optional PARSE-START is a position to which the point should be moved first.
1144DIRECTION has to be 'forward or 'backward ('forward by default)."
1106 (if parse-start (goto-char parse-start)) 1145 (if parse-start (goto-char parse-start))
1107 (let ((case-fold-search nil)) 1146 (let ((case-fold-search nil))
1108 (if (looking-at lua-indentation-modifier-regexp) 1147 (if (looking-at lua-indentation-modifier-regexp)
@@ -1114,7 +1153,10 @@ the matching token if successful, nil otherwise."
1114(defun lua-goto-matching-block (&optional noreport) 1153(defun lua-goto-matching-block (&optional noreport)
1115 "Go to the keyword balancing the one under the point. 1154 "Go to the keyword balancing the one under the point.
1116If the point is on a keyword/brace that starts a block, go to the 1155If the point is on a keyword/brace that starts a block, go to the
1117matching keyword that ends the block, and vice versa." 1156matching keyword that ends the block, and vice versa.
1157
1158If optional NOREPORT is non-nil, it won't flag an error if there
1159is no block open/close open."
1118 (interactive) 1160 (interactive)
1119 ;; search backward to the beginning of the keyword if necessary 1161 ;; search backward to the beginning of the keyword if necessary
1120 (if (eq (char-syntax (following-char)) ?w) 1162 (if (eq (char-syntax (following-char)) ?w)
@@ -1129,7 +1171,7 @@ matching keyword that ends the block, and vice versa."
1129 "Move 1 line forward (back if BACK is non-nil) skipping blank lines. 1171 "Move 1 line forward (back if BACK is non-nil) skipping blank lines.
1130 1172
1131Moves point 1 line forward (or backward) skipping lines that contain 1173Moves point 1 line forward (or backward) skipping lines that contain
1132no Lua code besides comments. The point is put to the beginning of 1174no Lua code besides comments. The point is put to the beginning of
1133the line. 1175the line.
1134 1176
1135Returns final value of point as integer or nil if operation failed." 1177Returns final value of point as integer or nil if operation failed."
@@ -1160,7 +1202,7 @@ Returns final value of point as integer or nil if operation failed."
1160 t) 1202 t)
1161 "\\)" 1203 "\\)"
1162 "\\s *\\=")) 1204 "\\s *\\="))
1163 "Regexp that matches the ending of a line that needs continuation 1205 "Regexp that matches the ending of a line that needs continuation.
1164 1206
1165This regexp starts from eol and looks for a binary operator or an unclosed 1207This regexp starts from eol and looks for a binary operator or an unclosed
1166block intro (i.e. 'for' without 'do' or 'if' without 'then') followed by 1208block intro (i.e. 'for' without 'do' or 'if' without 'then') followed by
@@ -1179,15 +1221,15 @@ an optional whitespace till the end of the line.")
1179 t) 1221 t)
1180 "\\($\\|[^" lua-operator-class "]\\)" 1222 "\\($\\|[^" lua-operator-class "]\\)"
1181 "\\)")) 1223 "\\)"))
1182 "Regexp that matches a line that continues previous one 1224 "Regexp that matches a line that continues previous one.
1183 1225
1184This regexp means, starting from point there is an optional whitespace followed 1226This regexp means, starting from point there is an optional whitespace followed
1185by Lua binary operator. Lua is very liberal when it comes to continuation line, 1227by Lua binary operator. Lua is very liberal when it comes to continuation line,
1186so we're safe to assume that every line that starts with a binop continues 1228so we're safe to assume that every line that starts with a binop continues
1187previous one even though it looked like an end-of-statement.") 1229previous one even though it looked like an end-of-statement.")
1188 1230
1189(defun lua-last-token-continues-p () 1231(defun lua-last-token-continues-p ()
1190 "Returns true if the last token on this line is a continuation token." 1232 "Return non-nil if the last token on this line is a continuation token."
1191 (let ((line-begin (line-beginning-position)) 1233 (let ((line-begin (line-beginning-position))
1192 (line-end (line-end-position))) 1234 (line-end (line-end-position)))
1193 (save-excursion 1235 (save-excursion
@@ -1201,7 +1243,7 @@ previous one even though it looked like an end-of-statement.")
1201 (re-search-backward lua-cont-eol-regexp line-begin t)))) 1243 (re-search-backward lua-cont-eol-regexp line-begin t))))
1202 1244
1203(defun lua-first-token-continues-p () 1245(defun lua-first-token-continues-p ()
1204 "Returns true if the first token on this line is a continuation token." 1246 "Return non-nil if the first token on this line is a continuation token."
1205 (let ((line-end (line-end-position))) 1247 (let ((line-end (line-end-position)))
1206 (save-excursion 1248 (save-excursion
1207 (beginning-of-line) 1249 (beginning-of-line)
@@ -1219,14 +1261,15 @@ previous one even though it looked like an end-of-statement.")
1219 "\\_>\\)"))) 1261 "\\_>\\)")))
1220 1262
1221(defun lua-first-token-starts-block-p () 1263(defun lua-first-token-starts-block-p ()
1222 "Returns true if the first token on this line is a block starter token." 1264 "Return non-nil if the first token on this line is a block starter token."
1223 (let ((line-end (line-end-position))) 1265 (let ((line-end (line-end-position)))
1224 (save-excursion 1266 (save-excursion
1225 (beginning-of-line) 1267 (beginning-of-line)
1226 (re-search-forward (concat "\\s *" lua-block-starter-regexp) line-end t)))) 1268 (re-search-forward (concat "\\s *" lua-block-starter-regexp) line-end t))))
1227 1269
1228(defun lua-is-continuing-statement-p (&optional parse-start) 1270(defun lua-is-continuing-statement-p (&optional parse-start)
1229 "Return non-nil if the line continues a statement. 1271 "Return non-nil if the line at PARSE-START continues a statement.
1272
1230More specifically, return the point in the line that is continued. 1273More specifically, return the point in the line that is continued.
1231The criteria for a continuing statement are: 1274The criteria for a continuing statement are:
1232 1275
@@ -1246,8 +1289,10 @@ The criteria for a continuing statement are:
1246 (lua-last-token-continues-p))))))) 1289 (lua-last-token-continues-p)))))))
1247 1290
1248(defun lua-make-indentation-info-pair (found-token found-pos) 1291(defun lua-make-indentation-info-pair (found-token found-pos)
1249 "This is a helper function to lua-calculate-indentation-info. Don't 1292 "Create a pair from FOUND-TOKEN and FOUND-POS for indentation calculation.
1250use standalone." 1293
1294This is a helper function to lua-calculate-indentation-info.
1295Don't use standalone."
1251 (cond 1296 (cond
1252 ;; function is a bit tricky to indent right. They can appear in a lot ot 1297 ;; function is a bit tricky to indent right. They can appear in a lot ot
1253 ;; different contexts. Until I find a shortcut, I'll leave it with a simple 1298 ;; different contexts. Until I find a shortcut, I'll leave it with a simple
@@ -1321,17 +1366,17 @@ use standalone."
1321 (- lua-indent-level)))))) 1366 (- lua-indent-level))))))
1322 1367
1323(defun lua-add-indentation-info-pair (pair info) 1368(defun lua-add-indentation-info-pair (pair info)
1324 "Add the given indentation info pair to the list of indentation information. 1369 "Add the given indentation info PAIR to the list of indentation INFO.
1325This function has special case handling for two tokens: remove-matching, 1370This function has special case handling for two tokens: remove-matching,
1326and replace-matching. These two tokens are cleanup tokens that remove or 1371and replace-matching. These two tokens are cleanup tokens that remove or
1327alter the effect of a previously recorded indentation info. 1372alter the effect of a previously recorded indentation info.
1328 1373
1329When a remove-matching token is encountered, the last recorded info, i.e. 1374When a remove-matching token is encountered, the last recorded info, i.e.
1330the car of the list is removed. This is used to roll-back an indentation of a 1375the car of the list is removed. This is used to roll-back an indentation of a
1331block opening statement when it is closed. 1376block opening statement when it is closed.
1332 1377
1333When a replace-matching token is seen, the last recorded info is removed, 1378When a replace-matching token is seen, the last recorded info is removed,
1334and the cdr of the replace-matching info is added in its place. This is used 1379and the cdr of the replace-matching info is added in its place. This is used
1335when a middle-of the block (the only case is 'else') is seen on the same line 1380when a middle-of the block (the only case is 'else') is seen on the same line
1336the block is opened." 1381the block is opened."
1337 (cond 1382 (cond
@@ -1354,9 +1399,7 @@ Return list of indentation modifiers from point to BOUND."
1354 (while (lua-find-regexp 'forward lua-indentation-modifier-regexp 1399 (while (lua-find-regexp 'forward lua-indentation-modifier-regexp
1355 bound) 1400 bound)
1356 (let ((found-token (match-string 0)) 1401 (let ((found-token (match-string 0))
1357 (found-pos (match-beginning 0)) 1402 (found-pos (match-beginning 0)))
1358 (found-end (match-end 0))
1359 (data (match-data)))
1360 (setq indentation-info 1403 (setq indentation-info
1361 (lua-add-indentation-info-pair 1404 (lua-add-indentation-info-pair
1362 (lua-make-indentation-info-pair found-token found-pos) 1405 (lua-make-indentation-info-pair found-token found-pos)
@@ -1370,8 +1413,7 @@ The effect of each token can be either a shift relative to the current
1370indentation level, or indentation to some absolute column. This information 1413indentation level, or indentation to some absolute column. This information
1371is collected in a list of indentation info pairs, which denote absolute 1414is collected in a list of indentation info pairs, which denote absolute
1372and relative each, and the shift/column to indent to." 1415and relative each, and the shift/column to indent to."
1373 (let ((combined-line-end (line-end-position)) 1416 (let (indentation-info)
1374 indentation-info)
1375 1417
1376 (while (lua-is-continuing-statement-p) 1418 (while (lua-is-continuing-statement-p)
1377 (lua-forward-line-skip-blanks 'back)) 1419 (lua-forward-line-skip-blanks 'back))
@@ -1541,11 +1583,10 @@ If not, return nil."
1541 (current-indentation) 1583 (current-indentation)
1542 (current-column))))))) 1584 (current-column)))))))
1543 1585
1544(defun lua-calculate-indentation (&optional parse-start) 1586(defun lua-calculate-indentation ()
1545 "Return appropriate indentation for current line as Lua code." 1587 "Return appropriate indentation for current line as Lua code."
1546 (save-excursion 1588 (save-excursion
1547 (let ((continuing-p (lua-is-continuing-statement-p)) 1589 (let ((cur-line-begin-pos (line-beginning-position)))
1548 (cur-line-begin-pos (line-beginning-position)))
1549 (or 1590 (or
1550 ;; when calculating indentation, do the following: 1591 ;; when calculating indentation, do the following:
1551 ;; 1. check, if the line starts with indentation-modifier (open/close brace) 1592 ;; 1. check, if the line starts with indentation-modifier (open/close brace)
@@ -1689,7 +1730,8 @@ When called interactively, switch to the process buffer."
1689 (setq compilation-error-regexp-alist 1730 (setq compilation-error-regexp-alist
1690 (cons (list lua-traceback-line-re 1 2) 1731 (cons (list lua-traceback-line-re 1 2)
1691 compilation-error-regexp-alist)) 1732 compilation-error-regexp-alist))
1692 (compilation-shell-minor-mode 1)) 1733 (compilation-shell-minor-mode 1)
1734 (setq-local comint-prompt-regexp lua-prompt-regexp))
1693 1735
1694 ;; when called interactively, switch to process buffer 1736 ;; when called interactively, switch to process buffer
1695 (if (called-interactively-p 'any) 1737 (if (called-interactively-p 'any)
@@ -1856,13 +1898,10 @@ left out."
1856 "Forward to block end" 1898 "Forward to block end"
1857 (interactive "p") 1899 (interactive "p")
1858 ;; negative offsets not supported 1900 ;; negative offsets not supported
1859 (assert (or (not count) (>= count 0))) 1901 (cl-assert (or (not count) (>= count 0)))
1860 (save-match-data 1902 (save-match-data
1861 (let* ((count (or count 1)) 1903 (let ((count (or count 1))
1862 (block-start (mapcar 'car lua-sexp-alist)) 1904 (block-start (mapcar 'car lua-sexp-alist)))
1863 (block-end (mapcar 'cdr lua-sexp-alist))
1864 (block-regex (regexp-opt (append block-start block-end) 'words))
1865 current-exp)
1866 (while (> count 0) 1905 (while (> count 0)
1867 ;; skip whitespace 1906 ;; skip whitespace
1868 (skip-chars-forward " \t\n") 1907 (skip-chars-forward " \t\n")
diff --git a/.emacs.d/lisp/php-face.el b/.emacs.d/lisp/php-face.el
index 4230bae..5f40257 100644
--- a/.emacs.d/lisp/php-face.el
+++ b/.emacs.d/lisp/php-face.el
@@ -4,7 +4,7 @@
4 4
5;; Author: USAMI Kenta <tadsan@zonu.me> 5;; Author: USAMI Kenta <tadsan@zonu.me>
6;; Created: 5 May 2019 6;; Created: 5 May 2019
7;; Version: 1.21.4 7;; Version: 1.22.1
8;; Keywords: faces, php 8;; Keywords: faces, 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")) 10;; Package-Requires: ((emacs "24.3"))
@@ -56,7 +56,7 @@
56 :group 'php-faces 56 :group 'php-faces
57 :tag "PHP Function Name") 57 :tag "PHP Function Name")
58 58
59(defface php-function-call '((t (:inherit default))) 59(defface php-function-call '((t ()))
60 "PHP Mode face used to highlight function names in calles." 60 "PHP Mode face used to highlight function names in calles."
61 :group 'php-faces 61 :group 'php-faces
62 :tag "PHP Function Call") 62 :tag "PHP Function Call")
@@ -81,17 +81,52 @@
81 :group 'php-faces 81 :group 'php-faces
82 :tag "PHP Property Name") 82 :tag "PHP Property Name")
83 83
84(defface php-variable-sigil '((t (:inherit default))) 84(defface php-variable-sigil '((t ()))
85 "PHP Mode face used to highlight variable sigils ($)." 85 "PHP Mode face used to highlight variable sigils ($)."
86 :group 'php-faces 86 :group 'php-faces
87 :tag "PHP Variable Sigil") 87 :tag "PHP Variable Sigil")
88 88
89(defface php-object-op '((t (:inherit default))) 89(defface php-operator '((t ()))
90 "PHP Mode face used to operators."
91 :group 'php-faces
92 :tag "PHP Operator")
93
94(defface php-assignment-op '((t (:inherit php-operator)))
95 "PHP Mode face used to assignment operators (=, +=, ...)."
96 :group 'php-faces
97 :tag "PHP Object Op")
98
99(defface php-comparison-op '((t (:inherit php-operator)))
100 "PHP Mode face used to comparison operators (==, !=, ===, ...)."
101 :group 'php-faces
102 :tag "PHP Comparison Op")
103
104(defface php-logical-op '((t (:inherit php-operator)))
105 "PHP Mode face used to logical operators (&&, ||, ?:)."
106 :group 'php-faces
107 :tag "PHP Logical Op")
108
109(defface php-arithmetic-op '((t (:inherit php-operator)))
110 "PHP Mode face used to arithmetic operators (+, -, %, ...)."
111 :group 'php-faces
112 :tag "PHP Arithmetic Op")
113
114(defface php-inc-dec-op '((t (:inherit php-operator)))
115 "PHP Mode face used to increment and decremt operators (--, ++)."
116 :group 'php-faces
117 :tag "PHP Increment/Decrement Op")
118
119(defface php-string-op '((t (:inherit php-operator)))
120 "PHP Mode face used to logical operators (.)."
121 :group 'php-faces
122 :tag "PHP String Op")
123
124(defface php-object-op '((t (:inherit php-operator)))
90 "PHP Mode face used to object operators (->)." 125 "PHP Mode face used to object operators (->)."
91 :group 'php-faces 126 :group 'php-faces
92 :tag "PHP Object Op") 127 :tag "PHP Object Op")
93 128
94(defface php-paamayim-nekudotayim '((t (:inherit default))) 129(defface php-paamayim-nekudotayim '((t ()))
95 "PHP Mode face used to highlight \"Paamayim Nekudotayim\" scope resolution operators (::)." 130 "PHP Mode face used to highlight \"Paamayim Nekudotayim\" scope resolution operators (::)."
96 :group 'php-faces 131 :group 'php-faces
97 :tag "PHP Paamayim Nekudotayim") 132 :tag "PHP Paamayim Nekudotayim")
@@ -131,7 +166,7 @@
131 :group 'php-faces 166 :group 'php-faces
132 :tag "PHP $this Sigil") 167 :tag "PHP $this Sigil")
133 168
134(defface php-errorcontrol-op '((t (:inherit font-lock-type-face))) 169(defface php-errorcontrol-op '((t (:inherit font-lock-type-face)))
135 "PHP Mode face used to highlight errorcontrol operators (@).." 170 "PHP Mode face used to highlight errorcontrol operators (@).."
136 :group 'php-faces 171 :group 'php-faces
137 :tag "PHP ErrorControl Op") 172 :tag "PHP ErrorControl Op")
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el
index 9be3b55..faf2ec5 100644
--- a/.emacs.d/lisp/php-mode.el
+++ b/.emacs.d/lisp/php-mode.el
@@ -9,16 +9,13 @@
9;; Maintainer: USAMI Kenta <tadsan@zonu.me> 9;; Maintainer: USAMI Kenta <tadsan@zonu.me>
10;; URL: https://github.com/emacs-php/php-mode 10;; URL: https://github.com/emacs-php/php-mode
11;; Keywords: languages php 11;; Keywords: languages php
12;; Version: 1.21.4 12;; Version: 1.22.1
13;; Package-Requires: ((emacs "24.3") (cl-lib "0.5")) 13;; Package-Requires: ((emacs "24.3"))
14;; License: GPL-3.0-or-later 14;; License: GPL-3.0-or-later
15 15
16(defconst php-mode-version-number "1.21.4" 16(defconst php-mode-version-number "1.22.1"
17 "PHP Mode version number.") 17 "PHP Mode version number.")
18 18
19(defconst php-mode-modified "2019-05-29"
20 "PHP Mode build date.")
21
22;; This program is free software; you can redistribute it and/or modify 19;; This program is free software; you can redistribute it and/or modify
23;; it under the terms of the GNU General Public License as published by 20;; it under the terms of the GNU General Public License as published by
24;; the Free Software Foundation, either version 3 of the License, or 21;; the Free Software Foundation, either version 3 of the License, or
@@ -195,7 +192,10 @@ of constants when set."
195 :type 'boolean) 192 :type 'boolean)
196 193
197(defcustom php-mode-page-delimiter 194(defcustom php-mode-page-delimiter
198 (eval-when-compile (rx symbol-start (or "namespace" "function" "class" "trait" "interface") symbol-end)) 195 (eval-when-compile
196 (rx symbol-start
197 (or "namespace" "function" "class" "trait" "interface")
198 symbol-end))
199 "Regexp describing line-beginnings that PHP declaration statements." 199 "Regexp describing line-beginnings that PHP declaration statements."
200 :group 'php-mode 200 :group 'php-mode
201 :tag "PHP Mode Page Delimiter" 201 :tag "PHP Mode Page Delimiter"
@@ -307,7 +307,7 @@ This variable can take one of the following symbol values:
307`PSR-2' - use coding styles preferred for working with projects using PSR-2 standards." 307`PSR-2' - use coding styles preferred for working with projects using PSR-2 standards."
308 :group 'php-mode 308 :group 'php-mode
309 :tag "PHP Mode Coding Style" 309 :tag "PHP Mode Coding Style"
310 :type '(choice (const :tag "Default" default) 310 :type '(choice (const :tag "Default" php)
311 (const :tag "PEAR" pear) 311 (const :tag "PEAR" pear)
312 (const :tag "Drupal" drupal) 312 (const :tag "Drupal" drupal)
313 (const :tag "WordPress" wordpress) 313 (const :tag "WordPress" wordpress)
@@ -340,15 +340,27 @@ In that case set to `NIL'."
340 "When set to `T', do not run hooks of parent modes (`java-mode', `c-mode')." 340 "When set to `T', do not run hooks of parent modes (`java-mode', `c-mode')."
341 :group 'php-mode 341 :group 'php-mode
342 :tag "PHP Mode Disable C Mode Hook" 342 :tag "PHP Mode Disable C Mode Hook"
343 :type 'boolean 343 :type 'boolean)
344 :group 'php-mode) 344
345(defcustom php-mode-enable-project-local-variable t
346 "When set to `T', apply project local variable to buffer local variable."
347 :group 'php-mode
348 :tag "PHP Mode Enable Project Local Variable"
349 :type 'boolean)
345 350
346(defun php-mode-version () 351(defun php-mode-version ()
347 "Display string describing the version of PHP Mode." 352 "Display string describing the version of PHP Mode."
348 (interactive) 353 (interactive)
349 (funcall 354 (let ((fmt
350 (if (called-interactively-p 'interactive) #'message #'format) 355 (eval-when-compile
351 "PHP Mode %s of %s" php-mode-version-number php-mode-modified)) 356 (let ((id "$Id$"))
357 (concat "PHP Mode %s"
358 (if (string= id (concat [?$ ?I ?d ?$]))
359 ""
360 (concat " " id)))))))
361 (funcall
362 (if (called-interactively-p 'interactive) #'message #'format)
363 fmt php-mode-version-number)))
352 364
353;;;###autoload 365;;;###autoload
354(define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0") 366(define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0")
@@ -633,10 +645,37 @@ might be to handle switch and goto labels differently."
633(c-lang-defconst c-opt-<>-sexp-key 645(c-lang-defconst c-opt-<>-sexp-key
634 php nil) 646 php nil)
635 647
648(defconst php-mode--re-return-typed-closure
649 (eval-when-compile
650 (rx symbol-start "function" symbol-end
651 (* (syntax whitespace))
652 "(" (* (not (any "("))) ")"
653 (* (syntax whitespace))
654 (? symbol-start "use" symbol-end
655 (* (syntax whitespace))
656 "(" (* (not (any "("))) ")"
657 (* (syntax whitespace)))
658 ":" (+ (not (any "{}")))
659 (group "{"))))
660
661(defun php-c-lineup-arglist (langelem)
662 "Line up the current argument line under the first argument using `c-lineup-arglist' LANGELEM."
663 (let (in-return-typed-closure)
664 (when (and (consp langelem)
665 (eq 'arglist-cont-nonempty (car langelem)))
666 (save-excursion
667 (save-match-data
668 (when (re-search-backward php-mode--re-return-typed-closure (cdr langelem) t)
669 (goto-char (match-beginning 1))
670 (when (not (php-in-string-or-comment-p))
671 (setq in-return-typed-closure t))))))
672 (unless in-return-typed-closure
673 (c-lineup-arglist langelem))))
674
636(defun php-lineup-cascaded-calls (langelem) 675(defun php-lineup-cascaded-calls (langelem)
637 "Line up chained methods using `c-lineup-cascaded-calls', 676 "Line up chained methods using `c-lineup-cascaded-calls',
638but only if the setting is enabled" 677but only if the setting is enabled"
639 (if php-lineup-cascaded-calls 678 (when php-mode-lineup-cascaded-calls
640 (c-lineup-cascaded-calls langelem))) 679 (c-lineup-cascaded-calls langelem)))
641 680
642(c-add-style 681(c-add-style
@@ -644,11 +683,12 @@ but only if the setting is enabled"
644 `((c-basic-offset . 4) 683 `((c-basic-offset . 4)
645 (c-offsets-alist . ((arglist-close . php-lineup-arglist-close) 684 (c-offsets-alist . ((arglist-close . php-lineup-arglist-close)
646 (arglist-cont . (first php-lineup-cascaded-calls 0)) 685 (arglist-cont . (first php-lineup-cascaded-calls 0))
647 (arglist-cont-nonempty . (first php-lineup-cascaded-calls c-lineup-arglist)) 686 (arglist-cont-nonempty . (first php-lineup-cascaded-calls php-c-lineup-arglist))
648 (arglist-intro . php-lineup-arglist-intro) 687 (arglist-intro . php-lineup-arglist-intro)
649 (case-label . +) 688 (case-label . +)
650 (class-open . 0) 689 (class-open . 0)
651 (comment-intro . 0) 690 (comment-intro . 0)
691 (inexpr-class . 0)
652 (inlambda . 0) 692 (inlambda . 0)
653 (inline-open . 0) 693 (inline-open . 0)
654 (namespace-open . 0) 694 (namespace-open . 0)
@@ -661,6 +701,7 @@ but only if the setting is enabled"
661 (tab-width . ,(default-value 'tab-width)) 701 (tab-width . ,(default-value 'tab-width))
662 (fill-column . ,(default-value 'fill-column)) 702 (fill-column . ,(default-value 'fill-column))
663 (show-trailing-whitespace . ,(default-value 'show-trailing-whitespace)) 703 (show-trailing-whitespace . ,(default-value 'show-trailing-whitespace))
704 (php-mode-lineup-cascaded-calls . t)
664 (php-style-delete-trailing-whitespace . nil))) 705 (php-style-delete-trailing-whitespace . nil)))
665 706
666(defun php-enable-default-coding-style () 707(defun php-enable-default-coding-style ()
@@ -687,6 +728,7 @@ but only if the setting is enabled"
687 (tab-width . 2) 728 (tab-width . 2)
688 (fill-column . 78) 729 (fill-column . 78)
689 (show-trailing-whitespace . t) 730 (show-trailing-whitespace . t)
731 (php-mode-lineup-cascaded-calls . nil)
690 (php-style-delete-trailing-whitespace . t))) 732 (php-style-delete-trailing-whitespace . t)))
691 733
692(defun php-enable-drupal-coding-style () 734(defun php-enable-drupal-coding-style ()
@@ -713,6 +755,7 @@ but only if the setting is enabled"
713 '("php" 755 '("php"
714 (c-offsets-alist . ((statement-cont . php-lineup-hanging-semicolon))) 756 (c-offsets-alist . ((statement-cont . php-lineup-hanging-semicolon)))
715 (c-indent-comments-syntactically-p . t) 757 (c-indent-comments-syntactically-p . t)
758 (php-mode-lineup-cascaded-calls . nil)
716 (fill-column . 78))) 759 (fill-column . 78)))
717 760
718(defun php-enable-symfony2-coding-style () 761(defun php-enable-symfony2-coding-style ()
@@ -721,12 +764,13 @@ but only if the setting is enabled"
721 (php-set-style "symfony2")) 764 (php-set-style "symfony2"))
722 765
723(c-add-style 766(c-add-style
724 "psr2" 767 "psr2" ; PSR-2 / PSR-12
725 '("php" 768 '("php"
726 (c-offsets-alist . ((statement-cont . +))) 769 (c-offsets-alist . ((statement-cont . +)))
727 (c-indent-comments-syntactically-p . t) 770 (c-indent-comments-syntactically-p . t)
728 (fill-column . 78) 771 (fill-column . 78)
729 (show-trailing-whitespace . t) 772 (show-trailing-whitespace . t)
773 (php-mode-lineup-cascaded-calls . nil)
730 (php-style-delete-trailing-whitespace . t))) 774 (php-style-delete-trailing-whitespace . t)))
731 775
732(defun php-enable-psr2-coding-style () 776(defun php-enable-psr2-coding-style ()
@@ -734,10 +778,6 @@ but only if the setting is enabled"
734 (interactive) 778 (interactive)
735 (php-set-style "psr2")) 779 (php-set-style "psr2"))
736 780
737(defconst php-beginning-of-defun-regexp
738 "^\\s-*\\(?:\\(?:abstract\\|final\\|private\\|protected\\|public\\|static\\)\\s-+\\)*function\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*("
739 "Regular expression for a PHP function.")
740
741(defun php-beginning-of-defun (&optional arg) 781(defun php-beginning-of-defun (&optional arg)
742 "Move to the beginning of the ARGth PHP function from point. 782 "Move to the beginning of the ARGth PHP function from point.
743Implements PHP version of `beginning-of-defun-function'." 783Implements PHP version of `beginning-of-defun-function'."
@@ -1009,6 +1049,14 @@ this ^ lineup"
1009(easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands" 1049(easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands"
1010 (cons "PHP" (c-lang-const c-mode-menu php))) 1050 (cons "PHP" (c-lang-const c-mode-menu php)))
1011 1051
1052(defun php-mode-get-style-alist ()
1053 "Return an alist consisting of `php' style and styles that inherit it."
1054 (cl-loop for l in c-style-alist
1055 if (or (string= (car l) "php")
1056 (equal (cadr l) "php"))
1057 collect l))
1058
1059(defvar php-mode-set-style-history nil)
1012(defvar-local php-mode--delayed-set-style nil) 1060(defvar-local php-mode--delayed-set-style nil)
1013(defvar-local php-style-delete-trailing-whitespace nil) 1061(defvar-local php-style-delete-trailing-whitespace nil)
1014 1062
@@ -1027,7 +1075,15 @@ After setting the stylevars run hooks according to STYLENAME
1027 \"wordpress\" `php-mode-wordpress-hook' 1075 \"wordpress\" `php-mode-wordpress-hook'
1028 \"symfony2\" `php-mode-symfony2-hook' 1076 \"symfony2\" `php-mode-symfony2-hook'
1029 \"psr2\" `php-mode-psr2-hook'" 1077 \"psr2\" `php-mode-psr2-hook'"
1030 (interactive) 1078 (interactive
1079 (list (let ((completion-ignore-case t)
1080 (prompt (format "Which %s indentation style? "
1081 mode-name)))
1082 (completing-read prompt
1083 (php-mode-get-style-alist)
1084 nil t nil
1085 'php-mode-set-style-history
1086 c-indentation-style))))
1031 (php-mode--disable-delay-set-style) 1087 (php-mode--disable-delay-set-style)
1032 1088
1033 ;; Back up manually set variables 1089 ;; Back up manually set variables
@@ -1046,13 +1102,11 @@ After setting the stylevars run hooks according to STYLENAME
1046 (if (eq (symbol-value 'php-style-delete-trailing-whitespace) t) 1102 (if (eq (symbol-value 'php-style-delete-trailing-whitespace) t)
1047 (add-hook 'before-save-hook 'delete-trailing-whitespace nil t) 1103 (add-hook 'before-save-hook 'delete-trailing-whitespace nil t)
1048 (remove-hook 'before-save-hook 'delete-trailing-whitespace t)) 1104 (remove-hook 'before-save-hook 'delete-trailing-whitespace t))
1049 (cond ((eq stylename "pear") (run-hooks 'php-mode-pear-hook)) 1105 (cond ((equal stylename "pear") (run-hooks 'php-mode-pear-hook))
1050 ((eq stylename "drupal") (run-hooks 'php-mode-drupal-hook)) 1106 ((equal stylename "drupal") (run-hooks 'php-mode-drupal-hook))
1051 ((eq stylename "wordpress") (run-hooks 'php-mode-wordpress-hook)) 1107 ((equal stylename "wordpress") (run-hooks 'php-mode-wordpress-hook))
1052 ((eq stylename "symfony2") (run-hooks 'php-mode-symfony2-hook)) 1108 ((equal stylename "symfony2") (run-hooks 'php-mode-symfony2-hook))
1053 ((eq stylename "psr2") (run-hooks 'php-mode-psr2-hook)))) 1109 ((equal stylename "psr2") (run-hooks 'php-mode-psr2-hook))))
1054
1055(put 'php-set-style 'interactive-form (interactive-form 'c-set-style))
1056 1110
1057(defun php-mode--disable-delay-set-style (&rest args) 1111(defun php-mode--disable-delay-set-style (&rest args)
1058 "Disable php-mode-set-style-delay on after hook. `ARGS' be ignore." 1112 "Disable php-mode-set-style-delay on after hook. `ARGS' be ignore."
@@ -1069,6 +1123,11 @@ After setting the stylevars run hooks according to STYLENAME
1069 (php-set-style (symbol-name coding-style))) 1123 (php-set-style (symbol-name coding-style)))
1070 (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))) 1124 (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay)))))
1071 1125
1126(defun php-mode-set-local-variable-delay ()
1127 "Set local variable from php-project."
1128 (php-project-apply-local-variables)
1129 (remove-hook 'hack-local-variables-hook #'php-mode-set-local-variable-delay))
1130
1072(defvar php-mode-syntax-table 1131(defvar php-mode-syntax-table
1073 (let ((table (make-syntax-table))) 1132 (let ((table (make-syntax-table)))
1074 (c-populate-syntax-table table) 1133 (c-populate-syntax-table table)
@@ -1077,7 +1136,7 @@ After setting the stylevars run hooks according to STYLENAME
1077 (modify-syntax-entry ?\" "\"" table) 1136 (modify-syntax-entry ?\" "\"" table)
1078 (modify-syntax-entry ?# "< b" table) 1137 (modify-syntax-entry ?# "< b" table)
1079 (modify-syntax-entry ?\n "> b" table) 1138 (modify-syntax-entry ?\n "> b" table)
1080 (modify-syntax-entry ?$ "'" table) 1139 (modify-syntax-entry ?$ "_" table)
1081 table)) 1140 table))
1082 1141
1083;;;###autoload 1142;;;###autoload
@@ -1122,6 +1181,9 @@ After setting the stylevars run hooks according to STYLENAME
1122 ;; PHP vars are case-sensitive 1181 ;; PHP vars are case-sensitive
1123 (setq case-fold-search t) 1182 (setq case-fold-search t)
1124 1183
1184 (when php-mode-enable-project-local-variable
1185 (add-hook 'hack-local-variables-hook #'php-mode-set-local-variable-delay t t))
1186
1125 ;; When php-mode-enable-project-coding-style is set, it is delayed by hook. 1187 ;; When php-mode-enable-project-coding-style is set, it is delayed by hook.
1126 ;; Since it depends on the timing at which the file local variable is set. 1188 ;; Since it depends on the timing at which the file local variable is set.
1127 ;; File local variables are set after initialization of major mode except `run-hook' is complete. 1189 ;; File local variables are set after initialization of major mode except `run-hook' is complete.
@@ -1440,7 +1502,7 @@ a completion list."
1440 "return" "throws" "var")) 1502 "return" "throws" "var"))
1441 1503
1442(defconst php-phpdoc-font-lock-doc-comments 1504(defconst php-phpdoc-font-lock-doc-comments
1443 `(("{@[-[:alpha:]]+\\s-\\([^}]*\\)}" ; "{@foo ...}" markup. 1505 `(("{@[-[:alpha:]]+\\s-*\\([^}]*\\)}" ; "{@foo ...}" markup.
1444 (0 'php-doc-annotation-tag prepend nil) 1506 (0 'php-doc-annotation-tag prepend nil)
1445 (1 'php-string prepend nil)) 1507 (1 'php-string prepend nil))
1446 (,(rx (group "$") (group (in "A-Za-z_") (* (in "0-9A-Za-z_")))) 1508 (,(rx (group "$") (group (in "A-Za-z_") (* (in "0-9A-Za-z_"))))
@@ -1482,6 +1544,9 @@ a completion list."
1482 ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call)) 1544 ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call))
1483 ("\\<\\(const\\)\\s-+\\(\\_<.+?\\_>\\)" (1 'php-keyword) (2 'php-constant-assign)) 1545 ("\\<\\(const\\)\\s-+\\(\\_<.+?\\_>\\)" (1 'php-keyword) (2 'php-constant-assign))
1484 1546
1547 ;; Logical operator (!)
1548 ("\\(![^=]\\)" 1 'php-logical-op)
1549
1485 ;; Highlight special variables 1550 ;; Highlight special variables
1486 ("\\(\\$\\)\\(this\\)\\>" (1 'php-$this-sigil) (2 'php-$this)) 1551 ("\\(\\$\\)\\(this\\)\\>" (1 'php-$this-sigil) (2 'php-$this))
1487 ("\\(\\$+\\)\\(\\sw+\\)" (1 'php-variable-sigil) (2 'php-variable-name)) 1552 ("\\(\\$+\\)\\(\\sw+\\)" (1 'php-variable-sigil) (2 'php-variable-name))
@@ -1517,7 +1582,14 @@ a completion list."
1517 ;; Highlight static method calls as such. This is necessary for method 1582 ;; Highlight static method calls as such. This is necessary for method
1518 ;; names which are identical to keywords to be highlighted correctly. 1583 ;; names which are identical to keywords to be highlighted correctly.
1519 ("\\sw+::\\(\\sw+\\)(" 1 'php-static-method-call) 1584 ("\\sw+::\\(\\sw+\\)(" 1 'php-static-method-call)
1520 1585 ;; Multiple catch (FooException | BarException $e)
1586 (,(rx symbol-start "catch" symbol-end
1587 (* (syntax whitespace)) "(" (* (syntax whitespace))
1588 (group (+ (or (syntax word) (syntax symbol)))))
1589 (1 font-lock-type-face)
1590 (,(rx (* (syntax whitespace)) "|" (* (syntax whitespace))
1591 (group (+ (or (syntax word) (syntax symbol))) symbol-end))
1592 nil nil (1 font-lock-type-face)))
1521 ;; While c-opt-cpp-* highlights the <?php opening tags, it is not 1593 ;; While c-opt-cpp-* highlights the <?php opening tags, it is not
1522 ;; possible to make it highlight short open tags and closing tags 1594 ;; possible to make it highlight short open tags and closing tags
1523 ;; as well. So we force the correct face on all cases that 1595 ;; as well. So we force the correct face on all cases that
@@ -1542,6 +1614,8 @@ a completion list."
1542 ;; is usually overkill. 1614 ;; is usually overkill.
1543 `( 1615 `(
1544 ("\\<\\(@\\)" 1 'php-errorcontrol-op) 1616 ("\\<\\(@\\)" 1 'php-errorcontrol-op)
1617 ;; Highlight function calls
1618 ("\\(\\_<\\(?:\\sw\\|\\s_\\)+?\\_>\\)\\s-*(" 1 'php-function-call)
1545 ;; Highlight all upper-cased symbols as constant 1619 ;; Highlight all upper-cased symbols as constant
1546 ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant) 1620 ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant)
1547 1621
@@ -1581,7 +1655,23 @@ a completion list."
1581 ("\\?\\(\\(:?\\sw\\|\\s_\\)+\\)\\s-+\\$" 1 font-lock-type-face) 1655 ("\\?\\(\\(:?\\sw\\|\\s_\\)+\\)\\s-+\\$" 1 font-lock-type-face)
1582 ("function.+:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face) 1656 ("function.+:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face)
1583 (")\\s-*:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*\\(?:\{\\|;\\)" 1 font-lock-type-face) 1657 (")\\s-*:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*\\(?:\{\\|;\\)" 1 font-lock-type-face)
1584 )) 1658
1659 ;; Assignment operators (=, +=, ...)
1660 ("\\([^=<!>]+?\\([\-+./%]?=\\)[^=<!>]+?\\)" 2 'php-assignment-op)
1661
1662 ;; Comparison operators (==, ===, >=, ...)
1663 ("\\([!=]=\\{1,2\\}[>]?\\|[<>]=?\\)" 1 'php-comparison-op)
1664
1665 ;; Arithmetic operators (+, -, *, **, /, %)
1666 ("\\(?:[A-Za-z0-9[:blank:]]\\)\\([\-+*/%]\\*?\\)\\(?:[A-Za-z0-9[:blank:]]\\)" 1 'php-arithmetic-op)
1667
1668 ;; Increment and Decrement operators (++, --)
1669 ("\\(\-\-\\|\+\+\\)\$\\w+" 1 'php-inc-dec-op) ;; pre inc/dec
1670 ("\$\\w+\\(\-\-\\|\+\+\\)" 1 'php-inc-dec-op) ;; post inc/dec
1671
1672 ;; Logical operators (and, or, &&, ...)
1673 ;; Not operator (!) is defined in "before cc-mode" section above.
1674 ("\\(&&\\|||\\)" 1 'php-logical-op)))
1585 "Detailed highlighting for PHP Mode.") 1675 "Detailed highlighting for PHP Mode.")
1586 1676
1587(defvar php-font-lock-keywords php-font-lock-keywords-3 1677(defvar php-font-lock-keywords php-font-lock-keywords-3
diff --git a/.emacs.d/lisp/php-project.el b/.emacs.d/lisp/php-project.el
index eb9a50e..18115cc 100644
--- a/.emacs.d/lisp/php-project.el
+++ b/.emacs.d/lisp/php-project.el
@@ -5,8 +5,8 @@
5;; Author: USAMI Kenta <tadsan@zonu.me> 5;; Author: USAMI Kenta <tadsan@zonu.me>
6;; Keywords: tools, files 6;; Keywords: tools, files
7;; URL: https://github.com/emacs-php/php-mode 7;; URL: https://github.com/emacs-php/php-mode
8;; Version: 1.21.4 8;; Version: 1.22.1
9;; Package-Requires: ((emacs "24.3") (cl-lib "0.5")) 9;; Package-Requires: ((emacs "24.3"))
10;; License: GPL-3.0-or-later 10;; License: GPL-3.0-or-later
11 11
12;; This program is free software; you can redistribute it and/or modify 12;; This program is free software; you can redistribute it and/or modify
@@ -72,6 +72,19 @@
72;; Constants 72;; Constants
73(defconst php-project-composer-autoloader "vendor/autoload.php") 73(defconst php-project-composer-autoloader "vendor/autoload.php")
74 74
75;; Custom variables
76(defgroup php-project nil
77 "Major mode for editing PHP code."
78 :tag "PHP Project"
79 :prefix "php-project-"
80 :group 'php)
81
82(defcustom php-project-auto-detect-etags-file nil
83 "If `T', automatically detect etags file when file is opened."
84 :tag "PHP Project Auto Detect Etags File"
85 :group 'php-project
86 :type 'boolean)
87
75;; Variables 88;; Variables
76(defvar php-project-available-root-files 89(defvar php-project-available-root-files
77 '((projectile ".projectile") 90 '((projectile ".projectile")
@@ -104,6 +117,12 @@ STRING
104 (put 'php-project-root 'safe-local-variable 117 (put 'php-project-root 'safe-local-variable
105 #'(lambda (v) (or (stringp v) (assq v php-project-available-root-files)))) 118 #'(lambda (v) (or (stringp v) (assq v php-project-available-root-files))))
106 119
120 (defvar-local php-project-etags-file nil)
121 (put 'php-project-etags-file 'safe-local-variable
122 #'(lambda (v) (or (functionp v)
123 (eq v t)
124 (php-project--eval-bootstrap-scripts v))))
125
107 (defvar-local php-project-bootstrap-scripts nil 126 (defvar-local php-project-bootstrap-scripts nil
108 "List of path to bootstrap php script file. 127 "List of path to bootstrap php script file.
109 128
@@ -172,7 +191,6 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
172 (put 'php-project-server-start 'safe-local-variable 191 (put 'php-project-server-start 'safe-local-variable
173 #'(lambda (v) (or (functionp v) 192 #'(lambda (v) (or (functionp v)
174 (php-project--eval-bootstrap-scripts v))))) 193 (php-project--eval-bootstrap-scripts v)))))
175
176 194
177;; Functions 195;; Functions
178(defun php-project--validate-php-file-as-template (val) 196(defun php-project--validate-php-file-as-template (val)
@@ -229,6 +247,17 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
229 (t (prog1 nil 247 (t (prog1 nil
230 (warn "php-project-php-file-as-template is unexpected format"))))) 248 (warn "php-project-php-file-as-template is unexpected format")))))
231 249
250(defun php-project-apply-local-variables ()
251 "Apply php-project variables to local variables."
252 (when (null tags-file-name)
253 (when (or (and php-project-auto-detect-etags-file
254 (null php-project-etags-file))
255 (eq php-project-etags-file t))
256 (let ((tags-file (expand-file-name "TAGS" (php-project-get-root-dir))))
257 (when (file-exists-p tags-file)
258 (setq-local php-project-etags-file tags-file))))
259 (when php-project-etags-file
260 (setq-local tags-file-name (php-project--eval-bootstrap-scripts php-project-etags-file)))))
232;;;###autoload 261;;;###autoload
233(defun php-project-get-bootstrap-scripts () 262(defun php-project-get-bootstrap-scripts ()
234 "Return list of bootstrap script." 263 "Return list of bootstrap script."
diff --git a/.emacs.d/lisp/php-util-buffer.el b/.emacs.d/lisp/php-util-buffer.el
new file mode 100644
index 0000000..70836a0
--- /dev/null
+++ b/.emacs.d/lisp/php-util-buffer.el
@@ -0,0 +1,135 @@
1;;; php-util-buffer.el --- Utility function for buffer manipulation -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2018-2019 Friends of Emacs-PHP development
4;; Copyright 2013 The go-mode Authors. All rights reserved.
5
6;; Author: Dominik Honnef
7;; Maintainer: USAMI Kenta <tadsan@zonu.me>
8;; URL: https://github.com/emacs-php/php-mode
9;; Keywords: lisp
10
11;; This program is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; This program is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with this program. If not, see <https://www.gnu.org/licenses/>.
23
24;;; Commentary:
25
26;; Functions for patching buffer.
27
28;;; Original License:
29
30;; Copyright (c) 2014 The go-mode Authors. All rights reserved.
31
32;; Redistribution and use in source and binary forms, with or without
33;; modification, are permitted provided that the following conditions are
34;; met:
35
36;; * Redistributions of source code must retain the above copyright
37;; notice, this list of conditions and the following disclaimer.
38;; * Redistributions in binary form must reproduce the above
39;; copyright notice, this list of conditions and the following disclaimer
40;; in the documentation and/or other materials provided with the
41;; distribution.
42;; * Neither the name of the copyright holder nor the names of its
43;; contributors may be used to endorse or promote products derived from
44;; this software without specific prior written permission.
45
46;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
49;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
50;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57
58;;; Code:
59
60;; gofmt apply-rcs-patch Function
61;; These functions are copied by go-mode(gofmt).
62(defun php-util-buffer--delete-whole-line (&optional arg)
63 "Delete the current line without putting it in the `kill-ring'.
64Derived from function `kill-whole-line'. ARG is defined as for that
65function."
66 (setq arg (or arg 1))
67 (if (and (> arg 0)
68 (eobp)
69 (save-excursion (forward-visible-line 0) (eobp)))
70 (signal 'end-of-buffer nil))
71 (if (and (< arg 0)
72 (bobp)
73 (save-excursion (end-of-visible-line) (bobp)))
74 (signal 'beginning-of-buffer nil))
75 (cond ((zerop arg)
76 (delete-region (progn (forward-visible-line 0) (point))
77 (progn (end-of-visible-line) (point))))
78 ((< arg 0)
79 (delete-region (progn (end-of-visible-line) (point))
80 (progn (forward-visible-line (1+ arg))
81 (unless (bobp)
82 (backward-char))
83 (point))))
84 (t
85 (delete-region (progn (forward-visible-line 0) (point))
86 (progn (forward-visible-line arg) (point))))))
87
88(defun php-util-buffer-apply-rcs-patch (target-buffer patch-buffer)
89 "Apply an RCS-formatted diff from `PATCH-BUFFER' to the `TARGET-BUFFER'."
90 (let (
91 ;; Relative offset between buffer line numbers and line numbers
92 ;; in patch.
93 ;;
94 ;; Line numbers in the patch are based on the source file, so
95 ;; we have to keep an offset when making changes to the
96 ;; buffer.
97 ;;
98 ;; Appending lines decrements the offset (possibly making it
99 ;; negative), deleting lines increments it. This order
100 ;; simplifies the forward-line invocations.
101 (line-offset 0)
102 (column (current-column)))
103 (save-excursion
104 (with-current-buffer patch-buffer
105 (goto-char (point-min))
106 (while (not (eobp))
107 (unless (looking-at "^\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)")
108 (error "Invalid rcs patch or internal error in php-util-buffer-apply-rcs-patch"))
109 (forward-line)
110 (let ((action (match-string 1))
111 (from (string-to-number (match-string 2)))
112 (len (string-to-number (match-string 3))))
113 (cond
114 ((equal action "a")
115 (let ((start (point)))
116 (forward-line len)
117 (let ((text (buffer-substring start (point))))
118 (with-current-buffer target-buffer
119 (cl-decf line-offset len)
120 (goto-char (point-min))
121 (forward-line (- from len line-offset))
122 (insert text)))))
123 ((equal action "d")
124 (with-current-buffer target-buffer
125 (goto-char (point-min))
126 (forward-line (1- (- from line-offset)))
127 (cl-incf line-offset len)
128 (php-util-buffer--delete-whole-line len)))
129 (t
130 (error "Invalid rcs patch or internal error in php-util-buffer--apply-rcs-patch")))))))
131 (move-to-column column)))
132;; Copy of go-mode.el ends here
133
134(provide 'php-util-buffer)
135;;; php-util-buffer.el ends here
diff --git a/.emacs.d/lisp/php.el b/.emacs.d/lisp/php.el
index 2bf117b..663559a 100644
--- a/.emacs.d/lisp/php.el
+++ b/.emacs.d/lisp/php.el
@@ -4,10 +4,10 @@
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.4 7;; Version: 1.22.1
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"))
11;; License: GPL-3.0-or-later 11;; License: GPL-3.0-or-later
12 12
13;; This program is free software; you can redistribute it and/or modify 13;; This program is free software; you can redistribute it and/or modify
@@ -159,8 +159,13 @@ it is the character that will terminate the string, or t if the string should be
159 (and (boundp 'poly-php-html-mode) 159 (and (boundp 'poly-php-html-mode)
160 (symbol-value 'poly-php-html-mode))) 160 (symbol-value 'poly-php-html-mode)))
161 161
162(defun php-create-regexp-for-method (visibility) 162(defconst php-beginning-of-defun-regexp
163 "Make a regular expression for methods with the given VISIBILITY. 163 "^\\s-*\\(?:\\(?:abstract\\|final\\|private\\|protected\\|public\\|static\\)\\s-+\\)*function\\s-+&?\\(\\(\\sw\\|\\s_\\)+\\)\\s-*("
164 "Regular expression for a PHP function.")
165
166(eval-when-compile
167 (defun php-create-regexp-for-method (&optional visibility)
168 "Make a regular expression for methods with the given VISIBILITY.
164 169
165VISIBILITY must be a string that names the visibility for a PHP 170VISIBILITY must be a string that names the visibility for a PHP
166method, e.g. 'public'. The parameter VISIBILITY can itself also 171method, e.g. 'public'. The parameter VISIBILITY can itself also
@@ -170,67 +175,81 @@ The regular expression this function returns will check for other
170keywords that can appear in method signatures, e.g. 'final' and 175keywords that can appear in method signatures, e.g. 'final' and
171'static'. The regular expression will have one capture group 176'static'. The regular expression will have one capture group
172which will be the name of the method." 177which will be the name of the method."
173 (concat 178 (when (stringp visibility)
174 ;; Initial space with possible 'abstract' or 'final' keywords 179 (setq visibility (list visibility)))
175 "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?" 180 (rx-to-string `(: line-start
176 ;; 'static' keyword may come either before or after visibility 181 (* (syntax whitespace))
177 "\\(?:" visibility "\\(?:\\s-+static\\)?\\|\\(?:static\\s-+\\)?" visibility "\\)\\s-+" 182 ,@(if visibility
178 ;; Make sure 'function' comes next with some space after 183 `((* (or "abstract" "final" "static")
179 "function\\s-+" 184 (+ (syntax whitespace)))
180 ;; Capture the name as the first group and the regexp and make sure 185 (or ,@visibility)
181 ;; by the end we see the opening parenthesis for the parameters. 186 (+ (syntax whitespace))
182 "\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(")) 187 (* (or "abstract" "final" "static")
188 (+ (syntax whitespace))))
189 '((* (* (or "abstract" "final" "static"
190 "private" "protected" "public")
191 (+ (syntax whitespace))))))
192 "function"
193 (+ (syntax whitespace))
194 (? "&" (* (syntax whitespace)))
195 (group (+ (or (syntax word) (syntax symbol))))
196 (* (syntax whitespace))
197 "(")))
183 198
184(defun php-create-regexp-for-classlike (type) 199 (defun php-create-regexp-for-classlike (type)
185 "Accepts a `TYPE' of a 'classlike' object as a string, such as 200 "Accepts a `TYPE' of a 'classlike' object as a string, such as
186'class' or 'interface', and returns a regexp as a string which 201'class' or 'interface', and returns a regexp as a string which
187can be used to match against definitions for that classlike." 202can be used to match against definitions for that classlike."
188 (concat 203 (concat
189 ;; First see if 'abstract' or 'final' appear, although really these 204 ;; First see if 'abstract' or 'final' appear, although really these
190 ;; are not valid for all values of `type' that the function 205 ;; are not valid for all values of `type' that the function
191 ;; accepts. 206 ;; accepts.
192 "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?" 207 "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?"
193 ;; The classlike type 208 ;; The classlike type
194 type 209 type
195 ;; Its name, which is the first captured group in the regexp. We 210 ;; Its name, which is the first captured group in the regexp. We
196 ;; allow backslashes in the name to handle namespaces, but again 211 ;; allow backslashes in the name to handle namespaces, but again
197 ;; this is not necessarily correct for all values of `type'. 212 ;; this is not necessarily correct for all values of `type'.
198 "\\s-+\\(\\(?:\\sw\\|\\\\\\|\\s_\\)+\\)")) 213 "\\s-+\\(\\(?:\\sw\\|\\\\\\|\\s_\\)+\\)")))
199 214
200(defvar php-imenu-generic-expression 215(defconst php-imenu-generic-expression
201 `(("Namespaces" 216 (eval-when-compile
202 ,(php-create-regexp-for-classlike "namespace") 1) 217 `(("Namespaces"
203 ("Classes" 218 ,(php-create-regexp-for-classlike "namespace") 1)
204 ,(php-create-regexp-for-classlike "class") 1) 219 ("Classes"
205 ("Interfaces" 220 ,(php-create-regexp-for-classlike "class") 1)
206 ,(php-create-regexp-for-classlike "interface") 1) 221 ("Interfaces"
207 ("Traits" 222 ,(php-create-regexp-for-classlike "interface") 1)
208 ,(php-create-regexp-for-classlike "trait") 1) 223 ("Traits"
209 ("All Methods" 224 ,(php-create-regexp-for-classlike "trait") 1)
210 ,(php-create-regexp-for-method "\\(?:\\sw\\|\\s_\\)+") 1) 225 ("All Methods"
211 ("Private Methods" 226 ,(php-create-regexp-for-method) 1)
212 ,(php-create-regexp-for-method "private") 1) 227 ("Private Methods"
213 ("Protected Methods" 228 ,(php-create-regexp-for-method '("private")) 1)
214 ,(php-create-regexp-for-method "protected") 1) 229 ("Protected Methods"
215 ("Public Methods" 230 ,(php-create-regexp-for-method '("protected")) 1)
216 ,(php-create-regexp-for-method "public") 1) 231 ("Public Methods"
217 ("Anonymous Functions" 232 ,(php-create-regexp-for-method '("public")) 1)
218 "\\<\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*=\\s-*function\\s-*(" 1) 233 ("Anonymous Functions"
219 ("Named Functions" 234 "\\<\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*=\\s-*f\\(unctio\\)?n\\s-*(" 1)
220 "^\\s-*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1)) 235 ("Named Functions"
236 "^\\s-*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1)))
221 "Imenu generic expression for PHP Mode. See `imenu-generic-expression'.") 237 "Imenu generic expression for PHP Mode. See `imenu-generic-expression'.")
222 238
223(defvar php--re-namespace-pattern 239(defconst php--re-namespace-pattern
224 (php-create-regexp-for-classlike "namespace")) 240 (eval-when-compile
241 (php-create-regexp-for-classlike "namespace")))
225 242
226(defvar php--re-classlike-pattern 243(defconst php--re-classlike-pattern
227 (php-create-regexp-for-classlike (regexp-opt '("class" "interface" "trait")))) 244 (eval-when-compile
245 (php-create-regexp-for-classlike (regexp-opt '("class" "interface" "trait")))))
228 246
229(defun php-get-current-element (re-pattern) 247(defun php-get-current-element (re-pattern)
230 "Return backward matched element by RE-PATTERN." 248 "Return backward matched element by RE-PATTERN."
231 (save-excursion 249 (save-excursion
232 (when (re-search-backward re-pattern nil t) 250 (save-match-data
233 (match-string-no-properties 1)))) 251 (when (re-search-backward re-pattern nil t)
252 (match-string-no-properties 1)))))
234 253
235;;; Provide support for Flymake so that users can see warnings and 254;;; Provide support for Flymake so that users can see warnings and
236;;; errors in real-time as they write code. 255;;; errors in real-time as they write code.
@@ -245,7 +264,7 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
245 'flymake-php-init))))) 264 'flymake-php-init)))))
246 (list php-executable (cdr init)))) 265 (list php-executable (cdr init))))
247 266
248(defconst php-re-detect-html-tag 267(defconst php-re-detect-html-tag-aggressive
249 (eval-when-compile 268 (eval-when-compile
250 (rx (or (: string-start (* (in space)) 269 (rx (or (: string-start (* (in space))
251 "<!" 270 "<!"
@@ -257,13 +276,38 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
257 (* (in space)) (+ (in alpha "-")) (* (in space)) ">")) 276 (* (in space)) (+ (in alpha "-")) (* (in space)) ">"))
258 (: "<" (* (in space)) (+ (in alpha "-")) (* (in space)) ">")))))) 277 (: "<" (* (in space)) (+ (in alpha "-")) (* (in space)) ">"))))))
259 278
279(defconst php-re-detect-html-tag-default
280 (eval-when-compile
281 (rx (or (: string-start (* (in space))
282 "<!"
283 (or "DOCTYPE" "doctype")
284 (+ (in space))
285 (or "HTML" "html"))
286 (: line-start
287 (: "<" (* (in space)) (+ (in alpha "-")) (* (in space)) ">"))))))
288
289(defcustom php-re-detect-html-tag 'php-re-detect-html-tag-default
290 "Regexp pattern variable-name of HTML detection."
291 :group 'php
292 :tag "PHP Re Detect HTML Tag"
293 :type '(choice (const :tag "Default pattern" 'php-re-detect-html-tag-default)
294 (const :tag "Aggressive pattern" 'php-re-detect-html-tag-aggressive)
295 (variable :tag "Variable name of RegExp pattern")))
296
297(defsubst php-re-detect-html-tag ()
298 "Return RegExp pattern for HTML detection."
299 (if (symbolp php-re-detect-html-tag)
300 (symbol-value php-re-detect-html-tag)
301 php-re-detect-html-tag))
302
260(defun php-buffer-has-html-tag () 303(defun php-buffer-has-html-tag ()
261 "Return position of HTML tag or NIL in current buffer." 304 "Return position of HTML tag or NIL in current buffer."
262 (save-excursion 305 (save-excursion
263 (save-restriction 306 (save-restriction
264 (widen) 307 (widen)
265 (goto-char (point-min)) 308 (goto-char (point-min))
266 (re-search-forward php-re-detect-html-tag nil t)))) 309 (save-match-data
310 (re-search-forward (php-re-detect-html-tag) nil t)))))
267 311
268(defun php-derivation-major-mode () 312(defun php-derivation-major-mode ()
269 "Return major mode for PHP file by file-name and its content." 313 "Return major mode for PHP file by file-name and its content."
@@ -310,6 +354,17 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
310 (insert (concat matched php-namespace-suffix-when-insert))))) 354 (insert (concat matched php-namespace-suffix-when-insert)))))
311 355
312;;;###autoload 356;;;###autoload
357(defun php-copyit-fqsen ()
358 "Copy/kill class/method FQSEN."
359 (interactive)
360 (let ((namespace (or (php-get-current-element php--re-namespace-pattern) ""))
361 (class (or (php-get-current-element php--re-classlike-pattern) ""))
362 (namedfunc (php-get-current-element php-beginning-of-defun-regexp)))
363 (kill-new (concat (if (string= namespace "") "" namespace)
364 (if (string= class "") "" (concat "\\" class "::"))
365 (if (string= namedfunc "") "" (concat namedfunc "()"))))))
366
367;;;###autoload
313(defun php-run-builtin-web-server (router-or-dir hostname port &optional document-root) 368(defun php-run-builtin-web-server (router-or-dir hostname port &optional document-root)
314 "Run PHP Built-in web server. 369 "Run PHP Built-in web server.
315 370
@@ -338,9 +393,8 @@ When `DOCUMENT-ROOT' is NIL, the document root is obtained from `ROUTER-OR-DIR'.
338 (if (file-directory-p router-or-dir) 393 (if (file-directory-p router-or-dir)
339 router-or-dir 394 router-or-dir
340 (directory-file-name router-or-dir)))) 395 (directory-file-name router-or-dir))))
341 (pattern (rx-form `(: bos ,(getenv "HOME")))) 396 (short-dirname (abbreviate-file-name default-directory))
342 (short-dirname (replace-regexp-in-string pattern "~" default-directory)) 397 (short-filename (abbreviate-file-name router-or-dir))
343 (short-filename (replace-regexp-in-string pattern "~" router-or-dir))
344 (buf-name (format "php -S %s:%s -t %s %s" 398 (buf-name (format "php -S %s:%s -t %s %s"
345 hostname 399 hostname
346 port 400 port
@@ -359,5 +413,40 @@ When `DOCUMENT-ROOT' is NIL, the document root is obtained from `ROUTER-OR-DIR'.
359 (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer) 413 (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer)
360 (format "*%s*" buf-name)))) 414 (format "*%s*" buf-name))))
361 415
416(defun php-ini ()
417 "Get `php --ini' output buffer."
418 (interactive)
419 (let ((buffer (get-buffer-create " *php --ini*")))
420 (with-current-buffer buffer
421 (view-mode -1)
422 (read-only-mode -1)
423 (erase-buffer)
424 (shell-command (concat php-executable " --ini") buffer)
425 (view-mode +1))
426 (if (called-interactively-p 'interactive)
427 (pop-to-buffer buffer)
428 buffer)))
429
430(defun php-find-system-php-ini-file (&optional file)
431 "Find php.ini FILE by `php --ini'."
432 (interactive
433 (list
434 (let* ((default-directory (expand-file-name "~"))
435 (buffer (php-ini))
436 (path (with-current-buffer buffer
437 (goto-char (point-min))
438 (save-match-data
439 (when (re-search-forward ": \\(.+?\\)$" nil nil)
440 (match-string 1))))))
441 (when (or (null path) (not (file-directory-p path)))
442 (when (called-interactively-p 'interactive)
443 (pop-to-buffer buffer))
444 (user-error "Failed get path to PHP ini files directory"))
445 (read-file-name "Find php.ini file: "
446 (concat (expand-file-name path) "/")
447 nil nil nil
448 #'file-exists-p))))
449 (find-file file))
450
362(provide 'php) 451(provide 'php)
363;;; php.el ends here 452;;; php.el ends here
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el
index 3bbb94d..bfd904e 100644
--- a/.emacs.d/lisp/yasnippet.el
+++ b/.emacs.d/lisp/yasnippet.el
@@ -386,7 +386,7 @@ It must be set to nil before loading yasnippet to take effect."
386;; Only two faces, and one of them shouldn't even be used... 386;; Only two faces, and one of them shouldn't even be used...
387;; 387;;
388(defface yas-field-highlight-face 388(defface yas-field-highlight-face
389 '((t (:inherit 'region))) 389 '((t (:inherit region)))
390 "The face used to highlight the currently active field of a snippet") 390 "The face used to highlight the currently active field of a snippet")
391 391
392(defface yas--field-debug-face 392(defface yas--field-debug-face
@@ -1399,6 +1399,9 @@ conditions to filter out potential expansions."
1399 (push (cons name template) acc)) 1399 (push (cons name template) acc))
1400 namehash)) 1400 namehash))
1401 (yas--table-hash table)) 1401 (yas--table-hash table))
1402 (maphash #'(lambda (uuid template)
1403 (push (cons uuid template) acc))
1404 (yas--table-uuidhash table))
1402 (yas--filter-templates-by-condition acc)))) 1405 (yas--filter-templates-by-condition acc))))
1403 1406
1404(defun yas--templates-for-key-at-point () 1407(defun yas--templates-for-key-at-point ()
@@ -4727,7 +4730,14 @@ When multiple expressions are found, only the last one counts."
4727 ;; 4730 ;;
4728 (save-excursion 4731 (save-excursion
4729 (while (re-search-forward yas--field-regexp nil t) 4732 (while (re-search-forward yas--field-regexp nil t)
4730 (let* ((real-match-end-0 (yas--scan-sexps (1+ (match-beginning 0)) 1)) 4733 (let* ((brace-scan (yas--scan-sexps (1+ (match-beginning 0)) 1))
4734 ;; if the `brace-scan' didn't reach a brace, we have a
4735 ;; snippet with invalid escaping, probably a closing
4736 ;; brace escaped with two backslashes (github#979). But
4737 ;; be lenient, because we can.
4738 (real-match-end-0 (if (eq ?} (char-before brace-scan))
4739 brace-scan
4740 (point)))
4731 (number (and (match-string-no-properties 1) 4741 (number (and (match-string-no-properties 1)
4732 (string-to-number (match-string-no-properties 1)))) 4742 (string-to-number (match-string-no-properties 1))))
4733 (brand-new-field (and real-match-end-0 4743 (brand-new-field (and real-match-end-0