Modefile editing: Swapping ModeFiles

Experimenting with changes in a ModeFile, I wanted to be able to swap back to the original to test the effect of the changes. Here is Fred's method. It involves changing the relevant ModeFile - so if you are wary of making such changes, keep a copy of the original.

The original ModeFile may well be in !StrongED.Defaults.Modes. in which case there should be no problem. The changes will be in !StrED_cfg.UserPrefs.Modes. so will not affect the original.

You cannot simply swap mode files whilst StrongED is running, for the ModeFile is only parsed when when StrongEd knows it needs parsing - either when StrongED is started or when the ModeFile is saved from StrongED. If you are editing a ModeFile then, when you save it, StrongED will parse it to check it makes sense. Of course even if your changes make sense to StrongED they may mot cause StrongEd to do what you intended. which is why the ability to swop back to an unchanged version can be useful.

I will use the Basemode in this example, but it can be applied to any mode.

The method

  1. First make sure that the ModeFiles that need to be swapped are in !StrED_cfg.UserPrefs.Modes.Basemode and that the alternative ModeFile is named ModeFileA. In that directory also create a directory called: Tools (if one does not already exist).

    You will probably want to implement this swapping before you start experimenting, in which case make the changes below to the ModeFile concerned and copy it as ModeFileA.

  2. Create an Obey file named SwapMF1 and save it in the Tools directory. SwapMF1 contents are:
    Set SwapMF$Dir <StrongED$Tmp_WriteDir>Modes.<StrongED$Tmp_ModeName>

    Rename <SwapMF$Dir>.ModeFile <SwapMF$Dir>.ModeFileB
    Rename <SwapMF$Dir>.ModeFileA <SwapMF$Dir>.ModeFile
    Rename <SwapMF$Dir>.ModeFileB <SwapMF$Dir>.ModeFileA

    Message StrongED_ExecCmds SetTmp() LoadOne("<StrongED$Tmp_ModePath>.ModeFile")
    Filer_Run <StrongED$Tmp_ModePath>.Tools.SwapMF2
    Unset SwapMF$Dir

  3. Create a second Obey file, SwapMF2, also in Tools that contains this:
    Message StrongED_ExecCmds SaveKill()
  4. Add a toolbar icon that runs the SwapMF1 to both ModeFiles:

    Functions
    tab/pngIcontab/pngsm!edit
    tab/pngSelecttab/pngSetTmp() Run("Filer_Run <StrongED$Tmp_ModePath>.Tools.SwapMF1")
    End
    If the ModeFile concerned already has a Functions secton you do not need the Functions and FunctionsEnd. Simply add the two lines into the Functions section.
  5. You can download a zip file containing these three scripts
Clicking on the new toolbar icon should now swap the ModeFiles and reparse the one now called ModeFile.

Testing

To test which ModeFile is active you can define a HotKey by adding a simple KeyList entry to each ModeFile:


KeyList
tab/pngc-Qtab/pngInsertStr("ModeFile")
End
The same for ModeFileA except that it should insert "ModeFileA".

After each click on the icon the inserted string should change, from 'ModeFile' to 'ModeFileA' then back to 'ModeFile' etc.

Was this page helpful? Please email me and/or rate this page:


If you want a reply make sure any email address @torrens.org will not get spam-binned!
Optional comment

Other relevant pages

Top of page


Page Information

http://css.torrens.org/valid-html401-bluehttp://css.torrens.org/valid-css Document URI: http://stronged.torrens.org/man/modes/examples/swap.html
Page first published 2nd of March, 2019
Last modified:Wed, 17 Jul 2019 14:34:35 BST
© 2018 - 2024 Richard Torrens.