From e5910016a6417d76dfd00c0beba49af148ec8e90 Mon Sep 17 00:00:00 2001 From: philipp schoenberger Date: Thu, 27 Oct 2016 12:34:37 +0200 Subject: [PATCH 1/4] add a parameter for identifying the applied state --- plugin/linuxsty.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/linuxsty.vim b/plugin/linuxsty.vim index b303cb3ae0..6855ccf638 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 From ee3ae942770304eeaf07558fe01b3261b24e0ffa Mon Sep 17 00:00:00 2001 From: philipp schoenberger Date: Wed, 30 Nov 2016 09:12:12 +0100 Subject: [PATCH 2/4] add parameter to check if the style is allied --- plugin/linuxsty.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/linuxsty.vim b/plugin/linuxsty.vim index 6855ccf638..4b71905b26 100644 --- a/plugin/linuxsty.vim +++ b/plugin/linuxsty.vim @@ -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() From 42c39894b2ff500476c1c5b3dc1421194bd49bc9 Mon Sep 17 00:00:00 2001 From: philipp schoenberger Date: Wed, 30 Nov 2016 09:13:21 +0100 Subject: [PATCH 3/4] update readme for b:linuxsty_applied and b:apply_linux_style --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 7e38043971..7935a95636 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,26 @@ 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. From eddccf8b0ecf4d3628864aee94eb6752a30424ef Mon Sep 17 00:00:00 2001 From: philipp schoenberger Date: Wed, 30 Nov 2016 09:15:30 +0100 Subject: [PATCH 4/4] correct code quotation marks and remove tailing whitespaces --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7935a95636..b4b4a3fb86 100644 --- a/README.md +++ b/README.md @@ -8,32 +8,32 @@ 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 @@ -60,5 +60,5 @@ An example how this could be useful is to set the |listchars| depending on the ## 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.