gregsexton / origami.el

A folding minor mode for Emacs
510 stars 41 forks source link

Question regarding merging parsers #101

Open ThibautVerron opened 3 years ago

ThibautVerron commented 3 years ago

Hi,

I'm trying to write a parser for LaTeX more, leveraging the built-in support by outline-minor-mode and tex-fold-mode.

So far I've been trying to integrate those parsers myself, but it looks like origami does have a lot of functions for tree manipulation. Is there something which would allow to merge trees, shortening nodes if needed?

For instance, for a buffer:

begin type1
begin type2
begin type1
end type2
end type1
end type1

and a parser "type 1" making a tree

type 1 (line 1 to  6) 
    -- type 1 (line 3 to 5)

and a parser "type 2" making a tree

type 2 (line 2 to 4)

I'd like a resulting "merged" tree:

type 1 (line 1 to 6)
    -- type 2 (line 2 to 4)
        -- type 1 (line 3 to 4)

Is that already implemented, or should I carry on doing it by hand?

And more generally, what is the easiest way to test the functions in origami.el? For the parsers, I can get an idea of the structure of the tree by passing 'list as 'create, but it seems to break for the origami- functions, which I guess expect more structure out of 'create.

jcs090218 commented 3 years ago

You can open this in my branch here, https://github.com/jcs-elpa/origami.el.

See, https://github.com/gregsexton/origami.el/issues/99.

ThibautVerron commented 3 years ago

Hi, thanks for your answer!

It took me a while to figure out what branch you meant... I guess you meant fork?

I have read about why this fork was created on Melpa but I'm afraid that separating issues between upstream and fork is only going to add to the confusion. Especially considering that this issue is really a question and not a bug report, I think it is better for it to be where more people will see it. Hopefully it will contribute to the goal of having a better documentation for parsers everywhere.

Are you by any chance familiar with the relevant part of the code?

jcs090218 commented 3 years ago

It took me a while to figure out what branch you meant... I guess you meant fork?

Yes! Sorry for the confusion. I have changed my title to branch and fork!

I have read about why this fork was created on Melpa but I'm afraid that separating issues between upstream and fork is only going to add to the confusion. Especially considering that this issue is really a question and not a bug report, I think it is better for it to be where more people will see it. Hopefully it will contribute to the goal of having a better documentation for parsers everywhere.

Got it!

Are you by any chance familiar with the relevant part of the code?

Not really. I am reading the code now but in a very slow progress. As I mentioned in the thread here, https://github.com/jcs-elpa/origami.el/issues/1. I am looking for people to co-maintain or further develop this package together. Mainly due to the author's lack of activity. Therefore, everything I am trying to do here is to keep this package alive. 👍

jvasile commented 3 years ago

Hello, I am interested in orgami-mode for Latex. I came here to get some hints on implementing it and found this issue. I don't particularly care whether this gets implemented in origami-mode or as a parser defined in my .emacs. @ThibautVerron have you made any progress? If your WIP is in a repo somewhere, drop a link and I'll take a look. Thanks!

jcs090218 commented 3 years ago

Hi @jvasile,

If you are looking for merging multiple parsers then try my fork here. It allows you to merge multiple parsers to one parser by using function origami-fold-shallow-merge. From what I remember from this version of origami, it only accept merging 2 parsers.

If you are going to write your own parser for origami, then you should go check the file origami-parsers.el. My fork has more examples for you to reference it.

ThibautVerron commented 3 years ago

Hi @jvasile . No I have not made new progress since last time, but I would like to look at it again in the very near future.

I put the code I have so far on https://gitlab.com/thibaut.verron/latex-folding. As far as I remember it's far from working, but if @jcs090218's fork lets us merge parsers, it could be made to work without too much effort. I believe a lot of my problems were coming from the fact that I was trying to do the merge by hand.

Regarding the origami fork, my goal was to make a parser which returns begin and end folding points for any folding engine to use. As it turns out, at the moment origami is the only folding engine using such a parser, and it has facilities for merging trees, etc.

So the short term plan would be to have a parser working with origami. I don't think that the fork will break compatibility badly enough that origami parsers would stop working. In the longer run I guess I still want to merge the trees directly in the parser, in order to really have a parser working with any folding engine.

jvasile commented 3 years ago

Thanks for the pointers, @ThibautVerron. I'll take a look and keep an eye on @jcs090218's fork.