Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: edison on September 12, 2014, 04:48:28 am

Title: setting auto save file in "Tools" ?
Post by: edison 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" ...
Title: Re: setting auto save file in "Tools" ?
Post by: ollydbg on September 12, 2014, 05:53:16 am
My suggest:
Use C::B build-in Scripting commands - CodeBlocks (http://wiki.codeblocks.org/index.php?title=Scripting_commands), there is a Save function in EditorManager.

EDIT: also, read Variable expansion - CodeBlocks (http://wiki.codeblocks.org/index.php?title=Variable_expansion)
Title: Re: setting auto save file in "Tools" ?
Post by: edison 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...
Title: Re: setting auto save file in "Tools" ?
Post by: ollydbg 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

Title: Re: setting auto save file in "Tools" ?
Post by: Jenna 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.
Title: Re: setting auto save file in "Tools" ?
Post by: edison 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)
Title: Re: setting auto save file in "Tools" ?
Post by: Jenna 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"
Title: Re: setting auto save file in "Tools" ?
Post by: edison 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.
Title: Re: setting auto save file in "Tools" ?
Post by: Jenna on September 12, 2014, 10:16:11 am
Which windows version do you use ?
Title: Re: setting auto save file in "Tools" ?
Post by: edison on September 12, 2014, 10:58:50 am
Windows 8.1 x64.
Title: Re: setting auto save file in "Tools" ?
Post by: Jenna 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"
Title: Re: setting auto save file in "Tools" ?
Post by: edison on September 12, 2014, 04:07:07 pm
It works now! :)
Thanks a lot again.