Author Topic: setting auto save file in "Tools" ?  (Read 8462 times)

Offline edison

  • Multiple posting newcomer
  • *
  • Posts: 53
setting auto save file in "Tools" ?
« on: September 12, 2014, 04:48:28 am »
The source formatter of CB is based on Astyle, It works great in most case but still have some bug(for example, it can not handle the noexcept of C++11 correctly sometimes).

So I decided try to set Clang-format as a item in the Tools menu. But I found there is a problem here:
The clang-format may change the content that was last version file I saved but not the current version file I edited. This behaviour would cause lost the the current content.

So, is there any CB macro or script can be used to save file and allow set before the called .exe in Tools's Executable input field ?
Or, if possible, add a auto save file option and a auto re-load file after .exe ran option would be much simple for using the "Tools" ...

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: setting auto save file in "Tools" ?
« Reply #1 on: September 12, 2014, 05:53:16 am »
My suggest:
Use C::B build-in Scripting commands - CodeBlocks, there is a Save function in EditorManager.

EDIT: also, read Variable expansion - CodeBlocks
« Last Edit: September 12, 2014, 05:58:38 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline edison

  • Multiple posting newcomer
  • *
  • Posts: 53
Re: setting auto save file in "Tools" ?
« Reply #2 on: September 12, 2014, 06:15:02 am »
I have try put these in the Executable input field:

SaveActive(); & $(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe
or
[[SaveActive();]] & $(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe
or
'SaveActive();' & $(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe

it does not works...
« Last Edit: September 12, 2014, 06:41:47 am by edison »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: setting auto save file in "Tools" ?
« Reply #3 on: September 12, 2014, 07:00:50 am »
Please read the two wiki pages carefully in my first replies.

Here is a minimal sample, you save all the files, and then run cmd.exe

Code
[[GetEditorManager().SaveAll();]] & cmd.exe

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: setting auto save file in "Tools" ?
« Reply #4 on: September 12, 2014, 07:23:30 am »
You might want to use SaveActive() instead of SaveAll(), so only the active editor gets saved.
I had to put a (sleep 1)before the exe-command, because sometimes the check for externally modified files does not kick in.
I think this happens because the saving might happen in the same second as the change by the external tool happens.
I don't know if there is such an easy command on windows or you need windows-scripting for it.
On linux I put
Code
[[ GetEditorManager().SaveActive(); ]] sleep 1 && 
before the executables name.

Offline edison

  • Multiple posting newcomer
  • *
  • Posts: 53
Re: setting auto save file in "Tools" ?
« Reply #5 on: September 12, 2014, 07:47:36 am »
Thanks a lot.
now this is working:
[[GetEditorManager().SaveActive();]] "$(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe"

but:
[[GetEditorManager().SaveActive();]] "timeout 1" && "$(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe"
still return a error status: 1966102423 (0x75305797)

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: setting auto save file in "Tools" ?
« Reply #6 on: September 12, 2014, 08:54:20 am »
Thanks a lot.
now this is working:
[[GetEditorManager().SaveActive();]] "$(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe"

but:
[[GetEditorManager().SaveActive();]] "timeout 1" && "$(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe"
still return a error status: 1966102423 (0x75305797)

Try:
[[GetEditorManager().SaveActive();]] cmd.exe /c "timeout 1" && "$(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe"

Offline edison

  • Multiple posting newcomer
  • *
  • Posts: 53
Re: setting auto save file in "Tools" ?
« Reply #7 on: September 12, 2014, 09:58:31 am »
That does not works here too.

I have not encounter any problems without the "pause stage" before run the clang-format (my files is not very big so far) , so the "[[GetEditorManager().SaveActive();]] "$(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe"" is ok for me.

I think if possible, it's better to add a "auto save option before call .exe" and a "auto re-load file(which should also allow bypass the "file changed" pop-up window)" in the Tools setting dialog box.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: setting auto save file in "Tools" ?
« Reply #8 on: September 12, 2014, 10:16:11 am »
Which windows version do you use ?

Offline edison

  • Multiple posting newcomer
  • *
  • Posts: 53
Re: setting auto save file in "Tools" ?
« Reply #9 on: September 12, 2014, 10:58:50 am »
Windows 8.1 x64.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: setting auto save file in "Tools" ?
« Reply #10 on: September 12, 2014, 12:00:59 pm »
Windows 8.1 x64.
Tested there.
The following works for me (not tested with clang-format):
Code
[[GetEditorManager().SaveActive();]] cmd.exe /c "timeout" "1" && "$(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe"

Offline edison

  • Multiple posting newcomer
  • *
  • Posts: 53
Re: setting auto save file in "Tools" ?
« Reply #11 on: September 12, 2014, 04:07:07 pm »
It works now! :)
Thanks a lot again.