tmhedberg / SimpylFold

No-BS Python code folding for Vim
BSD 3-Clause "New" or "Revised" License
653 stars 57 forks source link

Can't turn off docstring folding #138

Closed mmadrid closed 1 year ago

mmadrid commented 1 year ago

I'm probably missing something simple, but I can't get docstring folding turned off.

I have tested in a completely clean environment with no other plugins or filetype settings. Here's my setup:

Ubuntu 22.04.1 LTS Python 3.11.1
NVIM v0.7.2 Build type: Release LuaJIT 2.1.0-beta3 Compiled by team+vim@tracker.debian.org Features: +acl +iconv +tui

:checkhealth

## Python 3 provider (optional)
  - INFO: Using: g:python3_host_prog = "$HOME/python-environments/vimmer-py311/bin/python3"
  - INFO: Executable: /home/vimmer/python-environments/vimmer-py311/bin/python3
  - INFO: Python version: 3.11.1
  - INFO: pynvim version: 0.4.3
  - OK: Latest pynvim is installed.

## Python virtualenv
  - INFO: $VIRTUAL_ENV is set to: /home/vimmer/python-environments/vimmer-py311
  - INFO: Python version: 3.11.1
  - OK: $VIRTUAL_ENV provides :!python.

set foldexpr? foldexpr=SimpylFold#FoldExpr(v:lnum) set foldmethod? foldmethod=expr

init.vim:

let g:python3_host_prog = "$HOME/python-environments/vimmer-py311/bin/python3"

let g:SimpylFold_fold_docstring=0

call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')

Plug 'tmhedberg/SimpylFold'

call plug#end()

python code:

#!/usr/bin/env python

def testing_oneliner():
    """This is one line docstring!"""
    print("One liner")

def testing_multiliner():
    """This    
    is 
    a 
    multiline
    docstring
    """
    print("Multi liner")

Folded code:

#!/usr/bin/env python

+--  3 lines: def testing_oneliner():·······················································

+--  8 lines: def testing_multiliner():······················································

Note that SimpylFold_docstring_preview does work if I turn that on. I'd really like to use this feature. What am I missing?

Thanks in advance

tmhedberg commented 1 year ago

Try :SimpylFoldDocstring! and then reload the buffer.

This is counterintuitive behavior and the documentation is misleading; changing the configuration variable directly doesn't seem to have the intended effect. This is likely due to how we're caching folds. The command invalidates the cache, but changing the variable does not.

mmadrid commented 1 year ago

Try :SimpylFoldDocstring! and then reload the buffer.

This is counterintuitive behavior and the documentation is misleading; changing the configuration variable directly doesn't seem to have the intended effect. This is likely due to how we're caching folds. The command invalidates the cache, but changing the variable does not.

Thanks for the reply. This doesn't do anything.

tmhedberg commented 1 year ago

If that's the case, then I don't know what to tell you. It works for me when I run the command and reload.

Adding let g:SimpylFold_fold_docstring = 0 to my .vimrc also works. However, changing the config variable after Vim has already loaded a Python buffer has no effect.

mmadrid commented 1 year ago

This is actually a misunderstanding on my part. It works as intended. What I thought g:SimpylFold_fold_docstring = 0 would do is not fold the docstring (and thus not the function def either), but fold the rest of the function contents so that I would always be able to see the docstring (something like below). I realize now that that is not the intended functionality, and that I'm not sure I want that anyway. It was a good exersize in learning about folding in Vim!

def a_function():
    """This is a multiline docstring
    It prints out three lines of stuff
    """
+--  3 lines: print("Some stuff")··························
eric-saintetienne commented 1 year ago

I thought exactly the same thing, that the docstring would be visible but the code would be folded, because what I was looking forward is to get an overview of the code and see whether functions should be renamed.

The documentation/README needs to be updated to make this clear IMO. Like you I lost quite some time figuring why my docstrings would stay folded.