gnu.emacs.bug
[Top] [All Lists]

perl-mode - fix syntax of anonymous sub prototypes

Subject: perl-mode - fix syntax of anonymous sub prototypes
From: "Giuliano Procida"
Date: Fri, 28 Mar 2008 17:37:08 +0000
Newsgroups: gnu.emacs.bug

Hi.

GNU Emacs 22.1.1 (i386-pc-solaris2.10, X toolkit) of 2008-02-11 on robot

Constructs like this:

    my $del = sub($) {
        my ($old) = @_;
        return if not active($old);
        &$delete_row($old->{$fde_id});
    };

upset later indentation as the $ in the sub($) has the default
backslash syntax class (instead of being treated specially as in
non-anonymous sub definitions) and then the "sub(" triggers the
hanging parens check.

The fix is to modify perl-font-lock-syntactic-keywords to have:

    ;; Funny things in sub arg specifications like `sub myfunc ($$)'
and `sub ($)'
    ("\\<sub\\(?:\\s-+\\S-+\\)?\\s-*(\\([^)]+\\))" 1 '(1))

instead of the existing regexp.

Here's a patch.

--- emacs/22.1/lisp/progmodes/perl-mode.el~   2008-03-28
17:19:19.267639000 +0000
+++ emacs/22.1/lisp/progmodes/perl-mode.el    2008-03-28
17:32:15.510903000 +0000
@@ -265,7 +265,7 @@
     ("\\$ ?{?^?[_a-zA-Z][_a-zA-Z0-9]*\\('\\)[_a-zA-Z]" (1 "_"))
     ;; format statements
     ("^[ \t]*format.*=[ \t]*\\(\n\\)" (1 '(7)))
-    ;; Funny things in sub arg specifications like `sub myfunc ($$)'
+    ;; Funny things in sub arg specifications like `sub myfunc ($$)'
and `sub ($)'
     ("\\<sub\\(?:\\s-+\\S-+\\)?\\s-*(\\([^)]+\\))" 1 '(1))
     ;; regexp and funny quotes
     ("[?:.,;=!~({[][ \t\n]*\\(/\\)" (1 '(7)))

This was really annoying me! If you need a proper test case Perl file,
I can cook one up.

Regards,
Giuliano Procida.



<Prev in Thread] Current Thread [Next in Thread>