* [Qemu-devel] [PATCH] Add astyle option file for code formatting
@ 2011-09-11 17:00 Stefan Weil
2011-09-16 13:07 ` Anthony Liguori
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Weil @ 2011-09-11 17:00 UTC (permalink / raw)
To: qemu-devel
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 <weil@mail.berlios.de>
---
scripts/astylerc | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
create mode 100644 scripts/astylerc
diff --git a/scripts/astylerc b/scripts/astylerc
new file mode 100644
index 0000000..dcf9e3f
--- /dev/null
+++ b/scripts/astylerc
@@ -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
--
1.7.2.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] Add astyle option file for code formatting
2011-09-11 17:00 [Qemu-devel] [PATCH] Add astyle option file for code formatting Stefan Weil
@ 2011-09-16 13:07 ` Anthony Liguori
2011-09-16 14:31 ` Stefan Weil
2011-09-19 8:01 ` Markus Armbruster
0 siblings, 2 replies; 5+ messages in thread
From: Anthony Liguori @ 2011-09-16 13:07 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-devel
On 09/11/2011 12:00 PM, Stefan Weil wrote:
> 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<weil@mail.berlios.de>
> ---
> scripts/astylerc | 16 ++++++++++++++++
> 1 files changed, 16 insertions(+), 0 deletions(-)
> create mode 100644 scripts/astylerc
>
> diff --git a/scripts/astylerc b/scripts/astylerc
> new file mode 100644
> index 0000000..dcf9e3f
> --- /dev/null
> +++ b/scripts/astylerc
> @@ -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't
Regards,
Anthony Liguori
> +
> +add-brackets
> +align-pointer=name
> +convert-tabs
> +style=otbs
> +brackets=linux
> +indent=spaces=4
> +pad-oper
> +pad-header
> +unpad-paren
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] Add astyle option file for code formatting
2011-09-16 13:07 ` Anthony Liguori
@ 2011-09-16 14:31 ` Stefan Weil
2011-09-19 8:01 ` Markus Armbruster
1 sibling, 0 replies; 5+ messages in thread
From: Stefan Weil @ 2011-09-16 14:31 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
Am 16.09.2011 15:07, schrieb Anthony Liguori:
> On 09/11/2011 12:00 PM, Stefan Weil wrote:
>> 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<weil@mail.berlios.de>
>> ---
>> scripts/astylerc | 16 ++++++++++++++++
>> 1 files changed, 16 insertions(+), 0 deletions(-)
>> create mode 100644 scripts/astylerc
>>
> 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't
>
> 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_config
scripts/hxtool
scripts/make_device_config.sh
scripts/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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] Add astyle option file for code formatting
2011-09-16 13:07 ` Anthony Liguori
2011-09-16 14:31 ` Stefan Weil
@ 2011-09-19 8:01 ` Markus Armbruster
2011-09-19 8:38 ` Peter Maydell
1 sibling, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2011-09-19 8:01 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
Anthony Liguori <anthony@codemonkey.ws> writes:
[...]
> 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)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] Add astyle option file for code formatting
2011-09-19 8:01 ` Markus Armbruster
@ 2011-09-19 8:38 ` Peter Maydell
0 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2011-09-19 8:38 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel
On 19 September 2011 09:01, Markus Armbruster <armbru@redhat.com> wrote:
> Anthony Liguori <anthony@codemonkey.ws> writes:
>> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-09-19 8:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-11 17:00 [Qemu-devel] [PATCH] Add astyle option file for code formatting Stefan Weil
2011-09-16 13:07 ` Anthony Liguori
2011-09-16 14:31 ` Stefan Weil
2011-09-19 8:01 ` Markus Armbruster
2011-09-19 8:38 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).