Page 2 of 3
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 8:59 am
by rdos
Kevin wrote:So what are the configuration changes that both of you made?
I just checked my config and there isn't much special stuff in it. The only big thing is cscope integration (which I consider essential), and then there are smaller useful things like highlighting trailing whitespace or anything > 80 characters in a source file, enabling FPC extensions for Pascal syntax highlighting etc. I tried things like omnicppcomplete because everyone keeps saying that you absolutely need some context-sensitive autocompletion, but to be honest I found it to be more annoying than helpful. So I'm back to Ctrl-P for now.
When we are on the subject, does anybody know a decent "indention-fixer" that does NOT change the code in any way (like removing / adding { or }), but fixes the code so indention is alwayws a multiple of 4 spaces, and that replaces TABs with spaces? Some of my sorce-files have become a mixture of 4 and 8 space indentions (some of my tools incorrectly replace TAB with 8 spaces). I used some Linux-based tool years ago, but it broke my code as it tried to add / remove {} as well, which was no hit.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 9:26 am
by Solar
VIM.
Code: Select all
:set listchars=tab:>-,trail:ยท
:set list
Makes shift vs. tab visible. (Trailing spaces, too...)
Sets the relevant values (how big an indent should be / how far a tab should indent).
Code: Select all
:set expandtabs
:filetype plugin indent on
Tells VIM that indents should be spaces, not tabs, and activates the indent plugin.
Runs the indent plugin over the current source file.
If you have everything but the :retab in your ~/.vimrc, all you have to do is to call :retab to turn tabs into spaces for the given source file.
(Or vice versa, I know we have some TAB users out there.)
Combined with a macro, re-tabbing several thousand source files is a matter of a dozen keystrokes and 1-2 minutes waiting time. I did just that recently.
To get rid of trailing spaces:
qq/\s\+$
d$@qq@q
(qq - start recording macro for key 'q'. /\s\+$ - search for 1..n trailing spaces. d$ - delete until EOL. @q - call self. q - end recording. @q - execute macro for key 'q' (until EOF).)
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 10:16 am
by Kevin
You can also use = in visual mode to reindent only a specific part.
Solar wrote:To get rid of trailing spaces:
qq/\s\+$
d$@qq@q
Oh, that's a nice demonstration of macros, maybe I should take a closer look some time.
But I would really use
:%s/ \+$//g for this one.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 10:25 am
by Solar
Kevin wrote:Oh, that's a nice demonstration of macros, maybe I should take a closer look some time.
But I would really use
:%s/ \+$//g for this one.
Sadly any trivial demonstration of macros (and quite some non-trivial ones) can also be done with a search-and-replace.
One advantage of the macro is that it remains bound to the 'q' key until replaced with a different macro (including being saved on exit). Yes, VIM also keeps a command history, but that's limited in size, and doesn't come with the mnemonic of the key.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 10:31 am
by rdos
The thing is the source sometimes contains 4 spaces for a single indention, and sometimes 8 spaces, so trivial replace will not do it. The tool needs to understand C-syntax, but should not fiddle with { and }.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 10:36 am
by Kevin
= does do this.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 10:39 am
by Rusky
Not quite. If you have both 4 and 8 space indents, retab/= will see that as two different indent levels.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 10:41 am
by fronty
With emacs: 1. set up indentation for c-mode (google) 2. C-< C-space C-> M-x indent
I'm not so familiar with or interested in some vi-clone as a more IDE or anything, I use emacs when I need more power, and nvi when doing simpler things.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 10:49 am
by Kevin
Rusky wrote:Not quite. If you have both 4 and 8 space indents, retab/= will see that as two different indent levels.
= doesn't care about the original indentation, it reformats everything (and I seem to remember that it doesn't always understand everything correctly, which is why I'm usually very careful with it).
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 11:02 am
by Rusky
I just ran = on this:
It simply replaced each " " with a tab. My ~/.vimrc looks like this (partial):
Code: Select all
set tabstop=4 shiftwidth=4
filetype plugin indent on
More generally, one interesting setup would be to use
eclim to integrate vim with Eclipse. That way you get an IDE with the text-editing capabilities of vim.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 11:12 am
by Kevin
But your test "code" isn't valid C code. vim probably interprets it as one line-wrapped statement. Put a semicolon at the end of each line and it will indent them to the same level.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 11:39 am
by Rusky
Good point. That does work. However, :retab is apparently not equivalent to =, at least when converting to tabs.
Re: Best IDE for OSDev / Cross Compiling
Posted: Thu Jan 05, 2012 12:03 pm
by Kevin
Yes, retab is different, I think it only converts n spaces to a tab (or vice versa).
Re: Best IDE for OSDev / Cross Compiling
Posted: Fri Jan 06, 2012 11:49 am
by rdos
Kevin wrote:= does do this.
I downloaded & installed VIM for Windows, made the changes to the _vimrc file as below:
Code: Select all
:set shiftwidth=4
:set tabstop=4
:filetype plugin indent on
Then I took one of my messed-up source files, but it only works on one or a few lines at a time. It doesn't take the whole source file and reindent it!
Re: Best IDE for OSDev / Cross Compiling
Posted: Fri Jan 06, 2012 1:26 pm
by Kevin
I was talking about visual mode where you select a block that you want to have reindented (it can be started with v or Shift-v). In normal mode you need to specify the range on which = should work, for example G for "until the end of the file". Do this on the first line and the whole file is reindented, so everything combined gives you a gg=G in normal mode.