unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: haj@posteo.de (Harald Jörg)
Cc: "Clément Pit-Claudel" <cpitclaudel@gmail.com>, emacs-devel@gnu.org
Subject: Re: Handling extensions of programming languages
Date: Sun, 21 Mar 2021 08:39:12 -0400	[thread overview]
Message-ID: <jwva6qwy9ro.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87h7l43fa1.fsf@hajtower> ("Harald Jörg"'s message of "Sun, 21 Mar 2021 12:41:26 +0100")

>>> Well, I have my doubts that Perl is a good candidate for SMIE, and
>>> trying to use SMIE in CPerl mode would be a major rewrite anyway.  I
>>> guess the Emacs Losp basics (font-lock-add-keyword, hooks) will have to
>>> do the job.
>>
>> I'm pretty sure SMIE would work wonderfully for Perl, but I'm also not
>> sure how it relates to font-lock-add-keywords and hooks, so maybe
>> we're not thinking of the same thing?

FWIW, I'm sure SMIE could be made to work, but I highly doubt it would
"work wonderfully" in the sense that it would likely take a fair bit of
effort to make SMIE indent Perl mode as well as the current indentation
code in `cperl-mode` or in `perl-mode`.

>   class Coffee::Machine extends Lawn::Mower
>   {
>      has $grinder :reader :writer(replace_grinder)
>      method grind { ...; }
>   } 
[...]
>  - add "Dishwasher" and "clean_up" to the imenu index.

That seems to require AI (unless you're talking about a slightly
different example than the one quoted above ;-).

>  - make sure that indentation recognizes that the closing braces end a
>    statement after "class" and "method".  Perl syntax has various cases
>    where it doesn't.  I guess this is the part where SMIE would help.

Actually, the closing brace which also closes a statement is one of the
major pain points in `sm-c-mode`, so it would be one of the parts where
you'd need extra work to make SMIE understand what's going on.

> 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 indentation, it's fundamentally harder (for the same reason that
combining two LALR grammars doesn't necessarily give you an LALR
grammar), so it will have to be done in a somewhat ad-hoc way.
I suspect that if the base mode uses SMIE, it would make it
significantly easier to add extensions (because the structure of SMIE
imposes constraints that expose the "compositional" aspect of the
grammar, in some sense), but that's not what you have to work with
currently, so you're going to have to dig into the indentation code and
try and figure out how to make it work with your extension(s) and then
how to express the changes "from outside" (e.g. by using hooks,
`add-function`, or `advice-add`; we can of course add hooks
to `cperl-mode.el` or `perl-mode.el` to make that easier).


        Stefan




  reply	other threads:[~2021-03-21 12:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-19 18:53 Handling extensions of programming languages Harald Jörg
2021-03-20 17:02 ` Matt Armstrong
2021-03-20 23:40   ` Harald Jörg
2021-03-21  2:18     ` Clément Pit-Claudel
2021-03-21 11:41       ` Harald Jörg
2021-03-21 12:39         ` Stefan Monnier [this message]
2021-03-21 15:48           ` Harald Jörg
2021-03-21 17:59             ` Stefan Monnier
2021-03-22 14:08               ` Handling extensions of programming languages (Perl) Harald Jörg
2021-03-22 14:48                 ` Stefan Monnier
2021-03-22 17:32                   ` Harald Jörg
2021-03-22 18:27                     ` Stefan Monnier
2021-03-22 19:31                       ` Harald Jörg
2021-03-22 19:58                         ` [OFFTOPIC] " Stefan Monnier
2021-03-22 22:05                           ` Harald Jörg
2021-03-22 22:24                             ` Stefan Monnier
2021-03-22 23:43                               ` Harald Jörg
2021-03-23  3:49                                 ` [OFFTOPIC] " Stefan Monnier
2021-03-30 18:41             ` Handling extensions of programming languages Stephen Leake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwva6qwy9ro.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=cpitclaudel@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=haj@posteo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).