From: James Cherti <contact@jamescherti.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Suggestion of enhancement by adding a hyphen to sh-imenu-generic-expression
Date: Sun, 24 Nov 2024 12:21:04 -0500 [thread overview]
Message-ID: <c7541461-93df-4836-a842-4d3c0fd96044@jamescherti.com> (raw)
In-Reply-To: <86h67xj7f0.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 894 bytes --]
Hello Eli,
Attached is the patch you requested for sh-script.el.
The patch enables the use of hyphens in Bash function names by adding a
regular expression for Bash to `sh-imenu-generic-expression`.
--
James Cherti
GitHub: https://github.com/jamescherti
Website: https://www.jamescherti.com/
On 2024-11-24 04:41, Eli Zaretskii wrote:
>> Date: Sat, 23 Nov 2024 16:04:17 -0500
>> From: James Cherti <contact@jamescherti.com>
>>
>> Hello,
>>
>> While editing a Bash shell script today, I discovered that imenu does
>> not include functions with hyphens in their names.
>>
>> While it is true that sh does not allow hyphens in function names, Bash
>> does permit them.
>>
>> My suggestion is to add a hyphen '-' to the sh-imenu-generic-expression
>> (sh-script.el) regular expression to make imenu include these functions,
>
> Would you like to submit a patch along these lines?
>
> Thanks.
[-- Attachment #2: bash-imenu-hyphen.patch --]
[-- Type: text/x-patch, Size: 1092 bytes --]
From 6f4d453e0eafe1e081d7f1dbef7d128497840dc0 Mon Sep 17 00:00:00 2001
From: James Cherti <contact@jamescherti.com>
Date: Sun, 24 Nov 2024 12:09:33 -0500
Subject: [PATCH] Add hyphen to Bash function names in
`sh-imenu-generic-expression`
---
lisp/progmodes/sh-script.el | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 8ba64100203..04d995d0404 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -300,6 +300,18 @@ sh-imenu-generic-expression
(nil
"^\\s-*\\([[:alpha:]_][[:alnum:]_]*\\)\\s-*()"
1)))
+ ;; The difference between the Bash regular expression and the sh regular
+ ;; expression is that Bash also allows hyphens (-).
+ (bash
+ . ((nil
+ ;; function FOO
+ ;; function FOO()
+ "^\\s-*function\\s-+\\([[:alpha:]_][[:alnum:]_-]*\\)\\s-*\\(?:()\\)?"
+ 1)
+ ;; FOO()
+ (nil
+ "^\\s-*\\([[:alpha:]_][[:alnum:]_-]*\\)\\s-*()"
+ 1)))
(mksh
. ((nil
;; function FOO
--
2.39.5
next prev parent reply other threads:[~2024-11-24 17:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-23 21:04 Suggestion of enhancement by adding a hyphen to sh-imenu-generic-expression James Cherti
2024-11-24 9:41 ` Eli Zaretskii
2024-11-24 17:21 ` James Cherti [this message]
2024-11-30 10:35 ` Eli Zaretskii
2024-11-30 13:28 ` Visuwesh
2024-11-30 14:02 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c7541461-93df-4836-a842-4d3c0fd96044@jamescherti.com \
--to=contact@jamescherti.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).