@@ -227,7 +227,7 @@ it is the character that will terminate the string, or t if the string should be
227
227
" Regular expression for a PHP function." )
228
228
229
229
(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 )
231
231
" Make a regular expression for methods with the given VISIBILITY.
232
232
233
233
VISIBILITY must be a string that names the visibility for a PHP
@@ -242,22 +242,25 @@ which will be the name of the method."
242
242
(setq visibility (list visibility)))
243
243
(rx-to-string `(: line-start
244
244
(* (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))))))
261
264
262
265
(defun php-create-regexp-for-classlike (type )
263
266
" Accepts a `TYPE' of a 'classlike' object as a string, such as
@@ -275,7 +278,101 @@ can be used to match against definitions for that classlike."
275
278
; ; this is not necessarily correct for all values of `type' .
276
279
" \\ s-+\\ (\\ (?:\\ sw\\ |\\\\\\ |\\ s_\\ )+\\ )" )))
277
280
278
- (defconst php-imenu-generic-expression
281
+ (defconst php-imenu-generic-expression-default
282
+ (eval-when-compile
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 )
329
+ (" Classes"
330
+ ,(php-create-regexp-for-classlike " \\ (?:class\\ |interface\\ |trait\\ |enum\\ )" ) 0 )
331
+ (" Namespace"
332
+ ,(php-create-regexp-for-classlike " namespace" ) 1 )))
333
+ " Imenu generic expression for PHP Mode. See `imenu-generic-expression' ." )
334
+
335
+ (defconst php-imenu-generic-expression-simple
336
+ (eval-when-compile
337
+ `((" Methods"
338
+ ,(php-create-regexp-for-method nil ) 2 )
339
+ (" Properties"
340
+ ,(rx line-start
341
+ (* (syntax whitespace))
342
+ (+ (or " public" " protected" " private" " static" " var" )
343
+ (+ (syntax whitespace)))
344
+ (* (? (? (or " |" " ?" ))
345
+ (or " \\ " (syntax word) (syntax symbol))
346
+ (+ (syntax whitespace))))
347
+ (group
348
+ " $" (+ (or (syntax word) (syntax symbol))))
349
+ word-boundary)
350
+ 1 )
351
+ (" Constants"
352
+ ,(rx line-start
353
+ (* (syntax whitespace))
354
+ (group
355
+ (* (or " public" " protected" " private" )
356
+ (+ (syntax whitespace)))
357
+ " const"
358
+ (+ (syntax whitespace))
359
+ (+ (or (syntax word) (syntax symbol)))))
360
+ 1 )
361
+ (" Functions"
362
+ ,(rx line-start
363
+ (* (syntax whitespace))
364
+ " function"
365
+ (+ (syntax whitespace))
366
+ (group
367
+ (+ (or (syntax word) (syntax symbol)))))
368
+ 1 )
369
+ (" Classes"
370
+ ,(php-create-regexp-for-classlike " \\ (?:class\\ |interface\\ |trait\\ |enum\\ )" ) 1 )
371
+ (" Namespace"
372
+ ,(php-create-regexp-for-classlike " namespace" ) 1 )))
373
+ " Imenu generic expression for PHP Mode. See `imenu-generic-expression' ." )
374
+
375
+ (defconst php-imenu-generic-expression-legacy
279
376
(eval-when-compile
280
377
`((" Namespaces"
281
378
,(php-create-regexp-for-classlike " namespace" ) 1 )
@@ -288,17 +385,25 @@ can be used to match against definitions for that classlike."
288
385
(" All Methods"
289
386
,(php-create-regexp-for-method) 1 )
290
387
(" Private Methods"
291
- ,(php-create-regexp-for-method '(" private" )) 1 )
388
+ ,(php-create-regexp-for-method '(" private" )) 2 )
292
389
(" Protected Methods"
293
- ,(php-create-regexp-for-method '(" protected" )) 1 )
390
+ ,(php-create-regexp-for-method '(" protected" )) 2 )
294
391
(" Public Methods"
295
- ,(php-create-regexp-for-method '(" public" )) 1 )
392
+ ,(php-create-regexp-for-method '(" public" )) 2 )
296
393
(" Anonymous Functions"
297
394
" \\ <\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*=\\ s-*f\\ (unctio\\ )?n\\ s-*(" 1 )
298
395
(" Named Functions"
299
396
" ^\\ s-*function\\ s-+\\ (\\ (?:\\ sw\\ |\\ s_\\ )+\\ )\\ s-*(" 1 )))
300
397
" Imenu generic expression for PHP Mode. See `imenu-generic-expression' ." )
301
398
399
+ (defcustom php-imenu-generic-expression 'php-imenu-generic-expression-default
400
+ " Default Imenu generic expression for PHP Mode. See `imenu-generic-expression' ."
401
+ :type '(choice (alist :key-type string :value-type list )
402
+ (const 'php-imenu-generic-expression-legacy )
403
+ (const 'php-imenu-generic-expression-simple )
404
+ variable)
405
+ :group 'php )
406
+
302
407
(defconst php--re-namespace-pattern
303
408
(eval-when-compile
304
409
(php-create-regexp-for-classlike " namespace" )))
0 commit comments