-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
I'm working on aligning imenu with what's implemented in php-mode
:
(defconst php-imenu-generic-expression-simple
(eval-when-compile
`(("Methods"
,(php-create-regexp-for-method nil) 2)
("Properties"
,(rx line-start
(* (syntax whitespace))
(+ (or "public" "protected" "private" "static" "var")
(+ (syntax whitespace)))
(* (? (? (or "|" "?"))
(or "\\" (syntax word) (syntax symbol))
(+ (syntax whitespace))))
(group
"$" (+ (or (syntax word) (syntax symbol))))
word-boundary)
1)
("Constants"
,(rx line-start
(* (syntax whitespace))
(group
(* (or "public" "protected" "private")
(+ (syntax whitespace)))
"const"
(+ (syntax whitespace))
(+ (or (syntax word) (syntax symbol)))))
1)
("Functions"
,(rx line-start
(* (syntax whitespace))
"function"
(+ (syntax whitespace))
(group
(+ (or (syntax word) (syntax symbol)))))
1)
("Classes"
,(php-create-regexp-for-classlike "\\(?:class\\|interface\\|trait\\|enum\\)") 1)
("Namespace"
,(php-create-regexp-for-classlike "namespace") 1)))
"Imenu generic expression for PHP Mode. See `imenu-generic-expression'.")
In addition I'm trying to have similar imenu consult implementation to emacs-lisp-mode:
(defcustom consult-imenu-config
'((emacs-lisp-mode :toplevel "Functions"
:types ((?f "Functions" font-lock-function-name-face)
(?m "Macros" font-lock-function-name-face)
(?p "Packages" font-lock-constant-face)
(?t "Types" font-lock-type-face)
(?v "Variables" font-lock-variable-name-face))))
Here is what I have so far locally:
@zonuexe what do you think is it good direction?
(require 'consult-imenu)
(add-to-list 'consult-imenu-config '(php-ts-mode :toplevel "Namespace"
:types ((?n "Namespace" font-lock-function-name-face)
(?p "Properties" font-lock-type-face)
(?o "Constants" font-lock-type-face)
(?c "Classes" font-lock-type-face)
(?f "Functions" font-lock-function-name-face)
(?i "Imports" font-lock-type-face)
(?m "Methods" font-lock-function-name-face))))
I still have to finish a function to extract names for imports, properties, constants as they don't have :name property but I think I'm a right track.
(defun php-ts-mode--imenu-node-name (node)
"Imenu node name."
;;; TODO: traverse children based on node type
(message "%s : %s" node (treesit-node-text (treesit-node-child node 0)))
(treesit-node-text (treesit-node-child node 0)))
;; Imenu.
(setq-local treesit-simple-imenu-settings
`(("Namespace" "\\`namespace_definition\\'" nil nil)
("Classes" ,(rx bos (or "class_declaration"
"interface_declaration"
"enum_declaration"
"trait_declaration")
eos)
nil nil)
("Methods" "\\`method_declaration\\'" nil nil)
("Functions" "\\`function_definition\\'" nil nil)
("Constants" "\\`const_declaration\\'" nil php-ts-mode--imenu-node-name)
("Imports" "\\`namespace_use_declaration\\'"nil php-ts-mode--imenu-node-name)
("Properties" "\\`property_declaration\\'" nil php-ts-mode--imenu-node-name)))
zonuexe
Metadata
Metadata
Assignees
Labels
No labels