Subject: bug#19754: sh-script.el: mostly wrong defun-prompt-regexp

From: Carlos Pita <[email-masked]>
Date: Mon, 2 Feb 2015 23:05:31 -0300

Tags: patch

The defun regexp is defined for sh-sript mode as:

  (setq-local defun-prompt-regexp
     (concat "^\\(function[ \t]\\|[[:alnum:]]+[ \t]+()[ \t]+\\)"))

At least in bash you have several valid forms not allowed by that regexp:

1) spaces between (, ), and { are optional

2) function name {...} (indeed, function {} is not even valid!)

3) function name () {...}

4) function          name() {...}

Also the concat seems pointless to me.

Here is a patched version:

(setq-local defun-prompt-regexp
        (concat
         "^\\("
         "\\(function[ \t]\\)?[ \t]*[[:alnum:]]+[ \t]*([ \t]*)"
         "\\|"
         "function[ \t]+[[:alnum:]]+[ \t]*\\(([ \t]*)\\)?"
         "\\)[ \t]*"))