Bruce Dodson | 1 Feb 2006 08:21
Picon
Favicon

Re: Revision #6 to the job system

Hi April,

Congratulations, you're the lucky winner of ... a code 
review!  But I am not reviewing the JobQueue itself. 
Instead I will focus on how the SciTE Tools Menu and the 
Extensions interface with the new job system.  (Mainly 
because I worked on the Tools Menu and on the Extensions, so 
I have a personal interest in those parts.  But also because 
multithreaded code is hard to review, and I am lazy.)

1) As Neil pointed out, the correct model for setting up the 
function is like Open, not like SendEditor.  SendEditor and 
SendOutput are closures so that they can share the same 
code.  (A closure is just a function with some associated 
data: in this case, the extra data is a string that says 
where to send the message.)

 lua_pushliteral(luaState, "Open");
 lua_pushcfunction(luaState, cf_scite_open);
 lua_rawset(luaState, -3);

 lua_pushliteral(luaState, "Execute");
 lua_pushcfunction(luaState, cf_scite_execute);
 lua_rawset(luaState, -3);

The Lua API is stack-based, so it takes a bit of getting 
used to.  First you push the arguments, then you call the 
function.  The function call may reference other stack items 
by index; that's what the -3 is.  So here, if this were a 
normal C-style API, it would look something like this 
(Continue reading)

Istvan | 1 Feb 2006 13:32
Picon
Favicon

Lua question

Hi,

I wish to write a lua script which add this text:
Last Modified: 2006.02.01
at the top of the edited file when I save it.

I use OnSave() and I could add the text with these lines:
addtext="# Modified: "..os.date('%Y-%m-%d %H:%M:%S').."\r\n"
editor:InsertText(0,addtext)
It works well, without leaving the current position of the editor.

But my concern is that I couldn't update the text without jumping to begin of
the page. I tried editor:remove (and then insert again), but it jumped to begin of file.
Is there any way to update a text without jumping from the current position?

Thank you.
Istvan
Cowan, Hugh (MGS | 1 Feb 2006 16:32
Picon

RE: Using Regular Expressions with newline (\n) Character

Oh well, that's too bad.  But thanks for the reply and clarification. At least I can stop trying different
combinations to try and get it to work.

Hugh,

-----Original Message-----
From: scite-interest-bounces <at> lyra.org
[mailto:scite-interest-bounces <at> lyra.org]On Behalf Of Neil Hodgson
Sent: January 25, 2006 4:30 PM
To: Discussion of the SciTE editor
Subject: Re: [scite] Using Regular Expressions with newline (\n)
Character

Hugh:

> Is it possible to use the newline character (\n) in a regular expression
> with SciTE?

   No.

> I don't know if this is
> a bug, or it is simply not designed to work with the newline character?

   Its a limitation that I have no plans to improve.

   Neil

_______________________________________________
Scite-interest mailing list
Scite-interest <at> lyra.org
(Continue reading)

Kein-Hong Man | 1 Feb 2006 18:21
Picon

Re: Lua question

Istvan wrote:
> I wish to write a lua script which add this text:
> Last Modified: 2006.02.01
> at the top of the edited file when I save it.
> 
> I use OnSave() and I could add the text with these lines:
> addtext="# Modified: "..os.date('%Y-%m-%d %H:%M:%S').."\r\n"
> editor:InsertText(0,addtext)
> It works well, without leaving the current position of the editor.
> 
> But my concern is that I couldn't update the text without jumping to 
> begin of
> the page. I tried editor:remove (and then insert again), but it jumped 
> to begin of file.
> Is there any way to update a text without jumping from the current 
> position?

Try this:

   editor.TargetStart = editor:PositionFromLine(0)
   editor.TargetEnd = editor.LineEndPosition[0]
   editor:ReplaceTarget("# Modified: "..os.date('%Y-%m-%d %H:%M:%S'))

HTH,
--

-- 
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia
April White | 2 Feb 2006 01:54
Picon
Favicon

Re: Lua question

Istvan wrote:

> I wish to write a lua script which add this text:
> Last Modified: 2006.02.01
> at the top of the edited file when I save it.

I wrote something like this for my own use.  I can post my solution 
here, to the Lua-Users site, or by private email to yourself.

The only problem it seems to have is that the cursor is repositioned to 
where you left it, but the visible line on the screen may move.  I'm 
sure there is a solution, I've just not bothered to look into it.

April

--

-- 
As I learn the innermost secrets of people around me, they reward me in many ways to keep me quiet.
April White | 2 Feb 2006 02:50
Picon
Favicon

Re: Re: Revision #6 to the job system

Bruce Dodson wrote:

>Congratulations, you're the lucky winner of ... a code 
>review! 
>
Hello Bruce.  I feel so... special :-)

>1) As Neil pointed out, the correct model for setting up the 
>function is like Open, not like SendEditor. 
>  
>
I've altered this in my source.  Thank you Neil and Bruce.

>2) If it is necessary to add new methods to the 
>ExtensionAPI, I would try to keep them at a high level so 
>that other extensions (e.g. Director) can also use them 
>without having to copy boilerplate code from LuaExtension. 
>To that end, you might consider removing DecodeCommandMode 
>from ExtensionAPI, and changing AddJob to do that work. 
>AddJob could have this signature:
>
>  virtual bool AddJob(const char *jobCommand, const char 
>*jobDirectory, const char *jobMode, const char 
>*jobInput=0)=0;
>
>The implementation of AddJob would decode the mode string to 
>get the subsystem, save-before option, and flags.  Pass a 
>non-NULL for jobInput (even an empty string) and that means 
>jobHasInput gets added to the flags after the mode string is 
>decoded.  (Also, since the raw flags are not passed in to 
(Continue reading)

Neil Hodgson | 2 Feb 2006 03:22
Picon

Re: Re: Revision #6 to the job system

April White:

> Neil did not want an extension to interface to a SciTE method such as
> AddCommand(); AddJob() only has simple C parameter types

   One of the plans was to allow the extension interfaces to be used
from other languages or compilers through loading a DLL.

   Neil
Istvan | 2 Feb 2006 07:28
Picon
Favicon

Re: Lua question

Kein-Hong Man wrote:
> Istvan wrote:
>> I wish to write a lua script which add this text:
>> Last Modified: 2006.02.01
>> at the top of the edited file when I save it.
> Try this:
>   editor.TargetStart = editor:PositionFromLine(0)
>   editor.TargetEnd = editor.LineEndPosition[0]
>   editor:ReplaceTarget("# Modified: "..os.date('%Y-%m-%d %H:%M:%S'))

That works fine!
Now one think I don't like, after a Save, when do a Undo then I must undo 2 times
to undo the last operation. First will undo the addition for "# Modified ..." and
the second will undo the last operation.
Howe could I stop recording the undo operation for the writing of "# Modified ..."?

April White wrote:
> I wrote something like this for my own use.  I can post my solution 
> here, to the Lua-Users site, or by private email to yourself.
> The only problem it seems to have is that the cursor is repositioned to 
> where you left it, but the visible line on the screen may move.  
Please post it to the Lua-Users site. I'm very interested to see your solution.

Thank you!
Istvan
Kein-Hong Man | 2 Feb 2006 15:27
Picon

Re: Lua question

Istvan wrote:
> Kein-Hong Man wrote:
>> Istvan wrote:
>>> I wish to write a lua script which add this text:
>>> Last Modified: 2006.02.01
>>> at the top of the edited file when I save it.
>>
>> Try this:
>>   editor.TargetStart = editor:PositionFromLine(0)
>>   editor.TargetEnd = editor.LineEndPosition[0]
>>   editor:ReplaceTarget("# Modified: "..os.date('%Y-%m-%d %H:%M:%S'))
> 
> That works fine!
> Now one think I don't like, after a Save, when do a Undo then I must 
> undo 2 times
> to undo the last operation. First will undo the addition for "# Modified 
> ..." and
> the second will undo the last operation.
> Howe could I stop recording the undo operation for the writing of "# 
> Modified ..."?

Bracket with the following (barely tested):

   editor.UndoCollection = false
   -- edit stuff here
   editor.UndoCollection = true

HTH,
--

-- 
Cheers,
(Continue reading)

Bruce Dodson | 2 Feb 2006 23:28
Picon
Favicon

Re: Re: Revision #6 to the job system

Okay, in that case it would be a common method that is called by both AddJob 
and ToolsMenu, rather than having ToolsMenu call AddJob directly.  (Mainly 
for the sake of clenliness.)

There is some name confusion though.  SciTE is a sample application, not a 
library.  With that in mind, would it be okay to reconcile some of these 
names?  Right now we have AddCommand, AddJob, and Execute (plus whatever we 
call the worker method that gets invoked from both ToolsMenu and AddJob). 
It gets difficult to keep track.

Regards,
Bruce

* I like the idea of loadable extensions.  If nobody else is working on that 
right now, I may look into that personally.  (I assume this won't be 
stepping on April's toes, since it is not really tied to the Job system. 
Correct me if I'm wrong!)

"Neil Hodgson" <nyamatongwe <at> gmail.com> wrote in message 
news:50862ebd0602011822h6dca3b23p8773b04a3070b266 <at> mail.gmail.com...
> April White:
>
>> Neil did not want an extension to interface to a SciTE method such as
>> AddCommand(); AddJob() only has simple C parameter types
>
>   One of the plans was to allow the extension interfaces to be used
> from other languages or compilers through loading a DLL.
>
>   Neil 
(Continue reading)


Gmane