@@ -227,7 +227,7 @@ it is the character that will terminate the string, or t if the string should be
227227 " Regular expression for a PHP function." )
228228
229229(eval-when-compile
230- (defun php-create-regexp-for-method (&optional visibility )
230+ (cl- defun php-create-regexp-for-method (&optional visibility & key include-args )
231231 " Make a regular expression for methods with the given VISIBILITY.
232232
233233VISIBILITY must be a string that names the visibility for a PHP
@@ -242,22 +242,25 @@ which will be the name of the method."
242242 (setq visibility (list visibility)))
243243 (rx-to-string `(: line-start
244244 (* (syntax whitespace))
245- ,@(if visibility
246- `((* (or " abstract" " final" " static" )
247- (+ (syntax whitespace)))
248- (or ,@visibility )
249- (+ (syntax whitespace))
250- (* (or " abstract" " final" " static" )
251- (+ (syntax whitespace))))
252- '((* (* (or " abstract" " final" " static"
253- " private" " protected" " public" )
254- (+ (syntax whitespace))))))
255- " function"
256- (+ (syntax whitespace))
257- (? " &" (* (syntax whitespace)))
258- (group (+ (or (syntax word) (syntax symbol))))
259- (* (syntax whitespace))
260- " (" )))
245+ (group
246+ ,@(if visibility
247+ `((* (or " abstract" " final" " static" )
248+ (+ (syntax whitespace)))
249+ (or ,@visibility )
250+ (+ (syntax whitespace))
251+ (* (or " abstract" " final" " static" )
252+ (+ (syntax whitespace))))
253+ '((* (* (or " abstract" " final" " static"
254+ " private" " protected" " public" )
255+ (+ (syntax whitespace))))))
256+ " function"
257+ (+ (syntax whitespace))
258+ (? " &" (* (syntax whitespace)))
259+ (group (+ (or (syntax word) (syntax symbol))))
260+ (* (syntax whitespace))
261+ " ("
262+ ,@(when include-args
263+ '((* any) line-end))))))
261264
262265 (defun php-create-regexp-for-classlike (type )
263266 " Accepts a `TYPE' of a 'classlike' object as a string, such as
@@ -275,30 +278,66 @@ can be used to match against definitions for that classlike."
275278 ; ; this is not necessarily correct for all values of `type' .
276279 " \\ s-+\\ (\\ (?:\\ sw\\ |\\\\\\ |\\ s_\\ )+\\ )" )))
277280
278- (defconst php-imenu-generic-expression
281+ (defconst php-imenu-generic-expression-default
279282 (eval-when-compile
280- `((" Namespaces"
281- ,(php-create-regexp-for-classlike " namespace" ) 1 )
283+ `((" Methods"
284+ ,(php-create-regexp-for-method nil :include-args t ) 1 )
285+ (" Properties"
286+ ,(rx line-start
287+ (* (syntax whitespace))
288+ (group
289+ (+ (or " public" " protected" " private" " static" " var" )
290+ (+ (syntax whitespace)))
291+ (* (? (? (or " |" " ?" ))
292+ (or " \\ " (syntax word) (syntax symbol))
293+ (+ (syntax whitespace))))
294+ " $" (+ (or (syntax word) (syntax symbol)))
295+ word-boundary))
296+ 1 )
297+ (" Constants"
298+ ,(rx line-start
299+ (* (syntax whitespace))
300+ (group
301+ (* (or " public" " protected" " private" )
302+ (+ (syntax whitespace)))
303+ " const"
304+ (+ (syntax whitespace))
305+ (+ (or (syntax word) (syntax symbol)))
306+ (* (syntax whitespace))
307+ (? " =" (* (syntax whitespace))
308+ (repeat 0 40 any))))
309+ 1 )
310+ (" Functions"
311+ ,(rx line-start
312+ (* (syntax whitespace))
313+ (group
314+ " function"
315+ (+ (syntax whitespace))
316+ (+ (or (syntax word) (syntax symbol)))
317+ (* (syntax whitespace))
318+ " ("
319+ (repeat 0 100 any)))
320+ 1 )
321+ (" Import"
322+ ,(rx line-start
323+ ; ; (* (syntax whitespace))
324+ (group
325+ " use"
326+ (+ (syntax whitespace))
327+ (repeat 0 100 any)))
328+ 1 )
282329 (" Classes"
283- ,(php-create-regexp-for-classlike " class" ) 1 )
284- (" Interfaces"
285- ,(php-create-regexp-for-classlike " interface" ) 1 )
286- (" Traits"
287- ,(php-create-regexp-for-classlike " trait" ) 1 )
288- (" All Methods"
289- ,(php-create-regexp-for-method) 1 )
290- (" Private Methods"
291- ,(php-create-regexp-for-method '(" private" )) 1 )
292- (" Protected Methods"
293- ,(php-create-regexp-for-method '(" protected" )) 1 )
294- (" Public Methods"
295- ,(php-create-regexp-for-method '(" public" )) 1 )
296- (" Anonymous Functions"
297- " \\ <\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*=\\ s-*f\\ (unctio\\ )?n\\ s-*(" 1 )
298- (" Named Functions"
299- " ^\\ s-*function\\ s-+\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*(" 1 )))
330+ ,(php-create-regexp-for-classlike " \\ (?:class\\ |interface\\ |trait\\ |enum\\ )" ) 0 )
331+ (" Namespace"
332+ ,(php-create-regexp-for-classlike " namespace" ) 1 )))
300333 " Imenu generic expression for PHP Mode. See `imenu-generic-expression' ." )
301334
335+ (defcustom php-imenu-generic-expression php-imenu-generic-expression-default
336+ " Default Imenu generic expression for PHP Mode. See `imenu-generic-expression' ."
337+ :type '(alist :key-type string
338+ :value-type list )
339+ :group 'php )
340+
302341(defconst php--re-namespace-pattern
303342 (eval-when-compile
304343 (php-create-regexp-for-classlike " namespace" )))
0 commit comments