Sign in to follow this  
Followers 0
Gene

StartScite

13 posts in this topic

#1 ·  Posted (edited)

Here is the scenario:

The text editor 'Crimson' has a cool feature. When you close it, it remembers all the files you had open and reopens them when you start it again. Scite does that too as long as you open it with no file(s) as parameters. If you open Scite by a file's association, it forgets all the files that were open the last time and only opens the associated file(s) that caused it to open.

Crimson on the other hand remembers the last file(s) and opens them and the associated file(s) that caused Crimson to open.

I was grousing to JdeB about this difference when he suggested that I write a script to make the behavior the same by editing the Scite session (Scite.ses) file. He helped me in that I forgot to add a @LF when writing to a file and showed me a better way to open a file when Scite is already open.

The program will:

- Read the File(s) you want to open from the $CMDLINE

- Add this/these file(s) to the Scite.ses file

- Start SciTE with StartScite.EXE

Then change the EDIT association of the AU3 extension to the compiled version of StartScite in stead of SciTE. Be sure the format is

<"driveletter:\path\StartSciTE.exe" "%1"> minus the angle brackets

If you have several files you like to have open and adjacent at the same time for one

or more projects, you can make a shortcut to StartScite.EXE for each project and

include all those files (au3 or not) on the commandline.

This should do the job !!

Gene

#include <Array.au3>

Global $asTarget[1]
$asTarget[0] = $CmdLine[0]

;Get target file from CmdLine
If $CmdLine[0] > 0 Then
For $i = 1 To $CmdLine[0]
  _ArrayAdd($asTarget, $CmdLine[$i])
Next
Else
MsgBox(0, "Error Message", "StartScite must have one or more commandline parameters.  Each parameter must be a file name with the .au3 extension.  StartScite will close in 5 seconds.", 5)
Exit
EndIf

$sSciteFullPath = RegRead("HKEY_CLASSES_ROOT\AutoIt3Script\Shell\Open\Command", "")
$iCount = StringInStr($sSciteFullPath, 'SciTE.exe" "%1"')
$iCount = $iCount - 1
$sSciteDirPath = StringTrimLeft(StringMid($sSciteFullPath, 1, $iCount), 1)

If ProcessExists("Scite.exe") Then
For $i = 1 To $CmdLine[0]
  Run('"' & $sSciteDirPath & 'Scite.EXE" "' & $CmdLine[$i] & '"')
Next
Else
$fFile = FileOpen($sSciteDirPath & "Scite.ses", 1)
For $i = 1 To $CmdLine[0]
  $asTarget[$i] = "<pos=1> " & $asTarget[$i]
  $iResult = FileWrite($fFile, $asTarget[$i] & @LF)
Next
FileClose($fFile)

Sleep(1000)

Run($sSciteDirPath & "Scite.EXE")
EndIf
Exit

The zipped .au3 file is attached. I hope this helps someone besides me. :lmao:

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites



Gene, a few questions/suggestions:

- Don't you want to give the focus to the file opened via the commandline when SciTE isn't running yet ? if so you need to add a minus to this code: "<pos=-1> "

- Why do you need the test for the number of parameters and add them to an Array? If not Parameters are given and SciTE isn't running yet, then just start SciTE with its current SciTE.ses.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

SciTE can accept a session file on the command line like this (Assume we are in SciTE's home directory):

SciTE.exe -loadsession:SciTE.ses

To open the session and a new file, you can use this:

SciTE.exe -loadsession:SciTE.ses au3.keywords.properties
With either a (simpler) script or perhaps some massaging of the command line for the context menu, this can be used.

And yes, this is an undocumented feature. I had to search the mailing list archives to find it. Also, remember, when using SciTE's command line arguments, slashes must be escaped.

Share this post


Link to post
Share on other sites

Even better than an AutoIt script is a Lua script which only executes once when SciTE starts which automatically loads the session file:

function LoadSessionAtStart()
    if props['session.loaded'] == "" then
        props['session.loaded'] = "1"
        scite.Open(props["FilePath"] .. "\nloadsession:" .. props["SciteDefaultHome"] .. "\\SciTE.ses")
    end
end

LoadSessionAtStart()

Place that at the top of SciTEStartup.lua or whatever script is specified by "ext.lua.startup.script".

If the script doesn't load the session file or it loads it more than once, please tell me your settings for the properties "ext.lua.auto.reload" and "ext.lua.reset".

Thanks for the idea, Gene.

Share this post


Link to post
Share on other sites

Gene, a few questions/suggestions:

- Don't you want to give the focus to the file opened via the commandline when SciTE isn't running yet ? if so you need to add a minus to this code: "<pos=-1> "

- Why do you need the test for the number of parameters and add them to an Array? If not Parameters are given and SciTE isn't running yet, then just start SciTE with its current SciTE.ses.

Thanks for the response.

I didn't reset the focus because I frequently open more than 1 file at a time via its assciation and there the focus would as likely be wrong as right.

I used the array because I plan to create several shortcuts to open specific sets of files at a time. I know, that will require me to close them before Scite so I don't have a zillion files open at a time. I already have a habit of working on the 2 or 3 files under the right most tabs and using those on the left as references/resources.

If several people ask I could add an INI file on first run that would implement resetting the focus. It could set it to the first or last file on the command line.

Gene


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

You're welcome Valik, the idea was mine and JdeB's.

Thanks for the response.

I know very little about Lua scripts, so I'm going to ask what may be a dumb question.

  • Where in your code below does the file/files being opened via association get opened in addition to the files in the session file?
  • Or does your script make Scite open via the session file before it opens the associated file(s)?
  • Or just make it open the session file too?
So far I haven't found anything in the Scite dir containing "ext.lua.startup.script". Sometimes when the PC hasn't been restarted in a while Search becomes less than reliable. I'll be back later.

Gene

Even better than an AutoIt script is a Lua script which only executes once when SciTE starts which automatically loads the session file:

function LoadSessionAtStart()
    if props['session.loaded'] == "" then
        props['session.loaded'] = "1"
        scite.Open(props["FilePath"] .. "\nloadsession:" .. props["SciteDefaultHome"] .. "\\SciTE.ses")
    end
end

LoadSessionAtStart()

Place that at the top of SciTEStartup.lua or whatever script is specified by "ext.lua.startup.script".

If the script doesn't load the session file or it loads it more than once, please tell me your settings for the properties "ext.lua.auto.reload" and "ext.lua.reset".

Thanks for the idea, Gene.


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I know very little about Lua scripts, so I'm going to ask what may be a dumb question.

  • Where in your code below does the file/files being opened via association get opened in addition to the files in the session file?

  • Or does your script make Scite open via the session file before it opens the associated file(s)?

  • Or just make it open the session file too?
So far I haven't found anything in the Scite dir containing "ext.lua.startup.script". Sometimes when the PC hasn't been restarted in a while Search becomes less than reliable. I'll be back later.
The SciTE4AutoIt3 installer doesn't have "ext.lua.startup.script" defined.

Here are the steps you need to do to make it work like Valik describes:

- add this line to SciTEUser.properties:

ext.lua.startup.script=$(SciteDefaultHome)\SciTEStartup.lua

-Create a File called SciTEStartup.lua in the SciTE program directory and put these lines in it:

function LoadSessionAtStart()
    if props['session.loaded'] == "" then
       props['session.loaded'] = "1"
       scite.Open(props["FilePath"] .. "\nloadsession:" .. props["SciteDefaultHome"] .. "\\SciTE.ses")
    end
end

LoadSessionAtStart()

The result is that you don't need the SciTEStartup program, but the LUA script will load the file from the Commandline and The SciTE.ses files......

Nice solution Valik :lmao:

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

H'mmmn, I don't seem to have "SciTEUser.properties" either. I have SciTEGlobal.properties, SciTE.properties and Scriptol.properties. I checked also for User.properties too.

I did create the SciTEStartup.lua file. Attached is a zipped dir listing of my SciTe folder.

Gene ;)

The SciTE4AutoIt3 installer doesn't have "ext.lua.startup.script" defined.

Here are the steps you need to do to make it work like Valik describes:

- add this line to SciTEUser.properties:

ext.lua.startup.script=$(SciteDefaultHome)\SciTEStartup.lua

-Create a File called SciTEStartup.lua in the SciTE program directory and put these lines in it:

function LoadSessionAtStart()
    if props['session.loaded'] == "" then
       props['session.loaded'] = "1"
       scite.Open(props["FilePath"] .. "\nloadsession:" .. props["SciteDefaultHome"] .. "\\SciTE.ses")
    end
end

LoadSessionAtStart()

The result is that you don't need the SciTEStartup program, but the LUA script will load the file from the Commandline and The SciTE.ses files......

Nice solution Valik :lmao:


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

SciTEUser.properties is in your profile directory. You can open it via the Options menu in SciTE.

Share this post


Link to post
Share on other sites

SciTEUser.properties is in your profile directory. You can open it via the Options menu in SciTE.

I did, pasted, closed, and tested. Worked as I expected. Thanks again Valik and as JdeB said "Nice solution". :lmao:

Even though my script is now pointless, I did do two new (for me) things in it.

Gene


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

Wow, I was wondering how to do that.

There is one problem,

Although it loads the files that were open and the file passed on the command line, it erases the MRU list. Any idea how to preserve the list.

Also (also since were on the subject of SciTE) is there a way to change "-" on the numeric key pad (block remarks) to another key or combination?

eltorro

Share this post


Link to post
Share on other sites

Wow, I was wondering how to do that.

There is one problem,

Although it loads the files that were open and the file passed on the command line, it erases the MRU list. Any idea how to preserve the list.

Also (also since were on the subject of SciTE) is there a way to change "-" on the numeric key pad (block remarks) to another key or combination?

eltorro

If you're talking Most Recently Used list, SciTe.recent is still there, but it isn't enumerated in the File drop down menu on startup. Anything you close in a session is listed, but not when restarted.

Gene


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

Found the key binding I was looking for.

In SciTE global properties, at or about line 468 find:

KeypadMinus|IDM_BLOCK_COMMENT|\

and put a # in front of it. Ctrl + Q still works for block commenting, uncommenting.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0