Skip to content

Commit 02b76ca

Browse files
committed
Added support for Imenu
1 parent d6c48a1 commit 02b76ca

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

changelog.MD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ The changelog starts from version 0.1.4 as too much was added in each version be
1414

1515
- payable
1616

17+
- Added support for Imenu
18+
1719
## Version 0.1.9
1820

1921
- Integrated [company-solidity](https://github.com/ssmolkin1/company-solidity) into solidity-mode, providing autocompletion out of the box if the user has [company-mode](http://company-mode.github.io) installed.

solidity-mode.el

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,24 @@ Cursor must be at the function's name. Does not currently work for constructors
493493
(interactive)
494494
(solidity--start-gasestimate (thing-at-point 'symbol 'no-properties)))
495495

496+
;;; Support for imenu
497+
(defun solidity-mode-imenu-generic-expression ()
498+
(let* ((spacetabs "[\t\n ]+")
499+
(optional-spacetabs "[\t\n ]*")
500+
(ident-group "\\([A-Za-z_][A-Za-z0-9_]*\\)")
501+
(ctr-ident-group "\\(constructor\\)")
502+
(modifier (mapconcat 'identity
503+
'("payable" "public" "private" "external" "internal" "view" "pure")
504+
"\\|"))
505+
(modifiers (concat "\\(?:\\(?:" modifier "\\)" spacetabs "\\)*")))
506+
`(("function", (concat "^" optional-spacetabs "function" spacetabs ident-group) 1)
507+
("modifier", (concat "^" optional-spacetabs "modifier" spacetabs ident-group) 1)
508+
("constructor", (concat "^" optional-spacetabs ctr-ident-group) 1)
509+
("contract", (concat "^" optional-spacetabs "contract" spacetabs ident-group) 1)
510+
("library", (concat "^" optional-spacetabs "library" spacetabs ident-group) 1)
511+
("interface", (concat "^" optional-spacetabs "interface" spacetabs ident-group) 1)
512+
)))
513+
496514
;;;###autoload
497515
(define-derived-mode solidity-mode c-mode "solidity"
498516
"Major mode for editing solidity language buffers."
@@ -524,6 +542,10 @@ Cursor must be at the function's name. Does not currently work for constructors
524542
(set (make-local-variable 'comment-line-break-function)
525543
'c-indent-new-comment-line)
526544

545+
;; set imenu
546+
(setq imenu-generic-expression
547+
(solidity-mode-imenu-generic-expression))
548+
527549
;; set keymap
528550
(use-local-map solidity-mode-map)
529551
;; set hooks

0 commit comments

Comments
 (0)