How can I configure Spacemacs to always add a newline at the end of files when saving? - spacemacs

I would like text files that I edit in Spacemacs to always end with a newline (\n) when I save them, even if I don't explicitly add it. How can I configure Spacemacs to do this?
I noticed this issue when created a file called .clangd with the contents
CompileFlags:
Add: [-Isrc, -Isrc/effect]
When I wrote this file with :w, it did not have a newline at the end of the file.

(setq require-final-newline t)

Related

Intellij IDEA 14 - remove indents on empty lines

I have an annoying bug regarding intellij 14.0.3. The issue is that it keeps indents on empty lines and I can't remove that whitespace in any way. Under code style, I have not checked the checkbox "keep indents on empty lines" and judging from the display how that functionality works I'd say it would do it.
However, it still keeps the indents and that creates bad diffs in git since whitespace is added. Is this a bug? Can I in any way remove them? I have tried to uncheck that checkbox under both the language I use and the main one. None of them seems to change it.
Try enabling the Strip trailing spaces on save option in Settings/Editor/General.
You can choose whether this should be performed for All lines or only the lines you modify to avoid creating unnecessary diffs.
The whitespace is stripped when you explicitly hit CTRL+S or automatically after some period (IntelliJ has autosaving).
One thing to note is that if you have cursor on an empty line and there are some spaces before it, hitting CTRL + S won't strip the whitespace, because this would probably be annoying as your cursor would jump to the beginning of the line if the file was autosaved by IntelliJ (I read somewhere on YouTrack that this was a design decision).
Here is a screenshot of the option I describe:
What I did to strip spaces without having to open & save each file is running a regex in the find and replace window:
Ctrl+Shift+R
Text to find ^ +\n Find every line that starts with (^) one or more spaces ( +) and nothing else (/n).
Replace with: \n A new line.
General > Regular expression (obviously important to check this box)
Eventually you may want to limit the scope because this will be quite the lengthy operation
Find and eventually continue if IDEA warns for the high amount of occurrences.
Click All Files to run the actual replace operation. It might take some time before IDEA to respond.

Editor config new line at start of file

Editor config has an option to insert blank lines at the end of the file. Is there something similar which allows for blank lines at the start of the file, ignoring shebang lines?

VB.NET Append text to the end of a line in an exiting CSV file

How can I append text to the end a line in a text file with lines already there in VB.NET?
For example my text file looks like this:
header1,header2,header3
value1,value2,value3
stuff1,stuff2,stuff3
and I want to add new text to the end of each line so it looks like this:
header1,header2,header3,newheader
value1,value2,value3,newvalue
stuff1,stuff2,stuff3,newstuff
I know that in Perl you can point to the line and then act on it, is there some VB.net way to do this?
If the file isn't too big, the simplest is, probably, to use the IO.File.ReadAllLines method to read the file into memory and modify the data and write it back with the WriteAllLines method.
For very large files you're probably looking at reading each line modifying it and writing it to a different file.

Not completed file reading

I'm trying to print the number of rows in my file training.txt but found out that my code does not read the whole file. Code goes like this:
row = 1
for line in io.lines 'training.txt' do
row = row + 1
end
print(row)
I tried changing the file with test.txt that has the same format with training.txt and file reading worked fine, reads until the end of file. So maybe the problem is with my text file? But how? It has the same format.
Text files are uploaded here for testing.
The file you uploaded training.txt is not the same format as test.txt, it does not have newline characters that indicate the EOL (End of Line). Try opening it in notepad to see the difference.

How to edit a file in VB?

I have a CPP file. I am using VB in VS2005. I have opened that file using the FileSystemObject. I am reading each and every line in that CPP file. I have to comment all the lines until I encounter a return statement. I am using the scripting.textstream to read a line from the CPP file. But I have no idea as to how we can add a // comment to the beginning of every line that I read or even a multiline comment from the beginning till a return statement. Please help.
You seem to be using the FileSystemObject of the Windows script runtime instead of the System.IO.File class's methods. Strange!
The static System.IO.File.ReadAllLines() will read a file (and close it) and return a string array containing all the lines. You could then iterate through the array and add a comment to each line (except if the line starts with return).
Finally, save the changed text to the file using any of the WriteAllLines() method, thus overwriting any contained text.
Adding a multiline comment at the start would be even easier, you would not need to read the lines into an array.