Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to not fold function names and docstrings #114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `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:

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`SimpylFold_fold_docstring` overrides the affect of
`SimpylFold_fold_docstring` overrides the effect of

Typo

`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

Expand Down
23 changes: 20 additions & 3 deletions autoload/SimpylFold.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down