lua scripting and other events
April White <awhite <at> mail.rosecom.ca>
2004-01-04 20:07:36 GMT
Hello everyone, and a Happy New Year belated
I was foreseeing a wee bit of snow around here today - damn late if you
ask me so I was going to play with SciTE and Lua some more.
Well, the snow has not arrived, but I'm still going to play!
I have successfully got everything to work together, even the interface
to all exposed functions in the .iface file. Thank you Neil and Bruce!
My current script file saves the current position when the file
is closed, and restores it when the file is opened again.
I have other ideas in my mind for what I want, but some of them are not
implementable via the existing events, nor possibly even new events.
For examine, while I am working on sorce code, I have a habit of placing
my name and date in a comment when I make a change. In the dos editor I
used, I could create hot-key shortcuts to functions that were then
compiled into the exe itself. This way, I hit Ctrl+Shift+D to insert
what I want.
I know I can write a script something like:
function Me( CommentCharacter )
CommentCharacter .. ' ' ..
os.getenv( "USERNAME" ) ..
os.date( " %Y-%m-%d %H:%M:%S" ) )
but how would SciTE access it?
I tried using the OnChar() event, but two difficulties quickly showed.
First, returning 1 or 0 did not tell SciTE to discard the key entered
- it got inserted into the file along with the comment; secondly, since
only the character itself it passed in and not any control/shift/alt
status, it would be hit-or-miss to get the proper key code. For
examine, string.byte( TheChar ) == 4 matched for Ctrl+Shift+D, but
nothing appeared for Ctrl+Alt+D.
So I got to thinking yes it is dangerous
The SciTE.h file states "These are located 100 apart. No one will want
more than 100 in each menu ;)", so there is already enough space for
custom commands, it should only be a matter of getting SciTE to retrieve
the proper script info and execute. If we assume that no more thank 10
commands will be associated with keyboard shortcuts, the other 90 should
be free to exploit.
If I added:
(where IDM_TOOL+20 would be replaced by the actual value)
command.20.*.cpp=Me( "// " );
command.20.*.bat=Me( "rem " );
command.20.*.lua=Me( "-- " );
Then SciTE detects that the command number is above the base 10 keyboard
values, retrieves the command and passes it onto Lua instead of the
I would hazard that either the command string be pre-processed by the
environment expansion code, or environment variables be made available
to Lua scripts so that current conditions may be determined.
ie. command.20.*=Me( "$(FileNameExt)" ) -- the script will determine
the command indicator to use based on the extension of the file
Comments, criticism, discussion... all are welcome, to help pass a
wonderfully snowy day in doors
If you want breakfast in bed, sleep in the kitchen.