News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

setting auto save file in "Tools" ?

Started by edison, September 12, 2014, 04:48:28 AM

Previous topic - Next topic

edison

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" ...

ollydbg

#1
My suggest:
Use C::B build-in Scripting commands - CodeBlocks, there is a Save function in EditorManager.

EDIT: also, read Variable expansion - CodeBlocks
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.

edison

#2
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...

ollydbg

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


[[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.

Jenna

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 [[ GetEditorManager().SaveActive(); ]] sleep 1 && before the executables name.

edison

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)

Jenna

Quote from: 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)

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

edison

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.

Jenna


edison


Jenna

Quote from: edison on September 12, 2014, 10:58:50 AM
Windows 8.1 x64.
Tested there.
The following works for me (not tested with clang-format):
[[GetEditorManager().SaveActive();]] cmd.exe /c "timeout" "1" && "$(CODEBLOCKS)\sdk\LLVM\bin\clang-format.exe"

edison