[libvirt] [PATCH] Add vim configuration that makes vim auto-indent code

--- .lvimrc | 10 ++++++++++ HACKING | 5 +++++ 2 files changed, 15 insertions(+), 0 deletions(-) create mode 100644 .lvimrc diff --git a/.lvimrc b/.lvimrc new file mode 100644 index 0000000..3a732ce --- /dev/null +++ b/.lvimrc @@ -0,0 +1,10 @@ +set nocompatible +filetype on +set autoindent +set smartindent +set cindent +set tabstop=4 +set shiftwidth=4 +set expandtab +set cinoptions=(0,:0,l1,t0 +filetype plugin indent on diff --git a/HACKING b/HACKING index 4a71b37..adfb7ae 100644 --- a/HACKING +++ b/HACKING @@ -87,6 +87,11 @@ If you use Emacs, add the following to one of one of your start-up files '(lambda () (if (string-match "/libvirt" (buffer-file-name)) (libvirt-c-mode)))) +If you use vim, install vim script at this page: +http://www.vim.org/scripts/script.php?script_id=1408 +it will auto load .lvimrc at the root of libvirt source only when you're +editing libvirt's code. Or you can append the contents of .lvimrc to you +.vimrc file. Code formatting (especially for new code) ========================================= -- 1.7.3.1

On Wed, Mar 16, 2011 at 10:53:27AM +0800, Hu Tao wrote:
--- .lvimrc | 10 ++++++++++ HACKING | 5 +++++ 2 files changed, 15 insertions(+), 0 deletions(-) create mode 100644 .lvimrc
diff --git a/.lvimrc b/.lvimrc new file mode 100644 index 0000000..3a732ce --- /dev/null +++ b/.lvimrc @@ -0,0 +1,10 @@ +set nocompatible +filetype on +set autoindent +set smartindent +set cindent +set tabstop=4 +set shiftwidth=4 +set expandtab +set cinoptions=(0,:0,l1,t0 +filetype plugin indent on diff --git a/HACKING b/HACKING index 4a71b37..adfb7ae 100644
Heh, I use vim, but I would rather not put a configuration file in the tree, especially with autoindent which may defeat people typing habits. BTW I use the following: set autoindent set autowrite set keywordprg= set shiftwidth=4 set softtabstop=4 set expandtab set tabstop=8 au FileType make setlocal noexpandtab set showmode syntax on set backspace=2 set clipboard="" set nohls let c_space_errors=1 highlight RedundantSpaces ctermbg=red guibg=red match RedundantSpaces /\s\+$\| \+\ze\t/ BTW the last lines shows up in red any trailing spaces left at the end of lines, tip given by Jim Meyering a couple of years ago Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Wed, Mar 16, 2011 at 03:54:26PM +0800, Daniel Veillard wrote:
On Wed, Mar 16, 2011 at 10:53:27AM +0800, Hu Tao wrote:
--- .lvimrc | 10 ++++++++++ HACKING | 5 +++++ 2 files changed, 15 insertions(+), 0 deletions(-) create mode 100644 .lvimrc
diff --git a/.lvimrc b/.lvimrc new file mode 100644 index 0000000..3a732ce --- /dev/null +++ b/.lvimrc @@ -0,0 +1,10 @@ +set nocompatible +filetype on +set autoindent +set smartindent +set cindent +set tabstop=4 +set shiftwidth=4 +set expandtab +set cinoptions=(0,:0,l1,t0 +filetype plugin indent on diff --git a/HACKING b/HACKING index 4a71b37..adfb7ae 100644
Heh, I use vim, but I would rather not put a configuration file in the tree, especially with autoindent which may defeat people typing habits.
Agree. But do you think the script (see changes of HACKING file of this patch) is useful? with it the .lvimrc(not .vimrc) takes effect only if editing libvirt code, and there is no need to append it to ~/.vimrc.
BTW I use the following:
set autoindent set autowrite set keywordprg= set shiftwidth=4 set softtabstop=4 set expandtab set tabstop=8 au FileType make setlocal noexpandtab set showmode syntax on set backspace=2 set clipboard="" set nohls let c_space_errors=1 highlight RedundantSpaces ctermbg=red guibg=red match RedundantSpaces /\s\+$\| \+\ze\t/
BTW the last lines shows up in red any trailing spaces left at the end of lines, tip given by Jim Meyering a couple of years ago
Thank you, it helps catching trailing spaces early in vim. (although git diff can do it) -- Thanks, Hu Tao

On Wed, Mar 16, 2011 at 04:59:11PM +0800, Hu Tao wrote:
On Wed, Mar 16, 2011 at 03:54:26PM +0800, Daniel Veillard wrote:
On Wed, Mar 16, 2011 at 10:53:27AM +0800, Hu Tao wrote:
--- .lvimrc | 10 ++++++++++ HACKING | 5 +++++ 2 files changed, 15 insertions(+), 0 deletions(-) create mode 100644 .lvimrc
diff --git a/.lvimrc b/.lvimrc new file mode 100644 index 0000000..3a732ce --- /dev/null +++ b/.lvimrc @@ -0,0 +1,10 @@ +set nocompatible +filetype on +set autoindent +set smartindent +set cindent +set tabstop=4 +set shiftwidth=4 +set expandtab +set cinoptions=(0,:0,l1,t0 +filetype plugin indent on diff --git a/HACKING b/HACKING index 4a71b37..adfb7ae 100644
Heh, I use vim, but I would rather not put a configuration file in the tree, especially with autoindent which may defeat people typing habits.
Agree. But do you think the script (see changes of HACKING file of this patch) is useful? with it the .lvimrc(not .vimrc) takes effect only if editing libvirt code, and there is no need to append it to ~/.vimrc.
I tend to think it's a bit too specific. I would be fine with just adding instruction and the example file in HACKING however :-)
let c_space_errors=1 highlight RedundantSpaces ctermbg=red guibg=red match RedundantSpaces /\s\+$\| \+\ze\t/
BTW the last lines shows up in red any trailing spaces left at the end of lines, tip given by Jim Meyering a couple of years ago
Thank you, it helps catching trailing spaces early in vim. (although git diff can do it)
Yeah but it's nicer to catch them at creation time, though he extra red blocks on the editors need some time to get used too, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

--- What about this one? HACKING | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/HACKING b/HACKING index 4a71b37..b86243a 100644 --- a/HACKING +++ b/HACKING @@ -87,6 +87,22 @@ If you use Emacs, add the following to one of one of your start-up files '(lambda () (if (string-match "/libvirt" (buffer-file-name)) (libvirt-c-mode)))) +If you use vim, append the following to your ~/.vimrc file: + + set nocompatible + filetype on + set autoindent + set smartindent + set cindent + set tabstop=8 + set shiftwidth=4 + set expandtab + set cinoptions=(0,:0,l1,t0 + filetype plugin indent on + au FileType make setlocal noexpandtab + au BufRead,BufNewFile *.am setlocal noexpandtab + match ErrorMsg /\s\+$\| \+\ze\t/ + Code formatting (especially for new code) ========================================= -- 1.7.3.1 -- Thanks, Hu Tao

On 03/16/2011 04:01 AM, Hu Tao wrote:
---
What about this one?
HACKING | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
HACKING is generated. Edit docs/hacking.html.in instead.
+If you use vim, append the following to your ~/.vimrc file: + + set nocompatible + filetype on + set autoindent + set smartindent + set cindent + set tabstop=8 + set shiftwidth=4 + set expandtab + set cinoptions=(0,:0,l1,t0 + filetype plugin indent on + au FileType make setlocal noexpandtab + au BufRead,BufNewFile *.am setlocal noexpandtab + match ErrorMsg /\s\+$\| \+\ze\t/
You may also want to mention how to install .lvimrc files and use the script from http://www.vim.org/scripts/script.php?script_id=1408 (it is possible to 'echo .lvimrc >> .git/info/exclude' to avoid accidentally commiting it), even if we don't push .lvimrc into the repository. Is there any way to make configuration of tabstop/expandtab conditional based on whether the file is a Makefile or something else, so that you can continue to use proper TABs where they are required? -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Wed, Mar 16, 2011 at 09:11:25AM -0600, Eric Blake wrote:
On 03/16/2011 04:01 AM, Hu Tao wrote:
---
What about this one?
HACKING | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
HACKING is generated. Edit docs/hacking.html.in instead.
Thanks for reminding me.
+If you use vim, append the following to your ~/.vimrc file: + + set nocompatible + filetype on + set autoindent + set smartindent + set cindent + set tabstop=8 + set shiftwidth=4 + set expandtab + set cinoptions=(0,:0,l1,t0 + filetype plugin indent on + au FileType make setlocal noexpandtab + au BufRead,BufNewFile *.am setlocal noexpandtab + match ErrorMsg /\s\+$\| \+\ze\t/
You may also want to mention how to install .lvimrc files and use the script from http://www.vim.org/scripts/script.php?script_id=1408 (it is possible to 'echo .lvimrc >> .git/info/exclude' to avoid accidentally commiting it), even if we don't push .lvimrc into the repository.
OK, will update.
Is there any way to make configuration of tabstop/expandtab conditional based on whether the file is a Makefile or something else, so that you can continue to use proper TABs where they are required?
The two ^au lines do this. -- Thanks, Hu Tao

--- .gitignore | 1 + docs/hacking.html.in | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index 41f7654..197b4df 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ results.log stamp-h stamp-h.in stamp-h1 +.lvimrc diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 0d81b0b..6093fc6 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -101,6 +101,31 @@ (libvirt-c-mode)))) </pre> + <p> + If you use vim, append the following to your ~/.vimrc file: + </p> +<pre> + set nocompatible + filetype on + set autoindent + set smartindent + set cindent + set tabstop=8 + set shiftwidth=4 + set expandtab + set cinoptions=(0,:0,l1,t0 + filetype plugin indent on + au FileType make setlocal noexpandtab + au BufRead,BufNewFile *.am setlocal noexpandtab + match ErrorMsg /\s\+$\| \+\ze\t/ +</pre> + <p> + Or if you don't want to mess your ~/.vimrc up, you can save the above + into a file called .lvimrc(not .vimrc) located at the root of libvirt + source, then install a vim script from http://www.vim.org/scripts/script.php?script_id=1408, + It will load the .lvimrc only when you edit libvirt code. + </p> + <h2><a name="formatting">Code formatting (especially for new code)</a></h2> <p> -- 1.7.3.1

On 03/16/2011 08:35 PM, Hu Tao wrote:
--- .gitignore | 1 + docs/hacking.html.in | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore index 41f7654..197b4df 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ results.log stamp-h stamp-h.in stamp-h1 +.lvimrc
Sure, making it globally ignored works for me. But rerunning ./autogen.sh sorts on your behalf (next to .git-module-status), so I had to modify the commit..
diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 0d81b0b..6093fc6 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in
HACKING is generated; rerunning 'make' picked up those changes for me (if it didn't for you, then you are missing some prerequisite for converting xml to plain text; it's not fatal to the build, but does matter for things like this patch).
@@ -101,6 +101,31 @@ (libvirt-c-mode)))) </pre>
+ <p> + If you use vim, append the following to your ~/.vimrc file: + </p>
+ <p> + Or if you don't want to mess your ~/.vimrc up, you can save the above + into a file called .lvimrc(not .vimrc) located at the root of libvirt
s/.lvimrc(not/.lvimrc (not)/
+ source, then install a vim script from http://www.vim.org/scripts/script.php?script_id=1408, + It
", It" should have been ". It" or ", which"; I went with the latter. Can't say whether the content is accurate, but I'm assuming so. Therefore, ACK, and modified patch pushed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

At 03/16/2011 04:59 PM, Hu Tao Write:
On Wed, Mar 16, 2011 at 03:54:26PM +0800, Daniel Veillard wrote:
On Wed, Mar 16, 2011 at 10:53:27AM +0800, Hu Tao wrote:
--- .lvimrc | 10 ++++++++++ HACKING | 5 +++++ 2 files changed, 15 insertions(+), 0 deletions(-) create mode 100644 .lvimrc
diff --git a/.lvimrc b/.lvimrc new file mode 100644 index 0000000..3a732ce --- /dev/null +++ b/.lvimrc @@ -0,0 +1,10 @@ +set nocompatible +filetype on +set autoindent +set smartindent +set cindent +set tabstop=4 +set shiftwidth=4 +set expandtab +set cinoptions=(0,:0,l1,t0 +filetype plugin indent on diff --git a/HACKING b/HACKING index 4a71b37..adfb7ae 100644
Heh, I use vim, but I would rather not put a configuration file in the tree, especially with autoindent which may defeat people typing habits.
Agree. But do you think the script (see changes of HACKING file of this patch) is useful? with it the .lvimrc(not .vimrc) takes effect only if editing libvirt code, and there is no need to append it to ~/.vimrc.
We use tab in Makefile.am, so 'set expandtab' and 'set tabstop=4' are bad settings when modifing Makefile.am.
BTW I use the following:
set autoindent set autowrite set keywordprg= set shiftwidth=4 set softtabstop=4 set expandtab set tabstop=8 au FileType make setlocal noexpandtab set showmode syntax on set backspace=2 set clipboard="" set nohls let c_space_errors=1 highlight RedundantSpaces ctermbg=red guibg=red match RedundantSpaces /\s\+$\| \+\ze\t/
BTW the last lines shows up in red any trailing spaces left at the end of lines, tip given by Jim Meyering a couple of years ago
Thank you, it helps catching trailing spaces early in vim. (although git diff can do it)
participants (4)
-
Daniel Veillard
-
Eric Blake
-
Hu Tao
-
Wen Congyang