in reply to Hacking a source filter into the #! line

I have done some digging around LyX's source code and found some very interesting things. First, the LyX parser ignores commas, which means that the following is a valid (beginning of a) LyX source file:
#LyX 2.1 created this file. For more info see http://www.lyx.org/ \lyxformat, 474, \begin_document, \begin_header, \textclass, article, \begin_preamble, %ignore; use yX;

Notice the commas after every element? Those make it possible for perl to parse this document down to the "use yX", at which point the source filter can take over.

Unfortunately, I cannot find a way to override how LyX writes the contents of its files. Everything seems to boil down to calling the Buffer class's save method, which does not provide any runtime-modifiable hooks.

Perhaps I should take a different approach: defining a "Run Perl Source" output format. :-)

Replies are listed 'Best First'.
Re^2: Hacking a source filter into the #! line
by dcmertens (Scribe) on Jul 26, 2014 at 11:19 UTC
    To expand on the previous idea, LyX can produce lots of different document outputs including DVI, postscript, and PDF through multiple toolchains. I could add a "Run Perl" output document style, which would apply the source filter and run it. The problem is that the code is not run in a terminal (unless you started LyX in a terminal), so I would not be able to feed any arguments to the command. I tried invoking Prima, to see if I could provide a cross-platform mechanisms for getting user input, but encountered trouble. This still may be the best way to do things, but it'll be hard.