SciTELuaExporters is
a set
of Lua scripts for use with SciTE's Lua
extension (present in SciTE
1.60 and later) that more or less duplicates the functionality of the
standard set of SciTE file exporters. These scripts were adapted from
C++ code in SciTE (in src/Exporters.cxx), originally in support of a
project to develop a feature-ful PDF exporter for SciTE. The planned
PDF exporter is in development (update:
this is in hiatus, because the SXW exporter currently meets my
requirements quite well,) but in the meantime, I ported
over all the exporters (for HTML, PDF, RTF, TeX and XML) to give myself
some experience of writing SciTE
extensions in Lua.
These scripts are not meant to replace the existing exporters, but to supplement them for advanced SciTE users. They are also a kind of proof-of-concept of writing sophisticated scripts using the Lua extension. You might find these scripts useful if:
SciTELuaExporters uses the same MIT-style license as SciTE, and is
being distributed in the spirit of sharing. Should you find these
scripts useful, consider sharing your code as well under the terms of
the MIT license, or linking back to
this package, or sharing your experience. New exporters are welcome;
there may be practical limits to how many file exporters one can put in
SciTE, but there are no such limits to user-selectable and
user-customizable Lua scripts. The basic set of exporters will be kept
similar to their compiled counterparts, and modified versions will be
maintained as separate files.
Main links: Project Home Page on LuaForge
| Project Summary
Page on LuaForge | LuaForge
File
Releases: download SciTELuaExporters-0.9.7.zip
(70KB).
This release should be considered to be of beta quality. They
have been tested with several lexers, and are quite robust. A 1.0
release will be made later, when the exporters have got a bit more of a
workout.
What's new?
You need to be running a recent version of SciTE. The scripts were developed to run on a self-compiled vanilla Win32 SciTE that is a bit later than 1.61. I don't use Linux that much, so I haven't had much chance to test the scripts extensively on the Linux version of SciTE. If you are a serious user of SciTE Lua scripts, I recommend placing all Lua scripts in a separate subdirectory in your Win32 SciTE installation. Then, put the following line (or something like it) in your user properties file:
ext.lua.startup.script=$(SciteDefaultHome)/script/SciTEStartup.lua
Keeping all Lua scripts in a /script
directory will make maintenance easier. Please read the SciTE
documentation
(SciTEDoc.html) for the details on configuration. Upgrading simply
means copying the /script
directory and your user properties file over, it's that simple. There
are 6 separate exporters, for HTML, PDF, RTF, SXW, TeX and XML. Some
exporters have an extended version with additional features,
Step 1 is to load the scripts. You can place the following in your SciTEStartup.lua file to make loading of scripts easier:
function loadscript(scriptfile)The function will load a given script filename from the /script directory. If all your SciTE Lua scripts are in the same directory, then the usual Ctrl+Shift+O will very quickly open the script file under the caret.
Step 2 is to install an exporter function as a shortcut. When developing Lua-scripted SciTE functions, I add the following in SciTEUser.properties:
command.name.1.*=Experimental Script
command.subsystem.1.*=3
command.1.*=experimental
command.save.before.1.*=2
This will bind the Lua function experimental() to Ctrl-1. Then you can call the exporter function you want by writing a function like this in your SciTEStartup.lua file:
function experimental()
exporters:SaveToHTML()
end
By default, an exporter will open the output window and print a helpful message, including the full path of the file it is writing. Exporters will never overwrite any existing file, but will append a number to the exported filename to create a new, unique filename. Be warned, though, that exporting very large files takes several seconds, longer still on slow machines. You can force exporters to be silent using:
ext.lua.exporters.verbose=0
The exporters should be quite robust. If they crash, please let me
know.
The following are non-script files:
The following are the base script files:
The following are extended script files:
SciTE_ExportBase.lua
provides a number of functions, variables and constants to perform some
common tasks required for exporting data. All functions, variables and
constants are defined in two tables, exportutil, containing export
utility functions, and stylemgr,
containing style management functions. The exporters themselves are
located in separate self-contained files, and each exporter creates a
function in the exporters
table. If these three tables collides with the Lua namespace in your
SciTE setup, you will have to change the names of the tables.
SciTE_ExportTemplate.lua
is a sample exporter that is public domain code, and is heavily
commented for developers of Lua-based SciTE exporters.
Here is a summary of the functions found in SciTE_ExportBase.lua.
Currently, the style manager can handle a single style set only. To see
usage examples, look at the working exporters.
The exporters that are currently implemented in this distribution
are:
Step 1 is to initialize the
style manager using the current lexer
number or name:
Step 2 is to grab the
styles you want to access using the stylemgr:locate function, then
either assigning the return style table to your own variable, or access
the list of styles after calling the function. The former is done like
this:
The style table can be accessed in a variety of methods. Use
whatever method you like, keeping in mind readability is important when
writing a script you expect others to use and extend. For example:
The global default styles are created when the style manager is
initialized, as the list stylemgr.basestyles,
as opposed to the style list for the current lexer, which is processed
on-demand, and is named stylemgr.styles.
The default style for each list is always the usual style 32. The other
predefined styles that have specific usage are numbered 33 to 37. I
don't think they appear when processing a normal document, but you can
access and use them if you want to, using the usual stylemgr:locate function.
Style information is returned in a table with all field elements
always filled in. If a property does not explicitly specify a field,
then that field is inherited from the base style (style 32). Fields
that are explicitly specified have their field names added to a string,
the specified field. This
is probably not a very high-performance method but it works well and is
readable.
The table fields are as follows:
An exporter should accept an editor start position and an end
position. By using editor positions, an exporter can easily export the
whole file or a selected part of it. exportutil.GetSelPos() helps
with getting the position information during execution. If you need to
process the document line-by-line, you can retrieve the line number
using the appropriate SciTE API calls, like editor:GetLine. For more on
writing exporters, look at the completed ones found in this package.
pdf_linenumbers.diff is
an example of a feature. The diff adds optional line numbering to the
PDF exporter, all in less than 20 lines of Lua code and less than half
an hour's work. The upshot of it is that you do not have to customize
and recompile the SciTE binaries; you just need to move a portable
custom Lua script when upgrading.
SciTE is principally developed by Neil Hodgson, with the help of
many contributors, and can be found at:
http://scintilla.sourceforge.net/SciTE.html.
Bruce Dodson did much of the work to make the Lua extension usable.
Thanks to the LuaForge team for
hosting this material. This page was written on Mozilla. SciTELuaExporters was
developed on SciTE,
which I compiled on MinGW, thanks
to GNU software.
I consider the basic set of Lua exporters a straightforward conversion from C/C++ code, so I decline to claim them as my own code. Neil Hodgson's Scintilla/SciTE license applies to these scripts. The code for the Lua exporter support routines (SciTE_ExportBase.lua) and other exporters are either copyrighted by me or their respective authors, and the same MIT-style license applies. You can basically do almost anything you like to the scripts and this documentation except claim it as your own. The license text can be found at the beginning of each script.