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

Markdown folding disturbs diff mode #427

Open
yous opened this issue Apr 11, 2019 · 8 comments
Open

Markdown folding disturbs diff mode #427

yous opened this issue Apr 11, 2019 · 8 comments

Comments

@yous
Copy link
Contributor

yous commented Apr 11, 2019

For example, add a random line to this project's README.md and save it as README2.md:

# Vim Markdown
Test

[![Build Status](...)](...)

Run vimdiff README.md README2.md, then one of the buffer will have weird folding:

Screenshot 2019-04-11 17 03 16

According to after/ftplugin/markdown.vim, the s:MarkdownSetupFolding() is called on BufWinEnter, BufWritePost , InsertEnter, InsertLeave, CursorHold, CursorHoldI. When Vim shows diff, 'foldmethod' is set to 'diff', and s:MarkdownSetupFolding() resets it. So I think checking if the buffer is diff or not (using &diff) would be appropriate.

@kmac
Copy link

kmac commented Jun 25, 2019

I'm seeing this as well. For me, diffs are completely broken for markdown files when this plugin is active. i.e. [c and ]c don't work either. I'm working around it by not activating the plugin if started in diff mode.

@KSR-Yasuda
Copy link
Contributor

KSR-Yasuda commented Aug 28, 2019

I'm suffering from this, too.

Setting below in .vimrc,
the vim-markdown folding is suppressed to work only at opening file, at least
(Instead of vim-markdown auto setting, set folding settings by oneself).

Plugin 'plasticboy/vim-markdown'
let g:vim_markdown_folding_disabled = 1
autocmd BufNewFile,BufRead *.md setlocal foldmethod=expr foldexpr=Foldexpr_markdown(v:lnum)

@KSR-Yasuda
Copy link
Contributor

So I think checking if the buffer is diff or not (using &diff) would be appropriate.

This patch may work:

diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim
index 8be6ff9..9840217 100644
--- a/after/ftplugin/markdown.vim
+++ b/after/ftplugin/markdown.vim
@@ -177,8 +177,12 @@ function! s:MarkdownSetupFolding()
                 setlocal foldtext=Foldtext_markdown()
             endif
         endif
-        setlocal foldexpr=Foldexpr_markdown(v:lnum)
-        setlocal foldmethod=expr
+        if &foldexpr == ""
+            setlocal foldexpr=Foldexpr_markdown(v:lnum)
+        endif
+        if &foldmethod != "diff"
+            setlocal foldmethod=expr
+        endif
     endif
 endfunction
 

Besides foldmethod, if foldexpr is set, do not override it.

But I'm not sure whether this is a better solution.
Could someone review and merge it?

@KSR-Yasuda
Copy link
Contributor

Perhaps just checking foldexpr might be fine.
Sometimes manual folding is preferred, to add extra folding by zf.

diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim
index 8be6ff9..991a470 100644
--- a/after/ftplugin/markdown.vim
+++ b/after/ftplugin/markdown.vim
@@ -177,8 +177,10 @@ function! s:MarkdownSetupFolding()
                 setlocal foldtext=Foldtext_markdown()
             endif
         endif
-        setlocal foldexpr=Foldexpr_markdown(v:lnum)
-        setlocal foldmethod=expr
+        if &foldexpr == ""
+            setlocal foldexpr=Foldexpr_markdown(v:lnum)
+            setlocal foldmethod=expr
+        endif
     endif
 endfunction
 

@KSR-Yasuda
Copy link
Contributor

This issue being left for a long time,
raised a pull-request formally.

@yous
Copy link
Contributor Author

yous commented Jan 15, 2021

The default value of 'foldexpr' is "0", so comparing against "" would disable the entire feature.

                                                'foldexpr' 'fde'
'foldexpr' 'fde'        string (default: "0")
                        local to window
                        {not available when compiled without the +folding
                        or +eval features}

@KSR-Yasuda
Copy link
Contributor

Oh, this was because I set foldexpr for *.md in .vimrc. Got it.

@KSR-Yasuda
Copy link
Contributor

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants