Using clang tools with atom


I use clang tools such as clang-format.
I currently am using command-palette to execute the command.
I would like to overwrite my existing source file with the clang-formated output and reload the source file programmatically .
Any suggestions?
Thanks in advance.


What options do you have to export output formatted by clang?


None that are built-in. Clang tools are console tools and the output is displayed there, on stdout.
So, to send the output to a file means using redirection built-in to the OS. For example
clang-format main.cpp > main.tmp will send the formatted source code to main.tmp.
clang-format main.cpp > main.cpp wil not work because the redirection operator “>” will reset the file to zero bytes if it exists.

To run clang tools in atom I use Process-Palette which will give me an extra option of sending the output to the clipboard.


Hm, that’s odd, echo "some text" > test.txt will always update the file in Atom.

Try the following, it will only overwrite the file once clang-format has terminated:

clang-format main.cpp > main.tmp && mv main.tmp main.cpp


Your suggestion works. but I did have some permissions issues. I solved that by putting the .tmp file in a different directory and that solved the issue.


echo “some text” > main.cpp will work because text is being inserted into he file.
what I am doing is truncating the file to make it empty then trying passing the empty file to clang-format.
clang-format now has an empty file to work with and stops!

But it’s all good.
Thanks much for the help.