unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* perl-mode - fix syntax of anonymous sub prototypes
@ 2008-03-28 17:37 Giuliano Procida
  2008-03-29  8:43 ` Giuliano Procida
  0 siblings, 1 reply; 6+ messages in thread
From: Giuliano Procida @ 2008-03-28 17:37 UTC (permalink / raw)
  To: bug-gnu-emacs

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.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: perl-mode - fix syntax of anonymous sub prototypes
  2008-03-28 17:37 perl-mode - fix syntax of anonymous sub prototypes Giuliano Procida
@ 2008-03-29  8:43 ` Giuliano Procida
  2008-03-29 14:58   ` Giuliano Procida
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Giuliano Procida @ 2008-03-29  8:43 UTC (permalink / raw)
  To: bug-gnu-emacs

I have verified the problem against a recent Ubuntu snapshot.

GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.9) of
2008-03-19 on vernadsky, modified by Debian

However, it looks like the latest HEAD has a completely different regexp.

    ;; Funny things in sub arg specifications like `sub myfunc ($$)'
    ;; Be careful not to match "sub { (...) ... }".
    ("\\<sub[[:space:]]+[^{}[:punct:][:space:]]+[[:space:]]*(\\([^)]+\\))"
1 '(1))

It is still wrong for anonymous subs. Should be (untested):

"\\<sub\\(?:[[:space:]]+[^{}[:punct:][:space:]]+\\)?[[:space:]]*(\\([^)]+\\))"

Here is a simple test case.

#!/usr/bin/perl

use strict;
use warnings;

# the $ in the next line has syntax-table (1)
sub add ($) {
    my ($a) = @_;
    # the $ in the next line does not
    return sub ($) {
	my ($b) = @_;
	return $a+$b;
	# the brace on the next line will be misindented on TAB
    };
}

# the following line will also be misindented on TAB
print "1+2=", &{add(1)}(2), "\n";

Regards,
Giuliano Procida.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: perl-mode - fix syntax of anonymous sub prototypes
       [not found] <mailman.9555.1206755263.18990.bug-gnu-emacs@gnu.org>
@ 2008-03-29 11:23 ` Joost Diepenmaat
  0 siblings, 0 replies; 6+ messages in thread
From: Joost Diepenmaat @ 2008-03-29 11:23 UTC (permalink / raw)
  To: gnu-emacs-bug

"Giuliano Procida" <giuliano.procida@googlemail.com> writes:

> 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});
>     };

/slighly related comment.

Just FYI, prototypes on anonymous subs are useless. As in; discarded by
the perl interpreter. I'm actually surprised it's even valid syntax.

Also, I would strongly recommend cperl-mode (which in fact does
recognize the construct) instead of perl-mode.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: perl-mode - fix syntax of anonymous sub prototypes
  2008-03-29  8:43 ` Giuliano Procida
@ 2008-03-29 14:58   ` Giuliano Procida
       [not found]   ` <mailman.9574.1206802710.18990.bug-gnu-emacs@gnu.org>
  2008-04-03 22:10   ` Stefan Monnier
  2 siblings, 0 replies; 6+ messages in thread
From: Giuliano Procida @ 2008-03-29 14:58 UTC (permalink / raw)
  To: bug-gnu-emacs

Joost Diepenmaat wrote:

> Just FYI, prototypes on anonymous subs are useless. As in; discarded by
> the perl interpreter. I'm actually surprised it's even valid syntax.

We are getting off-topic here but I disagree. It is useful to the
programmer or maintainer to see the argument structure at a glance
(especially when writing a lot of functional-style code). It could
even be useful to code analysis tools, though with Perl that's going
to be a bit hard. I think the language syntax is more regular with
this feature than without.

> Also, I would strongly recommend cperl-mode (which in fact does
> recognize the construct) instead of perl-mode.

I have found cperl-mode's defaults rather unpleasant and I don't want
to spend ages customising it to my taste (i.e., make it look like
perl-mode). I just use perl-mode and I will be happy if I can fix the
few issues I have with it.

Giuliano Procida




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: perl-mode - fix syntax of anonymous sub prototypes
       [not found]   ` <mailman.9574.1206802710.18990.bug-gnu-emacs@gnu.org>
@ 2008-03-29 15:39     ` Joost Diepenmaat
  0 siblings, 0 replies; 6+ messages in thread
From: Joost Diepenmaat @ 2008-03-29 15:39 UTC (permalink / raw)
  To: gnu-emacs-bug

"Giuliano Procida" <giuliano.procida@googlemail.com> writes:

> Joost Diepenmaat wrote:
>
>> Just FYI, prototypes on anonymous subs are useless. As in; discarded by
>> the perl interpreter. I'm actually surprised it's even valid syntax.
>
> We are getting off-topic here but I disagree. It is useful to the
> programmer or maintainer to see the argument structure at a glance
> (especially when writing a lot of functional-style code). [ snip ]

Except that that's not what (most) prototypes do in perl. At least not
when they're actually used by the compiler. If they're discarded you can
of course use them for whatever documentation you like, but you'd still
be confusing readers who think you to expected them to "work".

Just in case:
http://library.n0i.net/programming/perl/articles/fm_prototypes/

>> Also, I would strongly recommend cperl-mode (which in fact does
>> recognize the construct) instead of perl-mode.
>
> I have found cperl-mode's defaults rather unpleasant and I don't want
> to spend ages customising it to my taste (i.e., make it look like
> perl-mode). I just use perl-mode and I will be happy if I can fix the
> few issues I have with it.

Fair enough.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: perl-mode - fix syntax of anonymous sub prototypes
  2008-03-29  8:43 ` Giuliano Procida
  2008-03-29 14:58   ` Giuliano Procida
       [not found]   ` <mailman.9574.1206802710.18990.bug-gnu-emacs@gnu.org>
@ 2008-04-03 22:10   ` Stefan Monnier
  2 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2008-04-03 22:10 UTC (permalink / raw)
  To: Giuliano Procida; +Cc: bug-gnu-emacs

>     ;; Funny things in sub arg specifications like `sub myfunc ($$)'
>     ;; Be careful not to match "sub { (...) ... }".
>     ("\\<sub[[:space:]]+[^{}[:punct:][:space:]]+[[:space:]]*(\\([^)]+\\))"
> 1 '(1))

> It is still wrong for anonymous subs. Should be (untested):

> "\\<sub\\(?:[[:space:]]+[^{}[:punct:][:space:]]+\\)?[[:space:]]*(\\([^)]+\\))"


Thanks, installed,


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-04-03 22:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-28 17:37 perl-mode - fix syntax of anonymous sub prototypes Giuliano Procida
2008-03-29  8:43 ` Giuliano Procida
2008-03-29 14:58   ` Giuliano Procida
     [not found]   ` <mailman.9574.1206802710.18990.bug-gnu-emacs@gnu.org>
2008-03-29 15:39     ` Joost Diepenmaat
2008-04-03 22:10   ` Stefan Monnier
     [not found] <mailman.9555.1206755263.18990.bug-gnu-emacs@gnu.org>
2008-03-29 11:23 ` Joost Diepenmaat

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).