diff --git a/README.md b/README.md index 7e38043971..b4b4a3fb86 100644 --- a/README.md +++ b/README.md @@ -8,37 +8,57 @@ It will automatically apply known rules to kernel related files, such as .c, error highlighting (like exceeding 80 chars). If you have any comments, fixes or requests, feel free to contact me or send me -a patch. The development also takes place on its official [Github +a patch. The development also takes place on its official [Github repository](https://github.com/vivien/vim-linux-coding-style). -The plugin is also available at [vim.org](www.vim.org), script ID +The plugin is also available at [vim.org](www.vim.org), script ID [4369](http://www.vim.org/scripts/script.php?script_id=4369). - + ## Installation -You can just drop the linuxsty.vim file in your ~/.vim/plugin directory. -Alternatively you can use the Git repository with a manager such as +You can just drop the linuxsty.vim file in your ~/.vim/plugin directory. +Alternatively you can use the Git repository with a manager such as [Pathogen](https://github.com/tpope/vim-pathogen). ## Usage -By default the Linux coding style is enabled for any file known to the Linux +By default the Linux coding style is enabled for any file known to the Linux project (C files, headers, patches, Kconfig, etc.). -If you prefer a finer control and apply it only on some files, define -a "g:linuxsty_patterns" array in your vimrc and the style will be applied only -if the buffer's path matches one of the pattern. For instance, you can match +If you prefer a finer control and apply it only on some files, define +a `g:linuxsty_patterns` array in your vimrc and the style will be applied only +if the buffer's path matches one of the pattern. For instance, you can match only projects under /usr/src/ and /linux with the following: let g:linuxsty_patterns = [ "/usr/src/", "/linux" ] -If you want to enable the coding style on demand without checking the filetype, -you can use the :LinuxCodingStyle command. For instance, you can map it with +If you want to enable the coding style on demand without checking the filetype, +you can use the `:LinuxCodingStyle` command. For instance, you can map it with the following in your vimrc: nnoremap a :LinuxCodingStyle +In oder to detect, if the coding style is applied or not there exists two +parameters per buffer. The `b:apply_linux_style` is set to 1 if the +style should be applied (e.g. the `g:linuxsty_patterns` matches). + +The `b:linuxsty_applied` is on the other hand set to 1 if the `:LinuxCodingStyle` +is called and finished for the current buffer. This includes also calls by other +plugins or even manual calls. +An example how this could be useful is to set the |listchars| depending on the +`b:linuxsty_applied` state. + + function! LoadCustomStyle() + if (exists("b:linuxsty_applied")) && b:linuxsty_applied == 1 + set listchars=tab:\ \ ,nbsp:_,trail:. + else + set listchars=tab:>~,nbsp:_,trail:. + endif + endfun + autocmd BufEnter * :call LoadCustomStyle() + + ## License -Copyright (c) Vivien Didelot. Distributed under the same terms as Vim itself. +Copyright (c) Vivien Didelot. Distributed under the same terms as Vim itself. See :help license. diff --git a/plugin/linuxsty.vim b/plugin/linuxsty.vim index b303cb3ae0..4b71905b26 100644 --- a/plugin/linuxsty.vim +++ b/plugin/linuxsty.vim @@ -28,21 +28,21 @@ augroup linuxsty augroup END function s:LinuxConfigure() - let apply_style = 0 + let b:apply_linux_style = 0 if exists("g:linuxsty_patterns") let path = expand('%:p') for p in g:linuxsty_patterns if path =~ p - let apply_style = 1 + let b:apply_linux_style = 1 break endif endfor else - let apply_style = 1 + let b:apply_linux_style = 1 endif - if apply_style + if b:apply_linux_style call s:LinuxCodingStyle() endif endfunction @@ -53,6 +53,7 @@ function! s:LinuxCodingStyle() call s:LinuxFormatting() call s:LinuxKeywords() call s:LinuxHighlighting() + let b:linuxsty_applied = 1 endfunction function s:LinuxFormatting()