From f50b927e8c3bc996780276e39c643e2d534682ac Mon Sep 17 00:00:00 2001 From: Siddarth Date: Sun, 29 Dec 2019 13:07:30 +0800 Subject: [PATCH 1/3] Support for Function Names and Docstrings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added two variables which allow users not to fold function names (à la foldmethod=indent) and also allow the docstrings not to be folded. There are a couple of considerations I should put into the README, which are both new variables need default values, and also if you want to use unfold_docstring, unfold_function name should also be set to enable. --- autoload/SimpylFold.vim | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/autoload/SimpylFold.vim b/autoload/SimpylFold.vim index ec1281d..cc654eb 100644 --- a/autoload/SimpylFold.vim +++ b/autoload/SimpylFold.vim @@ -29,6 +29,14 @@ function! SimpylFold#BufferInit() abort let b:SimpylFold_fold_import = \ !exists('g:SimpylFold_fold_import') || g:SimpylFold_fold_import endif + if !exists('b:SimpylFold_unfold_function_name') + let b:SimpylFold_unfold_function_name= + \ !exists('g:SimpylFold_unfold_function_name') || g:SimpylFold_unfold_function_name + endif + if !exists('b:SimpylFold_unfold_docstring') + let b:SimpylFold_unfold_docstring= + \ !exists('g:SimpylFold_unfold_docstring') || g:SimpylFold_unfold_docstring + endif endfunction " Get spaces per indent setting @@ -200,9 +208,15 @@ function! s:cache() abort else if docstring_start != -1 let foldlevel += 1 - let cache[docstring_start]['foldexpr'] = '>' . foldlevel + if b:SimpylFold_unfold_docstring + let cache[docstring_start]['foldexpr'] = 0 + let docfold = 0 + else + let cache[docstring_start]['foldexpr'] = '>' . foldlevel + let docfold = foldlevel + endif for lnum_docstring in range((docstring_start + 1), lnum) - let cache[lnum_docstring]['foldexpr'] = foldlevel + let cache[lnum_docstring]['foldexpr'] = docfold endfor let docstring_start = -1 endif @@ -257,7 +271,10 @@ function! s:cache() abort let foldlevel = len(defs_stack) - 1 let ind_def = ind call s:blanks_adj(cache, lnum, foldlevel) - let cache[lnum]['foldexpr'] = '>' . (foldlevel + 1) + let cache[lnum+b:SimpylFold_unfold_function_name]['foldexpr'] = '>' . (foldlevel + 1) + if b:SimpylFold_unfold_function_name + let cache[lnum]['foldexpr'] = (foldlevel + 1 - b:SimpylFold_unfold_function_name) + endif continue endif From 2063d58664a676c20ccc14ee8dab41db87a6624f Mon Sep 17 00:00:00 2001 From: Siddarth Raghuvanshi Date: Sun, 29 Dec 2019 13:28:04 +0800 Subject: [PATCH 2/3] Updated README Added the new variables and the issues of the unfold_docstring variable. --- README.md | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7c06e81..fdc13d5 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,27 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: ```vim let g:SimpylFold_docstring_preview = 1 ``` -| Variable | Description | Default | -| -------------------------------- | ------------------------------ | ------- | -| `g:SimpylFold_docstring_preview` | Preview docstring in fold text | `0` | -| `g:SimpylFold_fold_docstring` | Fold docstrings | `1` | -| `b:SimpylFold_fold_docstring` | Fold docstrings (buffer local) | `1` | -| `g:SimpylFold_fold_import` | Fold imports | `1` | -| `b:SimpylFold_fold_import` | Fold imports (buffer local) | `1` | +| Variable | Description | Default | +| ------------------------------------- | ------------------------------ | ------- | +| `g:SimpylFold_docstring_preview` | Preview docstring in fold text | `0` | +| `g:SimpylFold_fold_docstring` | Fold docstrings | `1` | +| `b:SimpylFold_fold_docstring` | Fold docstrings (buffer local) | `1` | +| `g:SimpylFold_fold_import` | Fold imports | `1` | +| `b:SimpylFold_fold_import` | Fold imports (buffer local) | `1` | +| `g:SimpylFold_unfold_function_names` | Fold imports | `0` | +| `b:SimpylFold_unfold_function_names` | Fold imports (buffer local) | `0` | +| `g:SimpylFold_unfold_docstring` | Fold imports | `0` | +| `b:SimpylFold_unfold_docstring` | Fold imports (buffer local) | `0` | + +Using `SimpylFold_unfold_docstring` does have some caveats: + +To work properly, it needs `SimpylFold_fold_docstring` to be set to the +default value `1` to find the docstring starting location. In addition, +`SimpylFold_fold_docstring` overrides the affect of +`SimpylFold_unfold_function_names` by having function names visible +constantly. This is intentional, but `g:SimpylFold_unfold_function_names` +should still be set to 1 in the `.vimrc` file to properly handle double +lined function or class definitions. ### Commands From 81690b74da1bd9e13b3c87811bc2671c4d75bc28 Mon Sep 17 00:00:00 2001 From: Siddarth Raghuvanshi Date: Sun, 29 Dec 2019 13:30:27 +0800 Subject: [PATCH 3/3] Updated Default Values of new variables --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fdc13d5..856b6bd 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,10 @@ let g:SimpylFold_docstring_preview = 1 | `b:SimpylFold_fold_docstring` | Fold docstrings (buffer local) | `1` | | `g:SimpylFold_fold_import` | Fold imports | `1` | | `b:SimpylFold_fold_import` | Fold imports (buffer local) | `1` | -| `g:SimpylFold_unfold_function_names` | Fold imports | `0` | -| `b:SimpylFold_unfold_function_names` | Fold imports (buffer local) | `0` | -| `g:SimpylFold_unfold_docstring` | Fold imports | `0` | -| `b:SimpylFold_unfold_docstring` | Fold imports (buffer local) | `0` | +| `g:SimpylFold_unfold_function_names` | Fold imports | `1` | +| `b:SimpylFold_unfold_function_names` | Fold imports (buffer local) | `1` | +| `g:SimpylFold_unfold_docstring` | Fold imports | `1` | +| `b:SimpylFold_unfold_docstring` | Fold imports (buffer local) | `1` | Using `SimpylFold_unfold_docstring` does have some caveats: