emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handling extensions of programming languages


From: Stefan Monnier
Subject: Re: Handling extensions of programming languages
Date: Sun, 21 Mar 2021 13:59:29 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> But, jokes aside: I actually consider adding entries to the imenu index
> _which aren't there._ In the example above, Object::Pad will silently
> create the methods `grinder' and `replace_grinder'.  I think these
> *should* go to imenu because if your code in another source calls
> $cm->grinder you might otherwise have a hard time finding where that
> routine is declared.

I don't see any problem with that.  You could even argue that they
*are* there.

>>> For the latter two tasks, I need to "hook" the logic somehow into
>>> CPerl's implementations of `imenu-create-index-function' and the various
>>> indentation functions.  The current indentation code in CPerl mode
>>> is... a bit messy, and some old bugs call for attention anyway.
>> AFAIK font-lock and imenu are easy.  For font-lock there's
>> `font-lock-add-keywords` and for imenu, you should be able to make it
>> work fairly well with just `add-function` to
>> `imenu-create-index-function`.
> For certain values of easy :).

I meant "easy" in the sense that once you've figured out how to match
those constructs and how to put the right face on the various parts,
adding it modularly (e.g. from a minor mode) should be reasonably easy,
because it shouldn't interact in too complex ways with the rest of the
font-lock rules.

> Your last parens touch another interesting aspect: Can that stuff be
> used by cperl-mode.el _and_ perl-mode.el?

For imenu and font-lock, I can't see why not.

> Well, as it turns out, the font-lock stuff "works" for both.  It looks a
> bit weird with Perl mode because the "new" keywords like `method' have
> different faces than the "old" ones like `my'.

I'm not sure why that would be: AFAICT, both `perl-mode` and
`cperl-mode` highlight keywords (like `sub`, `if`, `for`, ...) using the
`font-lock-keyword-face` (they generally use fairly different faces, but
this is a part where they agree ;-).

> For imenu, things are different: Perl mode uses
> `imenu-generic-expression', whereas CPerl mode uses a rather complex
> `imenu-create-index-function ', so that it can prepend the current
> namespace to the name of functions.

If you code uses `add-function` on `imenu-create-index-function` it
should work in both cases (`perl-mode` simply keeps the default value
of `imenu-create-index-function` which is the function that implements
`imenu-generic-expression`).

> And as for indentation...  I'd say the code in both modes needs to catch
> up with current perl before we consider extensions.  Maybe they could
> share functions or regular expressions how to find the beginning of a
> function, or how to identify closing braces which terminate a statement:
> The specification for this logic comes from Perl and should be the same
> for both modes.

Consolidation between the two modes is progress, so you got my vote.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]