[parted-devel] Wrong formatting in libaparted/tests/

Håkon Løvdal hlovdal at gmail.com
Thu May 24 04:14:43 UTC 2007


On 16/05/07, Otavio Salvador <otavio at debian.org> wrote:
> I'd like to propose a different idea here. While I agree that tabs
> could be better sometimes, I also think that the editor setup can be
> difficult.

Maybe I am bit naive to ask the following, but how is this
difficult? I have done some research to find how to do this
for what I expect to be a collection the most common text
editors or development environments.

The following is a list of how to configure each of the editors
to use tabs and display them with a width of 4 spaces. Obviously
if you like some other tab expansion width just replace 4 with
whatever you prefer.

anjuta (both "GtkSourceview editor" and "Scintilla Editor")
	Settings -> Preferences -> Editor -> Indentation -> Tab size in spaces -> 4
	Settings -> Preferences -> Editor -> Indentation -> Indentation size
in spaces -> 4
	Settings -> Preferences -> Editor -> Indentation, check "Use tabs for
indentation"

eclipse
	Window -> Preferences -> General -> Editors -> Text Editor ->
Displayed tab width -> 4
	Window -> Preferences -> C/C++ -> Editor, uncheck "insert space for tabs"

emacs, xemacs
	in $HOME/.emacs
	(defun tab-c-mode-common-hook ()
		(setq tab-width 4)
		(setq indent-tabs-mode t)     ; indent with tab and not space
		(define-key c-mode-map "\C-m" 'newline-and-indent)    ; indent on newline
		)
	;; Customizations for c-mode
	(add-hook 'c-mode-hook 'tab-c-mode-common-hook)

gedit
	Edit -> Preferences -> Editor -> Tab width -> 4
	Edit -> Preferences -> Editor, uncheck "insert spaces instead of tabs"

jed
	in $HOME/.jedrc
	TAB_DEFAULT = 4;
	public define global_mode_hook (hook_name)
	{
		local_setkey ("self_insert_cmd", "\t");
	}
	setkey ("self_insert_cmd", "\t");

joe
	in $HOME/.joerc (or similar included file) under the *.c section
	-usetabs
	-tab 4
	-indentc 9

kate
	Settings -> Configure Kate -> Editor -> Editing -> Tab width -> 4
	Settings -> Configure Kate -> Editor, uncheck "insert spaces instead
of tabulators"
	Settings -> Configure Kate -> Indentation, uncheck "use spaces
instead of tabs to indent"

kdevelop
	Settings -> Configure KDevelop -> Formating -> Indentation -> Use tabs

kedit
	No support

kwrite
	Settings -> Configure Editor -> Editing -> Tab width -> 4
	Settings -> Configure Editor -> Editing, uncheck "insert spaces
instead of tabulators"
	Settings -> Configure Editor -> Indentation, uncheck "use spaces
instead of tabs to indent"

less (not an editor, but sometimes used for reading source code)
	command line argument "-x4" (can also be issued run-time)

nano
	in $HOME/.nanorc
	set tabsize 4
	unset tabstospaces

nedit
	Preferences -> Tab Stops -> Tab spacing -> 4
	Preferences -> Tab Stops, uncheck "Emulate tabs"

pico
	I did not find any information about if variable
	tab width is supported, so I assume it is not.

vi - elvis
	in $HOME/.exrc
	:set ts=4 sw=4 noexpandtab

vi - nvi
	in $HOME/.exrc
	:set ts=4

vi - vile
	:set tabinsert ts=4 sw=4

vi - vim
	in $HOME/.vimrc
	:set noexpandtab shiftwidth=4 tabstop=4 softtabstop=4


Maybe I have missed an editor or two, but with the exception
of pico (where nano is an compatible alternative) and kedit
(a lightweight editor in the notepad class) all editors support
displaying tab with a user configurable setting.


Please educate me. Why do you consider space to be better
than tab?

(Are there other criteria/benefit differences I have forgotten
to consider here?)

* Uses less/more disk space?

This is a non-issue.

* Is it easier to write?

This cannot be the case since I assume nobody that argues
for space indentation actually presses the space key to do
the indentation but instead presses the tab key and lets the
editor convert that into spaces, and thus the work would be
identical in both cases. And in any case, how much work it is
to write the code should be a non-issue as I have argued before.

* Is it easier to read?

This is the only important factor. And I fail to see how
space is better than tab for this. Best case scenario on both
cases are not particularly interesting (i.e. your indentation
view preference is X spaces and the source is either indented
with X spaces or indented with tab and your editor is
configured to show tab as X spaces).

In the worst case scenario however a mismatch between the
actual code and your preference leaves space indentation as
an unfixable problem! For tab indentation the fix is just
to configure the editor.


> I then would like to propose the writting of an indent
> script to "properly format the code" and then we start to improve it
> until we find a good code style and we can use it to avoid formating
> mistakes.

Part of me is a bit sceptically to if a tool will be able to
reformat the code without ruining parts of the code that someone
has put some manual layout effort into making extra readable,
like for instance the alignment in ped_unit_get_size. But on
the other hand consistency is probably good, maybe it will work.


> Hakon, can you propose a initial script? I'd suggest you take a look
> how I've done[1] it for bindings.git as a starter point. I'd like to
> replace astyle with indent there to before commiting it.

As long as indentation is done with tabulators I have no other
outstanding issue with the code formatting and I think you are
better than me for this.


BR Håkon Løvdal


More information about the parted-devel mailing list