bug#46574: cperl-mode: Improve detection of entries for imenu [PATCH]
This patch helps CPerl mode to detect various declarations which should
go into the imenu index but were missed, and also prevents some false
positives from being included. Undetected package declarations also led
to wrong namespace attributions for subroutines declared within those
This comes with a new approach to handle Perl syntax: CPerl mode suffers
from a lot of very complex ad-hoc regular expressions, not always
consistent with each other, and very difficult to maintain. Instead, I
have created some regular expressions for basic syntactic building
blocks which I hope to use in upcoming refactorings to fix some
inaccuracies, and in particular to add support for "modern" or even
upcoming Perl syntax.
The regular expressions are built with rx syntax, but with the
restricted set of rx features which is available in Emacs 26.1 (as
eventually this should be the minimum version for an ELPA release).
These are the constructs which are now correctly processed:
> This patch helps CPerl mode to detect various declarations which should
> go into the imenu index but were missed, and also prevents some false
> positives from being included. Undetected package declarations also led
> to wrong namespace attributions for subroutines declared within those
I've only skimmed the patch, but it makes sense to me. When applying
it, though, patch said:
patching file lisp/progmodes/cperl-mode.el
Hunk #2 succeeded at 1210 (offset -41 lines).
Hunk #3 succeeded at 1367 (offset -41 lines).
Hunk #4 succeeded at 5286 (offset -41 lines).
Hunk #5 succeeded at 5368 (offset -41 lines).
Hunk #6 succeeded at 5403 (offset -41 lines).
Hunk #7 succeeded at 6734 (offset -41 lines).
Which is odd. Could you check whether the patch is against the current
> I've reviewed Stefan's changes now. There is definitely no conflict and
> the patch can be applied regardless of the offset. The offset mainly
> came with 24a98755 (Feb 13), where Stefan eliminated a length of
> obsolete documentation.
Thanks for checking; I've now applied your patch to Emacs 28.
> BTW: Stefan's cleanup work is great here.
> I've always wanted to start working on this but I am not confident
> enough. I don't know enough about the histories of (X)Emacs and
I'm a bit vague about the history of the mode, too, but it's OK to rip
out all XEmacs compat code (and compat code with Emacs < 26.1, I think).