Created
April 6, 2020 23:19
-
-
Save matthewpersico/40a8de316bfc05a02582bf71fdd64dd1 to your computer and use it in GitHub Desktop.
Adding colon as a valid function character
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; sh-script-imode.el --- imenu does not recognize some legal bash constructs. | |
;;; Commentary: | |
;;; Dashes in function names. 2016-02-23 | |
;;; Colons in function names. 2020-04-06 | |
;;; Code: | |
;;; First, make sure to load shell mode. | |
(require 'sh-script) | |
;;; Now, redefine the function checker, ripped out of sh-script.el. We simply added '-:' | |
;;; next to each '_' in the regexps. | |
(defun sh-current-defun-name () | |
"Advice for sh-current-defun-name, adding - and : as legal function name chars." | |
(save-excursion | |
(end-of-line) | |
(when (re-search-backward | |
(concat "\\(?:" | |
;; function FOO | |
;; function FOO() | |
"^\\s-*function\\s-+\\\([[:alpha:]_:-][[:alnum:]_:-]*\\)\\s-*\\(?:()\\)?" | |
"\\)\\|\\(?:" | |
;; FOO() | |
"^\\s-*\\([[:alpha:]_:-][[:alnum:]_:-]*\\)\\s-*()" | |
"\\)\\|\\(?:" | |
;; FOO= | |
"^\\([[:alpha:]_:-][[:alnum:]_:-]*\\)=" | |
"\\)") | |
nil t) | |
(or (match-string-no-properties 1) | |
(match-string-no-properties 2) | |
(match-string-no-properties 3)))) | |
) | |
;;; Also, we custom defined sh-imenu-generic-expression by adding the '-' where | |
;;; needed. See below. | |
(setq sh-imenu-generic-expression | |
(quote | |
((sh | |
(nil "^\\s-*function\\s-+\\([[:alpha:]_:-][[:alnum:]_:-]*\\)\\s-*\\(?:()\\)?" 1) | |
(nil "^\\s-*\\([[:alpha:]_:-][[:alnum:]_:-]*\\)\\s-*()" 1))))) | |
(provide 'sh-script-imode) | |
;;; sh-script-imode.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment