LanX has asked for the wisdom of the Perl Monks concerning the following question:

When editing this code in emacs in cperl-mode

use Carp; sub tst1 { carp "bla"; } sub tst2 { tst1() } tst2();

and running M-x mode-compile

I'm getting this output in the compilation window

-*- mode: compilation; default-directory: "~/" -*-
Compilation started at Thu Aug 11 01:37:03

C:/Perl_64/bin\perl.exe -w d:/Users/LanX/AppData/Roaming/tst_carp.pl bla at d:/Users/LanX/AppData/Roaming/tst_carp.pl line 8. main::tst1() called at d:/Users/LanX/AppData/Roaming/tst_carp.pl line 12 main::tst2() called at d:/Users/LanX/AppData/Roaming/tst_carp.pl line 15

Compilation finished at Thu Aug 11 01:37:03

Please note that in the last two lines the last digit of the line number (marked blue) is missing.

This means, when I try navigating to the error-line (like clicking) I'll always land in the line 1 instead of 12 or 15.

I nailed down the problem to this part of mode-compile.el and added a regex to match line numbers followed by newlines

(defvar perl-compilation-error-regexp-alist ;; Contributed by Martin Jost '( ;; PERL 4 ("in file \\([^ ]+\\) at line \\([0-9]+\\).*" 1 2) ;; PERL 5 Blubber at FILE line XY, <XY> line ab. ("at \\([^ ]+\\) line \\([0-9]+\\)," 1 2) ;; PERL 5 Blubber at FILE line XY. ("at \\([^ ]+\\) line \\([0-9]+\\)." 1 2) ;; PERL 5 Blubber at FILE line XY ("at \\([^ ]+\\) line \\([0-9]+\\)\n" 1 2) ; <--- added by LanX ) ;; This look like a paranoiac regexp: could anybody find a better on +e? (which WORK). ;;'(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\ +)[\\.,]" 2 3)) "Alist that specifies how to match errors in perl output.

The snippet about a "paranoic regexp" was taken from an old version of cperl-mode.el which now DOES match the newline

from cperl-mode.el 6.2

;; NB as it stands the code in cperl-mode assumes this only has one ;; element. If XEmacs 19 support were dropped, this could all be simpl +ified. (defvar cperl-compilation-error-regexp-alist ;; This look like a paranoiac regexp: could anybody find a better on +e? (which WORKS). '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[ +\\., \n]" 2 3)) "Alist that specifies how to match errors in perl output.")

please note now its cperl-compilation-error-regexp-alist not perl-compilation-error-regexp-alist

Now my questions:

Any ideas?
update

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re: [emacs] mode-compile with carp output buggy
by Erez (Priest) on Aug 11, 2016 at 07:22 UTC

    I just re-ran this entire thing and couldn't replicate. My setup is:

    • GNU Emacs 25.1.50.8 (x86_64-unknown-linux-gnu, GTK+ Version 3.20.6
    • mode-compile-version is "2.29"
    • cperl-version is "6.2"

    As for the mode-compile relevant section, it's here:>/p>

    (defvar perl-compilation-error-regexp-alist ;; Contributed by Martin Jost '( ;; PERL 4 ("in file \\([^ ]+\\) at line \\([0-9]+\\).*" 1 2) ;; PERL 5 Blubber at FILE line XY, <XY> line ab. ("at \\([^ ]+\\) line \\([0-9]+\\)," 1 2) ;; PERL 5 Blubber at FILE line XY. ("at \\([^ ]+\\) line \\([0-9]+\\)." 1 2) ) ;; This look like a paranoiac regexp: could anybody find a better on +e? (which WORK). ;;'(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\ +)[\\.,]" 2 3)) "Alist that specifies how to match errors in perl output. See variable compilation-error-regexp-alist for more details.")

    Mayhap all you need is to upgrade?

    Principle of Least Astonishment: Any language that doesn’t occasionally surprise the novice will pay for it by continually surprising the expert

      Thanks!

      The latest stable emacs release is 24.5. That's also the cygwin version I also tested.

      Did you check mode-compile-version with c-h v ? ( my el file says 2.29 too ) Otherwise I don't see where to get this version.

      The regexes you show shouldn't work, at least with perl-mode.

      I suspect my cperl-mode.el regexes are ignored because of of aliasing both modes (Perl-mode is default, cPerl-mode must be activated by start up)

      Will dig into it.

      As a side note emacs urgently needs test suites...

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        Did you check mode-compile-version with c-h v

        No, you're right, it does say "mode-compile.el,v 2.28"

        Principle of Least Astonishment: Any language that doesn’t occasionally surprise the novice will pay for it by continually surprising the expert