writing a new importer/writer

31 views
Skip to first unread message

Josef

unread,
Jun 3, 2019, 6:07:37 AM6/3/19
to leo-editor
For some time I have been thinking about writing an importer/writer for TaskJuggler and perhaps also LaTeX.
These would work similar to the ReST or MD importers/writers,
by turning task/section titles into headlines upon reading and turning them back on write.

The goal is to be able to re-organize a project by moving around nodes in the tree,
instead of cut-and-paste.
Moving tasks to different level or branches would require updating the references to other tasks (nodes) for TJ
and adjusting the section command on LaTeX, so I would need to link into the right hooks for that,
but that is already an advanced feature, not needed for the first cut.

I am not a programmer, and have never used Qt, but have used Python occasionally for small projects since version 1.3.

Where would I start? Should I start looking at the implementation of the ReST code?
Or should I first figure out how importing/writing is done generally?
Or should I first start with figuring out how to write a plugin?

- Josef

Edward K. Ream

unread,
Jun 3, 2019, 6:48:33 AM6/3/19
to leo-editor
On Mon, Jun 3, 2019 at 5:07 AM Josef <joe...@gmx.net> wrote:

For some time I have been thinking about writing an importer/writer for TaskJuggler and perhaps also LaTeX.
[snip]
I am not a programmer, and have never used Qt, but have used Python occasionally for small projects since version 1.3.

Where would I start? Should I start looking at the implementation of the ReST code?
Or should I first figure out how importing/writing is done generally?
Or should I first start with figuring out how to write a plugin?

Great questions.  First, some encouragement.  By far the best way to become a programmer is to have a juicy project to work on.  Which this certainly is ;-)

I'm not sure what the proper answers should be, but here goes...

1. Writing a plugin is easy.  I would start there. That will bring you up to speed on Python development within Leo.  Ask as many questions as you like. They will help other Leonistas who may be considering writing plugins or Leonine scripts.

2. Leo's markdown support is minimal at present, and Leo's rst3 code is extremely complex.  Way too complex, but that can't be helped now.  The only thing you have to know about the rst3 command is that it traverses an outline generating output text.

3. Next, I'd look at the Importer plugins and Writer plugins in leoPlugins(Ref).leo. The linescanner.py plugin contains common code for all importer plugins, contained in the Importer class. Many importers consist of just a few lines of code that modify the basic operation of linescanner. See this docstring:

leoPlugins.leo#Plugins-->Importer plugins-->
@file importers/linescanner.py--><< linescanner docstring >>

When you understand how linescanner.py provides "services" to other importers, you will understand (most of) how python allows classes to inherit methods from super classes.  That's a big deal.

Similarly, basewriter.py contains common code used by most writer plugins.  Writing is always easier than reading, so the BaseWriter class is much simpler than the Importer class in linescanner.py.

Most importers/writers come in pairs.  Take a look at one such pair and study it.

Above all, feel free to ask more questions here.

HTH.

Edward

Edward K. Ream

unread,
Jun 3, 2019, 6:58:10 AM6/3/19
to leo-editor
On Monday, June 3, 2019 at 5:48:33 AM UTC-5, Edward K. Ream wrote:
On Mon, Jun 3, 2019 at 5:07 AM Josef <joe...@gmx.net> wrote:

3. Next, I'd look at the Importer plugins and Writer plugins in leoPlugins(Ref).leo. The linescanner.py plugin contains common code for all importer plugins, contained in the Importer class. Many importers consist of just a few lines of code that modify the basic operation of linescanner.

My guess, and it's only a guess, is that you might want to do something like the org.py or otl.py importers/writers.  Both pairs of importers/exporters are relatively simple.  For each pair, the importer must accept what the writer writes, and vice versa.  This constraint isn't explicit in the code, iirc.

Edward
Reply all
Reply to author
Forward
0 new messages