masukomi / vim-markdown-folding

Fold markdown documents by section.
248 stars 43 forks source link

Folded heading text not showing in latest vim 8.2 version #42

Closed mikeboiko closed 1 month ago

mikeboiko commented 4 years ago

I created a simple markdown file to show the differences between vim versions. test.md:

# Section 1

a

# Section 2

b

Old vim - version

:version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jun 21 2020 16:11:23)
Included patches: 1-814
Compiled by Arch Linux

Old vim - folded buffer shows heading text properly

  1 #     Section 1                               [3 lines]---------------------------------------------------------
5   #     Section 2                               [2 lines]---------------------------------------------------------

New vim - version

:version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Aug 24 2020 19:37:58)
Included patches: 1-1522
Compiled by Arch Linux

New vim - folded buffer doesn't show heading text

  1 +--  4 lines folded --------------------------------------------------------------------------------------------
5   +--  3 lines folded --------------------------------------------------------------------------------------------

Hopefully this is an easy fix. Thanks!

arcdale commented 3 years ago

I have the same problem, since updating to MacVim 8.2

8.2 (2019 Dec 12, compiled Aug 19 2020 06:53:53) macOS version Included patches: 1-1456
Compiled by Homebrew

arcdale commented 3 years ago

In 8.2 there seem to be some changes that affect folding.vim

Although I am a developer, I am not a vim developer, but this is what I could figure out to get a workaround that seems to function in 8.2.

The following line no longer sets foldtext

let &l:foldtext = s:SID() . 'FoldText()'

I think this is why we don't see the headings for the folds.

As a workaround, to set foldtext I first cloned FoldText() to the following since I need access to it at a wider scope than the original definition:-

" Workaround for vim 8.2
function FoldTextWorkaround()
    let level = HeadingDepth(v:foldstart)
    let indent = repeat('#', level)
    let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')
    let foldsize = (v:foldend - v:foldstart)
    let linecount = '['.foldsize.' line'.(foldsize>1?'s':'').']'
    return indent.' '.title.' '.linecount
endfunction

And then changed

if g:markdown_fold_override_foldtext
  let &l:foldtext = s:SID() . 'FoldText()'
endif

to

if g:markdown_fold_override_foldtext
  "let &l:foldtext = s:SID() . 'FoldText()'
  setlocal foldtext=FoldTextWorkaround() 
endif

With this workaround fold headings in 8.2 look very similar again to how they look in 8.0 and earlier. I'm prepared to use it for now, but the issue does need looking at by someone with vim experience.

mikeboiko commented 3 years ago

Thanks for the snippet @arcdale! Since @masukomi doesn't seem to be maintaining this plugin anymore, I made a fork and implemented your bug fix. For other users experiencing this issue, you can clone my fork: https://github.com/mikeboiko/vim-markdown-folding

foalford commented 3 years ago

Following the discovery of @arcdale, I did some research and find that this fix will do the job. :h sid says it.

I forked the repo. However writing up a backward compatible fix with proper test is too much for a first time vim script writer. I put it out here for review. And probably come back to finish the rest (comparability and test)

jm3 commented 1 year ago

@mikeboiko THANK YOU.

masukomi commented 1 year ago

as a note: still looking for a new maintainer for this project. If any of you lovely people are interested in taking it over, please let me know. ;)

port19x commented 1 year ago

Following the discovery of @arcdale, I did some research and find that this fix will do the job. :h sid says it.

I forked the repo. However writing up a backward compatible fix with proper test is too much for a first time vim script writer. I put it out here for review. And probably come back to finish the rest (comparability and test)

Can confirm

port19x commented 1 year ago

as a note: still looking for a new maintainer for this project. If any of you lovely people are interested in taking it over, please let me know. ;)

~~Since I'm doing the opposite migration to you (from doom emacs back to nvim) I might be able to maintain the plugin at least at a superficial level (reviewing PRs, addressing issues, polishing docs). It's unlikely that I'll ever go deep into vimscript, but if I'm not back on emacs in a week or two I'll shoot you an email. Using this plugin to emulate org-modes outlining behaviour while writing a paper with markdown + pandoc~~

nvm

masukomi commented 1 month ago

fixed with PR #43 (Fixed issue with s:SID in Vim 8.2 )