Skip to content

Commit

Permalink
Added support for Imenu
Browse files Browse the repository at this point in the history
  • Loading branch information
tmythicator committed Jan 30, 2019
1 parent d6c48a1 commit 02b76ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog.MD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The changelog starts from version 0.1.4 as too much was added in each version be

- payable

- Added support for Imenu

## Version 0.1.9

- 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.
Expand Down
22 changes: 22 additions & 0 deletions solidity-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,24 @@ Cursor must be at the function's name. Does not currently work for constructors
(interactive)
(solidity--start-gasestimate (thing-at-point 'symbol 'no-properties)))

;;; Support for imenu
(defun solidity-mode-imenu-generic-expression ()
(let* ((spacetabs "[\t\n ]+")
(optional-spacetabs "[\t\n ]*")
(ident-group "\\([A-Za-z_][A-Za-z0-9_]*\\)")
(ctr-ident-group "\\(constructor\\)")
(modifier (mapconcat 'identity
'("payable" "public" "private" "external" "internal" "view" "pure")
"\\|"))
(modifiers (concat "\\(?:\\(?:" modifier "\\)" spacetabs "\\)*")))
`(("function", (concat "^" optional-spacetabs "function" spacetabs ident-group) 1)
("modifier", (concat "^" optional-spacetabs "modifier" spacetabs ident-group) 1)
("constructor", (concat "^" optional-spacetabs ctr-ident-group) 1)
("contract", (concat "^" optional-spacetabs "contract" spacetabs ident-group) 1)
("library", (concat "^" optional-spacetabs "library" spacetabs ident-group) 1)
("interface", (concat "^" optional-spacetabs "interface" spacetabs ident-group) 1)
)))

;;;###autoload
(define-derived-mode solidity-mode c-mode "solidity"
"Major mode for editing solidity language buffers."
Expand Down Expand Up @@ -524,6 +542,10 @@ Cursor must be at the function's name. Does not currently work for constructors
(set (make-local-variable 'comment-line-break-function)
'c-indent-new-comment-line)

;; set imenu
(setq imenu-generic-expression
(solidity-mode-imenu-generic-expression))

;; set keymap
(use-local-map solidity-mode-map)
;; set hooks
Expand Down

0 comments on commit 02b76ca

Please sign in to comment.