diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2024-10-21 21:37:00 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2024-10-21 21:37:00 +1300 |
commit | 0a64cb647914befcbb82f2a01cfd298109446bb2 (patch) | |
tree | 4abe2db6b51510375f7c7e86a724d7338055983f | |
parent | Merge branch 'release/v12.45.0' into develop (diff) | |
download | dotfiles-0a64cb647914befcbb82f2a01cfd298109446bb2.tar.gz dotfiles-0a64cb647914befcbb82f2a01cfd298109446bb2.zip |
Adjust Markdown support files for Vim
* Start using the stock plugin again, so move most of the functionality
to after/ftplugin
* Work around mis-placed indent code in the stock ftplugin
* Enable heading folding (the stock one is much faster than mine)
-rw-r--r-- | vim/after/ftplugin/markdown.vim | 48 | ||||
-rw-r--r-- | vim/after/indent/markdown.vim | 2 | ||||
-rw-r--r-- | vim/autoload/markdown.vim | 23 | ||||
-rw-r--r-- | vim/ftplugin/markdown.vim | 69 | ||||
-rw-r--r-- | vim/indent/markdown.vim | 8 |
5 files changed, 63 insertions, 87 deletions
diff --git a/vim/after/ftplugin/markdown.vim b/vim/after/ftplugin/markdown.vim new file mode 100644 index 00000000..46cd8598 --- /dev/null +++ b/vim/after/ftplugin/markdown.vim @@ -0,0 +1,48 @@ +" Clear away these flags we set for the stock ftplugin +unlet g:markdown_recommended_style +unlet g:markdown_folding + +" Spellcheck documents we're actually editing (not just viewing) +if &modifiable && !&readonly + setlocal spell + let b:undo_ftplugin .= '|setlocal spell<' +endif + +" Tolerate leading lowercase letters in README.md files, for things like +" headings being filenames +if expand('%:t') ==# 'README.md' + setlocal spellcapcheck= + let b:undo_ftplugin .= '|setlocal spellcapcheck<' +endif + +" Stop here if the user doesn't want ftplugin mappings +if exists('no_plugin_maps') || exists('no_markdown_maps') + finish +endif + +" Quote operator +nnoremap <buffer> <expr> <LocalLeader>q + \ quote#Quote() +xnoremap <buffer> <expr> <LocalLeader>q + \ quote#Quote() +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>q' + \ . '|xunmap <buffer> <LocalLeader>q' + +" Quote operator with reformatting +nnoremap <buffer> <expr> <LocalLeader>Q + \ quote#QuoteReformat() +xnoremap <buffer> <expr> <LocalLeader>Q + \ quote#QuoteReformat() +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q' + \ . '|xunmap <buffer> <LocalLeader>Q' + +" Automatically format headings +command -buffer -nargs=1 MarkdownHeading + \ call markdown#Heading(<f-args>) +nnoremap <buffer> <LocalLeader>= + \ :<C-U>MarkdownHeading =<CR> +nnoremap <buffer> <LocalLeader>- + \ :<C-U>MarkdownHeading -<CR> +let b:undo_ftplugin .= '|delcommand MarkdownHeading' + \ . '|nunmap <buffer> <LocalLeader>=' + \ . '|nunmap <buffer> <LocalLeader>-' diff --git a/vim/after/indent/markdown.vim b/vim/after/indent/markdown.vim deleted file mode 100644 index bff1b904..00000000 --- a/vim/after/indent/markdown.vim +++ /dev/null @@ -1,2 +0,0 @@ -" Use four spaces for indentation -call indent#Spaces(4) diff --git a/vim/autoload/markdown.vim b/vim/autoload/markdown.vim index 0f03961c..6c8187a0 100644 --- a/vim/autoload/markdown.vim +++ b/vim/autoload/markdown.vim @@ -1,26 +1,3 @@ -" Let's try this heading-based fold method out (Tim Pope) -function! markdown#Fold() abort - let line = getline(v:lnum) - - " Regular headers - let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=') - if depth > 0 - return '>' . depth - endif - - " Setext style headings - if line =~# '^.\+$' - let nextline = getline(v:lnum + 1) - if nextline =~# '^=\+$' - return '>1' - elseif nextline =~# '^-\+$' - return '>2' - endif - endif - - return '=' -endfunction - " Add an underline under a heading function! markdown#Heading(char) abort diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim index ddd88e2c..9c702404 100644 --- a/vim/ftplugin/markdown.vim +++ b/vim/ftplugin/markdown.vim @@ -2,67 +2,12 @@ if exists('b:did_ftplugin') finish endif -let b:did_ftplugin = 1 -" Specify format for comments (lists, quotes) -setlocal comments+=fb:* " Bulleted lists -setlocal comments+=fb:- " Dashed lists -setlocal comments+=fb:+ " Plussed lists (?) -setlocal comments+=n:> " Mail-style quotes -let &l:commentstring = '> %s' -let b:undo_ftplugin = 'setlocal comments< commentstring<' +" Don't load the recommended indent styles---not because they're wrong, but +" because they're loaded in the wrong place! They should be in an indent +" file. We'll handle that ourselves. +" +let g:markdown_recommended_style = 0 -" Specify format options (Tim Pope) -setlocal formatoptions+=ln -let &l:formatlistpat = '^\s*\d\+\.\s\+\|^[-*+]\s\+\|^\[^\ze[^\]]\+\]:' -let b:undo_ftplugin .= '|setlocal formatoptions< formatlistpat<' - -" Let's try this heading-based fold method out (Tim Pope) -setlocal foldexpr=markdown#Fold() -setlocal foldmethod=expr -let b:undo_ftplugin .= '|setlocal foldexpr< foldmethod<' - -" Spellcheck documents we're actually editing (not just viewing) -if &modifiable && !&readonly - setlocal spell - let b:undo_ftplugin .= '|setlocal spell<' -endif - -" Tolerate leading lowercase letters in README.md files, for things like -" headings being filenames -if expand('%:t') ==# 'README.md' - setlocal spellcapcheck= - let b:undo_ftplugin .= '|setlocal spellcapcheck<' -endif - -" Stop here if the user doesn't want ftplugin mappings -if exists('no_plugin_maps') || exists('no_markdown_maps') - finish -endif - -" Quote operator -nnoremap <buffer> <expr> <LocalLeader>q - \ quote#Quote() -xnoremap <buffer> <expr> <LocalLeader>q - \ quote#Quote() -let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>q' - \ . '|xunmap <buffer> <LocalLeader>q' - -" Quote operator with reformatting -nnoremap <buffer> <expr> <LocalLeader>Q - \ quote#QuoteReformat() -xnoremap <buffer> <expr> <LocalLeader>Q - \ quote#QuoteReformat() -let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q' - \ . '|xunmap <buffer> <LocalLeader>Q' - -" Automatically format headings -command -buffer -nargs=1 MarkdownHeading - \ call markdown#Heading(<f-args>) -nnoremap <buffer> <LocalLeader>= - \ :<C-U>MarkdownHeading =<CR> -nnoremap <buffer> <LocalLeader>- - \ :<C-U>MarkdownHeading -<CR> -let b:undo_ftplugin .= '|delcommand MarkdownHeading' - \ . '|nunmap <buffer> <LocalLeader>=' - \ . '|nunmap <buffer> <LocalLeader>-' +" Do load Markdown folding, even though it's a bit slow +let g:markdown_folding = 1 diff --git a/vim/indent/markdown.vim b/vim/indent/markdown.vim new file mode 100644 index 00000000..1f3fa423 --- /dev/null +++ b/vim/indent/markdown.vim @@ -0,0 +1,8 @@ +" Only do this when not yet done for this buffer +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +" Use four spaces for indentation +call indent#Spaces(4) |