Add astyle option file for code formatting
PATCH 1/1 Add astyle option file for code formatting
For new C code (and maybe also for existing code), a code formatter like Artistic Style is helpful because it can fix tabs, indentation and other style issues.
This option file tries to set astyle options which match QEMU's coding conventions.
The quality of astyle's code formatting depends on the astyle version (I got best results with newer versions) and on the code which is going to be formatted.
For some code, formatting of brackets and operators does not work well. Fixing indentation and tabs always worked well for me.
--- scripts/astylerc | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) create mode 100644 scripts/astylerc
scripts/astylerc new file +16 -0
@@ -0,0 +1,16 @@ +# Artistic Style (astyle) options for qemu source code. + +# Usage: +# astyle --options=scripts/astylerc {source files} + +# For best results, use latest astyle from http://astyle.sourceforge.net/. + +add-brackets +align-pointer=name +convert-tabs +style=otbs +brackets=linux +indent=spaces=4 +pad-oper +pad-header +unpad-paren
Signature · 1 line
1.7.2.5
Quoted 26 lines · Stefan Weil
For new C code (and maybe also for existing code), a code formatter like Artistic Style is helpful because it can fix tabs, indentation and other style issues.
This option file tries to set astyle options which match QEMU's coding conventions.
The quality of astyle's code formatting depends on the astyle version (I got best results with newer versions) and on the code which is going to be formatted.
For some code, formatting of brackets and operators does not work well. Fixing indentation and tabs always worked well for me.
Signed-off-by Stefan Weil<[email protected]>--- scripts/astylerc | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)create mode 100644
scripts/astylercscripts/astylerc new file +0
-0
scripts/astylerc line 6
Quoted 6 lines
scripts/astylerc new file +6
-0@@ -0,0 +1,16 @@ +# Artistic Style (astyle) options for qemu source code. + +# Usage: +# astyle --options=scripts/astylerc {source files} + +# For best results, use latest astyle from http://astyle.sourceforge.net/.
Please put a copyright in this file.
FWIW, this is what I use with emacs:
(c-add-style "qemu"
'("stroustrup"
(indent-tabs-mode . nil)
(c-basic-offset . 4)
(tab-width . 8)
)
nil) ; t = set this style, nil = don'tRegards,
Anthony Liguori
Quoted 10 lines
scripts/astylerc new file +10
-0+ +add-brackets +align-pointer=name +convert-tabs +style=otbs +brackets=linux +indent=spaces=4 +pad-oper +pad-header +unpad-paren
Am 16.09.2011 15:07, schrieb Anthony Liguori:
Quoted 33 lines · Stefan Weil
Quoted 11 lines
For new C code (and maybe also for existing code), a code formatter like Artistic Style is helpful because it can fix tabs, indentation and other style issues.
This option file tries to set astyle options which match QEMU's coding conventions.
The quality of astyle's code formatting depends on the astyle version (I got best results with newer versions) and on the code which is going to be formatted.
Quoted 9 lines
For some code, formatting of brackets and operators does not work well. Fixing indentation and tabs always worked well for me.
Signed-off-by Stefan Weil<[email protected]>--- scripts/astylerc | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)create mode 100644
scripts/astylercPlease put a copyright in this file.
FWIW, this is what I use with emacs:
(c-add-style "qemu"
'("stroustrup" (indent-tabs-mode . nil) (c-basic-offset . 4) (tab-width . 8) ) nil) ; t = set this style, nil = don't
Quoted 3 lines
Regards,
Anthony Liguori
Are you sure that you want a copyright even for simple configuration files like this one? I don't think this file could be copyrighted in my country because it is too simple.
There are more complex files in scripts without any copyright:
scripts/create_configscripts/hxtoolscripts/make_device_config.shscripts/qemu-binfmt-conf.sh
If it is common understanding that every file should have a copyright, this rule should be added to CODING_STYLE.
I don't mind adding a line "# public domain", nor do I mind if it is committed as it is.
Regards,
Stefan Weil
PS. It might help some people if you would commit your emacs style, too.
Anthony Liguori <[email protected]> writes:
[...]
Quoted 9 lines
FWIW, this is what I use with emacs:
(c-add-style "qemu"
'("stroustrup" (indent-tabs-mode . nil) (c-basic-offset . 4) (tab-width . 8) ) nil) ; t = set this style, nil = don't
Here's my configuration (excuse liberal use of sledgehammer):
(setq c-initialization-hook
(lambda() (setcar (member '(other . "gnu") c-default-style) (cons 'other "stroustrup"))))
(set-default 'c-recognize-knr-p nil)
(setq c-electric-pound-behavior '(alignleft))
(defun linux-c-mode ()
"C mode with adjusted defaults for use with the Linux kernel." (interactive)
(c-mode)
(c-set-style "K&R")
(setq tab-width 8)
(setq indent-tabs-mode t)
(setq c-basic-offset 8))
(setq auto-mode-alist
(cons '("/linux.*\\.[ch]\\'" . linux-c-mode)
auto-mode-alist));; avoid tabs for some projects
(defun my-choose-tabs ()
(let ((fname (buffer-file-name)))
(and fname (string-match "/qemu" fname)
(setq indent-tabs-mode nil))))
(add-hook 'after-change-major-mode-hook 'my-choose-tabs)
Quoted 4 lines · Markus Armbruster
Quoted 1 line · Anthony Liguori
FWIW, this is what I use with emacs:
Here's my configuration (excuse liberal use of sledgehammer):
Anybody seeking yet a third emacs configuration can try
https://wiki.linaro.org/PeterMaydell/QemuEmacsStyle
:-)
-- PMM