From 46c859c8a10b9f420cc73087182f0c9a6b272f71 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Mon, 23 Feb 2015 08:05:46 +0100 Subject: [PATCH 01/16] gx works from anywhere inside Markdown links. Fix #99. --- README.md | 33 ++++++++++++++--- ftplugin/mkd.vim | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ test/map.vader | 48 ++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0a652fa..8389667 100644 --- a/README.md +++ b/README.md @@ -97,12 +97,33 @@ let g:vim_markdown_frontmatter=1 The following work on normal and visual modes: -- `]]`: go to next header. `(Markdown_MoveToNextHeader)` -- `[[`: go to previous header. Contrast with `]c`. `(Markdown_MoveToPreviousHeader)` -- `][`: go to next sibling header if any. `(Markdown_MoveToNextSiblingHeader)` -- `[]`: go to previous sibling header if any. `(Markdown_MoveToPreviousSiblingHeader)` -- `]c`: go to Current header. `(Markdown_MoveToCurHeader)` -- `]u`: go to parent header (Up). `(Markdown_MoveToParentHeader)` +- `gx`: open the link under the cursor in the same browser as the standard `gx` command. + + The standard `gx` is extended by allowing you to put your cursor anywhere inside a link. + + For example, all the following cursor positions will work: + + [Example](http://example.com) + ^ ^ ^^ ^ ^ + 1 2 34 5 6 + + + ^ ^ ^ + 1 2 3 + + Known limitation: does not work for links that span multiple lines. + +- `]]`: go to next header. `(Markdown_MoveToNextHeader)` + +- `[[`: go to previous header. Contrast with `]c`. `(Markdown_MoveToPreviousHeader)` + +- `][`: go to next sibling header if any. `(Markdown_MoveToNextSiblingHeader)` + +- `[]`: go to previous sibling header if any. `(Markdown_MoveToPreviousSiblingHeader)` + +- `]c`: go to Current header. `(Markdown_MoveToCurHeader)` + +- `]u`: go to parent header (Up). `(Markdown_MoveToParentHeader)` ## Commands diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 63d7914..a2e7b5e 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -411,6 +411,100 @@ function! s:TableFormat() call setpos('.', l:pos) endfunction +" Parameters: +" +" - step +1 for right, -1 for left +" +" TODO: multiple lines. +" +function! s:FindCornerOfSyntax(lnum, col, step) + let l:col = a:col + let l:syn = synIDattr(synID(a:lnum, l:col, 1), 'name') + while synIDattr(synID(a:lnum, l:col, 1), 'name') ==# l:syn + let l:col += a:step + endwhile + return l:col - a:step +endfunction + +" Return the next position of the given syntax name, +" inclusive on the given position. +" +" TODO: multiple lines +" +function! s:FindNextSyntax(lnum, col, name) + let l:col = a:col + let l:step = 1 + while synIDattr(synID(a:lnum, l:col, 1), 'name') !=# a:name + let l:col += l:step + endwhile + return [a:lnum, l:col] +endfunction + +function! s:FindCornersOfSyntax(lnum, col) + return [FindLeftOfSyntax(a:lnum, a:col), FindRightOfSyntax(a:lnum, a:col)] +endfunction + +function! s:FindRightOfSyntax(lnum, col) + return FindCornerOfSyntax(a:lnum, a:col, 1) +endfunction + +function! s:FindLeftOfSyntax(lnum, col) + return FindCornerOfSyntax(a:lnum, a:col, -1) +endfunction + +" Returns: +" +" - a string with the the URL for the link under the cursor +" - an empty string if the cursor is not on a link +" +" `b:` instead of `s:` to make it testable. +" +" TODO +" +" - multiline support +" - give an error if the separator does is not on a link +" +function! b:Markdown_GetUrlForPosition(lnum, col) + let l:lnum = a:lnum + let l:col = a:col + let l:syn = synIDattr(synID(l:lnum, l:col, 1), 'name') + + if l:syn ==# 'mkdInlineURL' || l:syn ==# 'mkdURL' || l:syn ==# 'mkdLinkDefTarget' + " Do nothing. + elseif l:syn ==# 'mkdLink' + let [l:lnum, l:col] = FindNextSyntax(l:lnum, l:col, 'mkdURL') + let l:syn = 'mkdURL' + elseif l:syn ==# 'mkdDelimiter' + let l:line = getline(l:lnum) + let l:char = l:line[col - 1] + if l:char ==# '<' + let l:col += 1 + elseif l:char ==# '>' || l:char ==# ')' + let l:col -= 1 + elseif l:char ==# '[' || l:char ==# ']' || l:char ==# '(' + let [l:lnum, l:col] = FindNextSyntax(l:lnum, l:col, 'mkdURL') + else + return '' + endif + else + return '' + endif + + let [l:left, l:right] = FindCornersOfSyntax(l:lnum, l:col) + return getline(l:lnum)[l:left - 1 : l:right - 1] +endfunction + +" Front end for GetUrlForPosition. +" +function! s:OpenUrlUnderCursor() + let l:url = b:Markdown_GetUrlForPosition(line('.'), col('.')) + if l:url != '' + call netrw#NetrwBrowseX(l:url, 0) + else + echomsg 'The cursor is not on a link.' + endif +endfunction + call MapNormVis('(Markdown_MoveToNextHeader)', 'Markdown_MoveToNextHeader') call MapNormVis('(Markdown_MoveToPreviousHeader)', 'Markdown_MoveToPreviousHeader') call MapNormVis('(Markdown_MoveToNextSiblingHeader)', 'Markdown_MoveToNextSiblingHeader') @@ -419,6 +513,7 @@ call MapNormVis('(Markdown_MoveToPreviousSiblingHeader)', 'Markd call MapNormVis('(Markdown_MoveToParentHeader)', 'Markdown_MoveToParentHeader') " Menmonic: Current call MapNormVis('(Markdown_MoveToCurHeader)', 'Markdown_MoveToCurHeader') +nnoremap (OpenUrlUnderCursor) :call OpenUrlUnderCursor() if !get(g:, 'vim_markdown_no_default_key_mappings', 0) nmap ]] (Markdown_MoveToNextHeader) @@ -427,6 +522,7 @@ if !get(g:, 'vim_markdown_no_default_key_mappings', 0) nmap [] (Markdown_MoveToPreviousSiblingHeader) nmap ]u (Markdown_MoveToParentHeader) nmap ]c (Markdown_MoveToCurHeader) + nmap gx (OpenUrlUnderCursor) vmap ]] (Markdown_MoveToNextHeader) vmap [[ (Markdown_MoveToPreviousHeader) diff --git a/test/map.vader b/test/map.vader index 6cf0cee..51bde78 100644 --- a/test/map.vader +++ b/test/map.vader @@ -1,3 +1,51 @@ +Given mkd; +a c + +Execute (gx autolink): + let b:url = 'http://b' + let b:line = getline(1) + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'a') + 1), '' + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, '<') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'h') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, '>') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'c') + 1), '' + +Given mkd; +a http://b.bb c + +Execute (gx implicit autolink): + let b:url = 'http://b.bb' + let b:line = getline(1) + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'a') + 1), '' + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'h') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'c') + 1), '' + +Given mkd; +[a]: http://b "c" + +Execute (gx link reference definition): + let b:url = 'http://b' + let b:line = getline(1) + " TODO would be cool if all of the following gave the link. + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'a') + 1), '' + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'h') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'c') + 1), '' + +Given mkd; +a [b](c) d + +Execute (gx autolink): + let b:url = 'c' + let b:line = getline(1) + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'a') + 1), '' + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, '[') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'b') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, ']') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, '(') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'c') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, ')') + 1), b:url + AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'd') + 1), '' + Given mkd; # a -- 2.39.2 From 8853cbca8d956767e357540de792259f3922d15b Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Thu, 16 Apr 2015 11:09:58 +0200 Subject: [PATCH 02/16] Remove parenthesis from maps --- README.md | 12 ++++++------ ftplugin/mkd.vim | 42 ++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8389667..5ba457d 100644 --- a/README.md +++ b/README.md @@ -113,17 +113,17 @@ The following work on normal and visual modes: Known limitation: does not work for links that span multiple lines. -- `]]`: go to next header. `(Markdown_MoveToNextHeader)` +- `]]`: go to next header. `Markdown_MoveToNextHeader` -- `[[`: go to previous header. Contrast with `]c`. `(Markdown_MoveToPreviousHeader)` +- `[[`: go to previous header. Contrast with `]c`. `Markdown_MoveToPreviousHeader` -- `][`: go to next sibling header if any. `(Markdown_MoveToNextSiblingHeader)` +- `][`: go to next sibling header if any. `Markdown_MoveToNextSiblingHeader` -- `[]`: go to previous sibling header if any. `(Markdown_MoveToPreviousSiblingHeader)` +- `[]`: go to previous sibling header if any. `Markdown_MoveToPreviousSiblingHeader` -- `]c`: go to Current header. `(Markdown_MoveToCurHeader)` +- `]c`: go to Current header. `Markdown_MoveToCurHeader` -- `]u`: go to parent header (Up). `(Markdown_MoveToParentHeader)` +- `]u`: go to parent header (Up). `Markdown_MoveToParentHeader` ## Commands diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index a2e7b5e..9d84c77 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -505,31 +505,29 @@ function! s:OpenUrlUnderCursor() endif endfunction -call MapNormVis('(Markdown_MoveToNextHeader)', 'Markdown_MoveToNextHeader') -call MapNormVis('(Markdown_MoveToPreviousHeader)', 'Markdown_MoveToPreviousHeader') -call MapNormVis('(Markdown_MoveToNextSiblingHeader)', 'Markdown_MoveToNextSiblingHeader') -call MapNormVis('(Markdown_MoveToPreviousSiblingHeader)', 'Markdown_MoveToPreviousSiblingHeader') -" Menmonic: Up -call MapNormVis('(Markdown_MoveToParentHeader)', 'Markdown_MoveToParentHeader') -" Menmonic: Current -call MapNormVis('(Markdown_MoveToCurHeader)', 'Markdown_MoveToCurHeader') +call MapNormVis('Markdown_MoveToNextHeader', 'Markdown_MoveToNextHeader') +call MapNormVis('Markdown_MoveToPreviousHeader', 'Markdown_MoveToPreviousHeader') +call MapNormVis('Markdown_MoveToNextSiblingHeader', 'Markdown_MoveToNextSiblingHeader') +call MapNormVis('Markdown_MoveToPreviousSiblingHeader', 'Markdown_MoveToPreviousSiblingHeader') +call MapNormVis('Markdown_MoveToParentHeader', 'Markdown_MoveToParentHeader') +call MapNormVis('Markdown_MoveToCurHeader', 'Markdown_MoveToCurHeader') nnoremap (OpenUrlUnderCursor) :call OpenUrlUnderCursor() if !get(g:, 'vim_markdown_no_default_key_mappings', 0) - nmap ]] (Markdown_MoveToNextHeader) - nmap [[ (Markdown_MoveToPreviousHeader) - nmap ][ (Markdown_MoveToNextSiblingHeader) - nmap [] (Markdown_MoveToPreviousSiblingHeader) - nmap ]u (Markdown_MoveToParentHeader) - nmap ]c (Markdown_MoveToCurHeader) - nmap gx (OpenUrlUnderCursor) - - vmap ]] (Markdown_MoveToNextHeader) - vmap [[ (Markdown_MoveToPreviousHeader) - vmap ][ (Markdown_MoveToNextSiblingHeader) - vmap [] (Markdown_MoveToPreviousSiblingHeader) - vmap ]u (Markdown_MoveToParentHeader) - vmap ]c (Markdown_MoveToCurHeader) + nmap ]] Markdown_MoveToNextHeader + nmap [[ Markdown_MoveToPreviousHeader + nmap ][ Markdown_MoveToNextSiblingHeader + nmap [] Markdown_MoveToPreviousSiblingHeader + nmap ]u Markdown_MoveToParentHeader + nmap ]c Markdown_MoveToCurHeader + nmap gx OpenUrlUnderCursor + + vmap ]] Markdown_MoveToNextHeader + vmap [[ Markdown_MoveToPreviousHeader + vmap ][ Markdown_MoveToNextSiblingHeader + vmap [] Markdown_MoveToPreviousSiblingHeader + vmap ]u Markdown_MoveToParentHeader + vmap ]c Markdown_MoveToCurHeader endif command! -buffer -range=% HeaderDecrease call s:HeaderDecrease(, ) -- 2.39.2 From f3c4ace059796ff87802aa0d20732965bb8c8a32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?utf8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Thu, 16 Apr 2015 13:56:12 +0200 Subject: [PATCH 03/16] Improve style of ftplugin/mkd.vim - remove Markdown_ prefix from s: functions - always add one empty line between commands and methods --- ftplugin/mkd.vim | 149 +++++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 71 deletions(-) diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 9d84c77..05316ab 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -12,7 +12,7 @@ " " - move the cursor. All other functions do not move the cursor. " -" This is how you should view headers: +" This is how you should view headers for the header mappings: " " |BUFFER " | @@ -46,6 +46,7 @@ " e-+ " For each level, contains the regexp that matches at that level only. +" let s:levelRegexpDict = { \ 1: '\v^(#[^#]@=|.+\n\=+$)', \ 2: '\v^(##[^#]@=|.+\n-+$)', @@ -69,7 +70,7 @@ let s:headersRegexp = '\v^(#|.+\n(\=+|-+)$)' " " @param a:1 The line to look the header of. Default value: `getpos('.')`. " -function! s:Markdown_GetHeaderLineNum(...) +function! s:GetHeaderLineNum(...) if a:0 == 0 let l:l = line('.') else @@ -84,15 +85,15 @@ function! s:Markdown_GetHeaderLineNum(...) return 0 endfunction -" - if inside a header goes to it. +" - if inside a header goes to it. " Return its line number. " -" - if on top level outside any headers, +" - if on top level outside any headers, " print a warning " Return `0`. " -function! s:Markdown_MoveToCurHeader() - let l:lineNum = s:Markdown_GetHeaderLineNum() +function! s:MoveToCurHeader() + let l:lineNum = s:GetHeaderLineNum() if l:lineNum != 0 call cursor(l:lineNum, 1) else @@ -106,7 +107,7 @@ endfunction " " If there are no more headers, print a warning. " -function! s:Markdown_MoveToNextHeader() +function! s:MoveToNextHeader() if search(s:headersRegexp, 'W') == 0 "normal! G echo 'no next header' @@ -117,13 +118,13 @@ endfunction " " If it does not exist, print a warning. " -function! s:Markdown_MoveToPreviousHeader() - let l:curHeaderLineNumber = s:Markdown_GetHeaderLineNum() +function! s:MoveToPreviousHeader() + let l:curHeaderLineNumber = s:GetHeaderLineNum() let l:noPreviousHeader = 0 if l:curHeaderLineNumber <= 1 let l:noPreviousHeader = 1 else - let l:previousHeaderLineNumber = s:Markdown_GetHeaderLineNum(l:curHeaderLineNumber - 1) + let l:previousHeaderLineNumber = s:GetHeaderLineNum(l:curHeaderLineNumber - 1) if l:previousHeaderLineNumber == 0 let l:noPreviousHeader = 1 else @@ -139,15 +140,15 @@ endfunction " " - if line is at top level outside any headers, return `0`. " -function! s:Markdown_GetHeaderLevel(...) +function! s:GetHeaderLevel(...) if a:0 == 0 let l:line = line('.') else let l:line = a:1 endif - let l:linenum = s:Markdown_GetHeaderLineNum(l:line) + let l:linenum = s:GetHeaderLineNum(l:line) if l:linenum != 0 - return s:Markdown_GetLevelOfHeaderAtLine(l:linenum) + return s:GetLevelOfHeaderAtLine(l:linenum) else return 0 endif @@ -157,7 +158,7 @@ endfunction " " If there is no header at the given line, returns `0`. " -function! s:Markdown_GetLevelOfHeaderAtLine(linenum) +function! s:GetLevelOfHeaderAtLine(linenum) let l:lines = join(getline(a:linenum, a:linenum + 1), "\n") for l:key in keys(s:levelRegexpDict) if l:lines =~ get(s:levelRegexpDict, l:key) @@ -171,8 +172,8 @@ endfunction " " If it does not exit, print a warning and do nothing. " -function! s:Markdown_MoveToParentHeader() - let l:linenum = s:Markdown_GetParentHeaderLineNumber() +function! s:MoveToParentHeader() + let l:linenum = s:GetParentHeaderLineNumber() if l:linenum != 0 call cursor(l:linenum, 1) else @@ -184,15 +185,15 @@ endfunction " " If it has no parent, return `0`. " -function! s:Markdown_GetParentHeaderLineNumber(...) +function! s:GetParentHeaderLineNumber(...) if a:0 == 0 let l:line = line('.') else let l:line = a:1 endif - let l:level = s:Markdown_GetHeaderLevel(l:line) + let l:level = s:GetHeaderLevel(l:line) if l:level > 1 - let l:linenum = s:Markdown_GetPreviousHeaderLineNumberAtLevel(l:level - 1, l:line) + let l:linenum = s:GetPreviousHeaderLineNumberAtLevel(l:level - 1, l:line) return l:linenum endif return 0 @@ -205,7 +206,7 @@ endfunction " " If none return 0. " -function! s:Markdown_GetNextHeaderLineNumberAtLevel(level, ...) +function! s:GetNextHeaderLineNumberAtLevel(level, ...) if a:0 < 1 let l:line = line('.') else @@ -228,7 +229,7 @@ endfunction " " If none return 0. " -function! s:Markdown_GetPreviousHeaderLineNumberAtLevel(level, ...) +function! s:GetPreviousHeaderLineNumberAtLevel(level, ...) if a:0 == 0 let l:line = line('.') else @@ -248,16 +249,16 @@ endfunction " " If there is no next siblings, print a warning and don't move. " -function! s:Markdown_MoveToNextSiblingHeader() - let l:curHeaderLineNumber = s:Markdown_GetHeaderLineNum() - let l:curHeaderLevel = s:Markdown_GetLevelOfHeaderAtLine(l:curHeaderLineNumber) - let l:curHeaderParentLineNumber = s:Markdown_GetParentHeaderLineNumber() - let l:nextHeaderSameLevelLineNumber = s:Markdown_GetNextHeaderLineNumberAtLevel(l:curHeaderLevel, l:curHeaderLineNumber + 1) +function! s:MoveToNextSiblingHeader() + let l:curHeaderLineNumber = s:GetHeaderLineNum() + let l:curHeaderLevel = s:GetLevelOfHeaderAtLine(l:curHeaderLineNumber) + let l:curHeaderParentLineNumber = s:GetParentHeaderLineNumber() + let l:nextHeaderSameLevelLineNumber = s:GetNextHeaderLineNumberAtLevel(l:curHeaderLevel, l:curHeaderLineNumber + 1) let l:noNextSibling = 0 if l:nextHeaderSameLevelLineNumber == 0 let l:noNextSibling = 1 else - let l:nextHeaderSameLevelParentLineNumber = s:Markdown_GetParentHeaderLineNumber(l:nextHeaderSameLevelLineNumber) + let l:nextHeaderSameLevelParentLineNumber = s:GetParentHeaderLineNumber(l:nextHeaderSameLevelLineNumber) if l:curHeaderParentLineNumber == l:nextHeaderSameLevelParentLineNumber call cursor(l:nextHeaderSameLevelLineNumber, 1) else @@ -273,16 +274,16 @@ endfunction " " If there is no previous siblings, print a warning and do nothing. " -function! s:Markdown_MoveToPreviousSiblingHeader() - let l:curHeaderLineNumber = s:Markdown_GetHeaderLineNum() - let l:curHeaderLevel = s:Markdown_GetLevelOfHeaderAtLine(l:curHeaderLineNumber) - let l:curHeaderParentLineNumber = s:Markdown_GetParentHeaderLineNumber() - let l:previousHeaderSameLevelLineNumber = s:Markdown_GetPreviousHeaderLineNumberAtLevel(l:curHeaderLevel, l:curHeaderLineNumber - 1) +function! s:MoveToPreviousSiblingHeader() + let l:curHeaderLineNumber = s:GetHeaderLineNum() + let l:curHeaderLevel = s:GetLevelOfHeaderAtLine(l:curHeaderLineNumber) + let l:curHeaderParentLineNumber = s:GetParentHeaderLineNumber() + let l:previousHeaderSameLevelLineNumber = s:GetPreviousHeaderLineNumberAtLevel(l:curHeaderLevel, l:curHeaderLineNumber - 1) let l:noPreviousSibling = 0 if l:previousHeaderSameLevelLineNumber == 0 let l:noPreviousSibling = 1 else - let l:previousHeaderSameLevelParentLineNumber = s:Markdown_GetParentHeaderLineNumber(l:previousHeaderSameLevelLineNumber) + let l:previousHeaderSameLevelParentLineNumber = s:GetParentHeaderLineNumber(l:previousHeaderSameLevelLineNumber) if l:curHeaderParentLineNumber == l:previousHeaderSameLevelParentLineNumber call cursor(l:previousHeaderSameLevelLineNumber, 1) else @@ -294,7 +295,7 @@ function! s:Markdown_MoveToPreviousSiblingHeader() endif endfunction -function! s:Markdown_Toc(...) +function! s:Toc(...) if a:0 > 0 let l:window_type = a:1 else @@ -343,22 +344,10 @@ function! s:Markdown_Toc(...) normal! gg endfunction -" Wrapper to do move commands in visual mode. +" Convert Setex headers in range `line1 .. line2` to Atx. " -function! s:VisMove(f) - norm! gv - call function(a:f)() -endfunction - -" Map in both normal and visual modes. +" Return the number of conversions. " -function! s:MapNormVis(rhs,lhs) - execute 'nn ' . a:rhs . ' :call ' . a:lhs . '()' - execute 'vn ' . a:rhs . ' :call VisMove(''' . a:lhs . ''')' -endfunction - -" Convert Setex headers in range `line1 .. line2` to Atx. -" Returns the number of conversions. function! s:SetexToAtx(line1, line2) let l:originalNumLines = line('$') execute 'silent! ' . a:line1 . ',' . a:line2 . 'substitute/\v(.*\S.*)\n\=+$/# \1/' @@ -367,7 +356,9 @@ function! s:SetexToAtx(line1, line2) endfunction " If `a:1` is 0, decrease the level of all headers in range `line1 .. line2`. +" " Otherwise, increase the level. `a:1` defaults to `0`. +" function! s:HeaderDecrease(line1, line2, ...) if a:0 > 0 let l:increase = a:1 @@ -396,19 +387,35 @@ function! s:HeaderDecrease(line1, line2, ...) endfunction " Format table under cursor. +" " Depends on Tabularize. +" function! s:TableFormat() - let l:pos = getpos('.') - normal! { - " Search instead of `normal! j` because of the table at beginning of file edge case. - call search('|') - normal! j - " Remove everything that is not a pipe othewise well formated tables would grow - " because of addition of 2 spaces on the separator line by Tabularize /|. - s/[^|]//g - Tabularize /| - s/ /-/g - call setpos('.', l:pos) + let l:pos = getpos('.') + normal! { + " Search instead of `normal! j` because of the table at beginning of file edge case. + call search('|') + normal! j + " Remove everything that is not a pipe othewise well formated tables would grow + " because of addition of 2 spaces on the separator line by Tabularize /|. + s/[^|]//g + Tabularize /| + s/ /-/g + call setpos('.', l:pos) +endfunction + +" Wrapper to do move commands in visual mode. +" +function! s:VisMove(f) + norm! gv + call function(a:f)() +endfunction + +" Map in both normal and visual modes. +" +function! s:MapNormVis(rhs,lhs) + execute 'nn ' . a:rhs . ' :call ' . a:lhs . '()' + execute 'vn ' . a:rhs . ' :call VisMove(''' . a:lhs . ''')' endfunction " Parameters: @@ -505,13 +512,13 @@ function! s:OpenUrlUnderCursor() endif endfunction -call MapNormVis('Markdown_MoveToNextHeader', 'Markdown_MoveToNextHeader') -call MapNormVis('Markdown_MoveToPreviousHeader', 'Markdown_MoveToPreviousHeader') -call MapNormVis('Markdown_MoveToNextSiblingHeader', 'Markdown_MoveToNextSiblingHeader') -call MapNormVis('Markdown_MoveToPreviousSiblingHeader', 'Markdown_MoveToPreviousSiblingHeader') -call MapNormVis('Markdown_MoveToParentHeader', 'Markdown_MoveToParentHeader') -call MapNormVis('Markdown_MoveToCurHeader', 'Markdown_MoveToCurHeader') -nnoremap (OpenUrlUnderCursor) :call OpenUrlUnderCursor() +call MapNormVis('Markdown_MoveToNextHeader', 'MoveToNextHeader') +call MapNormVis('Markdown_MoveToPreviousHeader', 'MoveToPreviousHeader') +call MapNormVis('Markdown_MoveToNextSiblingHeader', 'MoveToNextSiblingHeader') +call MapNormVis('Markdown_MoveToPreviousSiblingHeader', 'MoveToPreviousSiblingHeader') +call MapNormVis('Markdown_MoveToParentHeader', 'MoveToParentHeader') +call MapNormVis('Markdown_MoveToCurHeader', 'MoveToCurHeader') +nnoremap Markdown_OpenUrlUnderCursor :call OpenUrlUnderCursor() if !get(g:, 'vim_markdown_no_default_key_mappings', 0) nmap ]] Markdown_MoveToNextHeader @@ -520,7 +527,7 @@ if !get(g:, 'vim_markdown_no_default_key_mappings', 0) nmap [] Markdown_MoveToPreviousSiblingHeader nmap ]u Markdown_MoveToParentHeader nmap ]c Markdown_MoveToCurHeader - nmap gx OpenUrlUnderCursor + nmap gx Markdown_OpenUrlUnderCursor vmap ]] Markdown_MoveToNextHeader vmap [[ Markdown_MoveToPreviousHeader @@ -534,7 +541,7 @@ command! -buffer -range=% HeaderDecrease call s:HeaderDecrease(, ) command! -buffer -range=% HeaderIncrease call s:HeaderDecrease(, , 1) command! -buffer -range=% SetexToAtx call s:SetexToAtx(, ) command! -buffer TableFormat call s:TableFormat() -command! -buffer Toc call s:Markdown_Toc() -command! -buffer Toch call s:Markdown_Toc('horizontal') -command! -buffer Tocv call s:Markdown_Toc('vertical') -command! -buffer Toct call s:Markdown_Toc('tab') +command! -buffer Toc call s:Toc() +command! -buffer Toch call s:Toc('horizontal') +command! -buffer Tocv call s:Toc('vertical') +command! -buffer Toct call s:Toc('tab') -- 2.39.2 From 7699a752ecdff53ffce1e8bf667caa60d92a42c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?utf8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Fri, 17 Apr 2015 10:12:34 +0200 Subject: [PATCH 04/16] Add TOC to README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 5ba457d..2ba5429 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,13 @@ Syntax highlighting, matching rules and mappings for [the original Markdown](http://daringfireball.net/projects/markdown/) and extensions. +1. [Installation](#installation) +1. [Options](#options) +1. [Mappings](#mappings) +1. [Commands](#commands) +1. [Credits](#credits) +1. [License](#license) + ## Installation If you use [Vundle](https://github.com/gmarik/vundle), add the following line to your `~/.vimrc`: -- 2.39.2 From ae271c7a4532c675f9c052021918fc25966a149a Mon Sep 17 00:00:00 2001 From: KazuakiM Date: Thu, 23 Apr 2015 23:21:11 +0900 Subject: [PATCH 05/16] Update Markdown_GetUrlForPosition function b: to s: --- ftplugin/mkd.vim | 6 ++---- test/map.vader | 42 +++++++++++++++++++++++------------------- test/vimrc | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 05316ab..6e04bd2 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -464,14 +464,12 @@ endfunction " - a string with the the URL for the link under the cursor " - an empty string if the cursor is not on a link " -" `b:` instead of `s:` to make it testable. -" " TODO " " - multiline support " - give an error if the separator does is not on a link " -function! b:Markdown_GetUrlForPosition(lnum, col) +function! s:Markdown_GetUrlForPosition(lnum, col) let l:lnum = a:lnum let l:col = a:col let l:syn = synIDattr(synID(l:lnum, l:col, 1), 'name') @@ -504,7 +502,7 @@ endfunction " Front end for GetUrlForPosition. " function! s:OpenUrlUnderCursor() - let l:url = b:Markdown_GetUrlForPosition(line('.'), col('.')) + let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.')) if l:url != '' call netrw#NetrwBrowseX(l:url, 0) else diff --git a/test/map.vader b/test/map.vader index 51bde78..ea96182 100644 --- a/test/map.vader +++ b/test/map.vader @@ -4,11 +4,12 @@ a c Execute (gx autolink): let b:url = 'http://b' let b:line = getline(1) - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'a') + 1), '' - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, '<') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'h') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, '>') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'c') + 1), '' + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/mkd.vim', 'Markdown_GetUrlForPosition') + AssertEqual b:func(1, match(b:line, 'a') + 1), '' + AssertEqual b:func(1, match(b:line, '<') + 1), b:url + AssertEqual b:func(1, match(b:line, 'h') + 1), b:url + AssertEqual b:func(1, match(b:line, '>') + 1), b:url + AssertEqual b:func(1, match(b:line, 'c') + 1), '' Given mkd; a http://b.bb c @@ -16,9 +17,10 @@ a http://b.bb c Execute (gx implicit autolink): let b:url = 'http://b.bb' let b:line = getline(1) - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'a') + 1), '' - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'h') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'c') + 1), '' + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/mkd.vim', 'Markdown_GetUrlForPosition') + AssertEqual b:func(1, match(b:line, 'a') + 1), '' + AssertEqual b:func(1, match(b:line, 'h') + 1), b:url + AssertEqual b:func(1, match(b:line, 'c') + 1), '' Given mkd; [a]: http://b "c" @@ -26,10 +28,11 @@ Given mkd; Execute (gx link reference definition): let b:url = 'http://b' let b:line = getline(1) + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/mkd.vim', 'Markdown_GetUrlForPosition') " TODO would be cool if all of the following gave the link. - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'a') + 1), '' - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'h') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'c') + 1), '' + AssertEqual b:func(1, match(b:line, 'a') + 1), '' + AssertEqual b:func(1, match(b:line, 'h') + 1), b:url + AssertEqual b:func(1, match(b:line, 'c') + 1), '' Given mkd; a [b](c) d @@ -37,14 +40,15 @@ a [b](c) d Execute (gx autolink): let b:url = 'c' let b:line = getline(1) - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'a') + 1), '' - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, '[') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'b') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, ']') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, '(') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'c') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, ')') + 1), b:url - AssertEqual b:Markdown_GetUrlForPosition(1, match(b:line, 'd') + 1), '' + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/mkd.vim', 'Markdown_GetUrlForPosition') + AssertEqual b:func(1, match(b:line, 'a') + 1), '' + AssertEqual b:func(1, match(b:line, '[') + 1), b:url + AssertEqual b:func(1, match(b:line, 'b') + 1), b:url + AssertEqual b:func(1, match(b:line, ']') + 1), b:url + AssertEqual b:func(1, match(b:line, '(') + 1), b:url + AssertEqual b:func(1, match(b:line, 'c') + 1), b:url + AssertEqual b:func(1, match(b:line, ')') + 1), b:url + AssertEqual b:func(1, match(b:line, 'd') + 1), '' Given mkd; # a diff --git a/test/vimrc b/test/vimrc index 86020ed..44df1b6 100644 --- a/test/vimrc +++ b/test/vimrc @@ -6,3 +6,19 @@ filetype on filetype plugin on filetype indent on syntax on + +function! Markdown_GetScriptID(fname) abort + let a:snlist = '' + redir => a:snlist + silent! scriptnames + redir END + let a:mx = '^\s*\(\d\+\):\s*\(.*\)$' + for a:line in split(a:snlist, "\n") + if stridx(a:line, a:fname) >= 0 + return substitute(a:line, a:mx, '\1', '') + endif + endfor +endfunction +function! Markdown_GetFunc(fname, funcname) abort + return function('' . Markdown_GetScriptID(a:fname) . '_' . a:funcname) +endfunction -- 2.39.2 From 1510e2cad59855b3bc4c48ec9a4c07c94e4bcb58 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?utf8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Mon, 4 May 2015 15:35:20 +0200 Subject: [PATCH 06/16] Document Markdown_OpenUrlUnderCursor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ba457d..e92ae3b 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ let g:vim_markdown_frontmatter=1 The following work on normal and visual modes: -- `gx`: open the link under the cursor in the same browser as the standard `gx` command. +- `gx`: open the link under the cursor in the same browser as the standard `gx` command. `Markdown_OpenUrlUnderCursor` The standard `gx` is extended by allowing you to put your cursor anywhere inside a link. -- 2.39.2 From 21e96cbe9b8e6ea61b11709fff11e4d42a82ce16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?utf8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Mon, 4 May 2015 16:14:30 +0200 Subject: [PATCH 07/16] Allow users to disable individual maps with hasmapto checks --- README.md | 8 ++++++++ ftplugin/mkd.vim | 28 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5ba457d..894037a 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,14 @@ The following work on normal and visual modes: - `]u`: go to parent header (Up). `Markdown_MoveToParentHeader` +This plugging follows the recommended Vim plugin mapping interface, so if you want to change the map `]u` to `asdf`, add to your `.vimrc`: + + map asdf Markdown_MoveToParentHeader + +To disable a map, use: + + map Markdown_MoveToParentHeader + ## Commands - `:HeaderDecrease`: diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 6e04bd2..d67864a 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -510,6 +510,13 @@ function! s:OpenUrlUnderCursor() endif endfunction +function! s:MapNotHasmapto(lhs, rhs) + if !hasmapto('' . a:rhs) + execute 'nmap ' . a:lhs . ' ' . a:rhs + execute 'vmap ' . a:lhs . ' ' . a:rhs + endif +endfunction + call MapNormVis('Markdown_MoveToNextHeader', 'MoveToNextHeader') call MapNormVis('Markdown_MoveToPreviousHeader', 'MoveToPreviousHeader') call MapNormVis('Markdown_MoveToNextSiblingHeader', 'MoveToNextSiblingHeader') @@ -519,20 +526,13 @@ call MapNormVis('Markdown_MoveToCurHeader', 'MoveToCurHeader') nnoremap Markdown_OpenUrlUnderCursor :call OpenUrlUnderCursor() if !get(g:, 'vim_markdown_no_default_key_mappings', 0) - nmap ]] Markdown_MoveToNextHeader - nmap [[ Markdown_MoveToPreviousHeader - nmap ][ Markdown_MoveToNextSiblingHeader - nmap [] Markdown_MoveToPreviousSiblingHeader - nmap ]u Markdown_MoveToParentHeader - nmap ]c Markdown_MoveToCurHeader - nmap gx Markdown_OpenUrlUnderCursor - - vmap ]] Markdown_MoveToNextHeader - vmap [[ Markdown_MoveToPreviousHeader - vmap ][ Markdown_MoveToNextSiblingHeader - vmap [] Markdown_MoveToPreviousSiblingHeader - vmap ]u Markdown_MoveToParentHeader - vmap ]c Markdown_MoveToCurHeader + call MapNotHasmapto(']]', 'Markdown_MoveToNextHeader') + call MapNotHasmapto('[[', 'Markdown_MoveToPreviousHeader') + call MapNotHasmapto('][', 'Markdown_MoveToNextSiblingHeader') + call MapNotHasmapto('[]', 'Markdown_MoveToPreviousSiblingHeader') + call MapNotHasmapto(']u', 'Markdown_MoveToParentHeader') + call MapNotHasmapto(']c', 'Markdown_MoveToCurHeader') + call MapNotHasmapto('gx', 'Markdown_OpenUrlUnderCursor') endif command! -buffer -range=% HeaderDecrease call s:HeaderDecrease(, ) -- 2.39.2 From 314f86e7a11e5e90eb49a795c29b807ceb46fe6c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?utf8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Mon, 4 May 2015 16:28:03 +0200 Subject: [PATCH 08/16] Fix typo plugging --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 770c625..a5bdbbe 100644 --- a/README.md +++ b/README.md @@ -132,11 +132,11 @@ The following work on normal and visual modes: - `]u`: go to parent header (Up). `Markdown_MoveToParentHeader` -This plugging follows the recommended Vim plugin mapping interface, so if you want to change the map `]u` to `asdf`, add to your `.vimrc`: +This plugin follows the recommended Vim plugin mapping interface, so to change the map `]u` to `asdf`, add to your `.vimrc`: map asdf Markdown_MoveToParentHeader -To disable a map, use: +To disable a map use: map Markdown_MoveToParentHeader -- 2.39.2 From df5d5c5adb5ff6a087e1e837aaaa25e22ba74d70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Simon=20D=C3=A9saulniers?= Date: Mon, 4 May 2015 18:05:41 -0400 Subject: [PATCH 09/16] adding VersionAwareNetrwBrowseX() function for doing right call to netrw browsex --- ftplugin/mkd.vim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index d67864a..9b98767 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -504,12 +504,20 @@ endfunction function! s:OpenUrlUnderCursor() let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.')) if l:url != '' - call netrw#NetrwBrowseX(l:url, 0) + call s:VersionAwareNetrwBrowseX(l:url) else echomsg 'The cursor is not on a link.' endif endfunction +function! s:VersionAwareNetrwBrowseX(url) + if has('patch-7.4.567') + call netrw#BrowseX(a:url, 0) + else + call netrw#NetrwBrowseX(a:url, 0) + endif +endf + function! s:MapNotHasmapto(lhs, rhs) if !hasmapto('' . a:rhs) execute 'nmap ' . a:lhs . ' ' . a:rhs -- 2.39.2 From df4229881641e6e0bba075a394009ac3d1b38bcc Mon Sep 17 00:00:00 2001 From: "Jeremy Pallats/starcraft.man" Date: Mon, 11 May 2015 08:21:51 -0400 Subject: [PATCH 10/16] Build latest vim quickly from git mirror * Executes test against travis package vim & latest 7.4.x * Fixes #201 --- .travis.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 12bf12e..130c2af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,22 @@ language: vim +env: + - TEST=package + - TEST=latest -install: | - sudo apt-get update - sudo apt-get install vim +before_script: | cd .. + if [ "$TEST" = "package" ]; then + sudo apt-get -y update + sudo apt-get -y install vim + else + git clone --depth 1 https://github.com/vim/vim + cd vim + ./configure --with-features=huge + make + sudo make install + export PATH="/usr/local/bin:$PATH" + cd - + fi git clone https://github.com/godlygeek/tabular git clone https://github.com/junegunn/vader.vim -- 2.39.2 From af5bd7c119e061838d483fb9903f456e09e73518 Mon Sep 17 00:00:00 2001 From: Simon Ruggier Date: Sun, 24 May 2015 17:37:22 -0400 Subject: [PATCH 11/16] CONTRIBUTING.md: add a section about issue reporting --- CONTRIBUTING.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b29b8cc..a2c1580 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,3 +37,18 @@ If you wish to have a behavior that differs from that style guide, add an option # Tests All new features must have unit tests. + +# Issues + +Issues are tracked within GitHub. + +When reporting issues, your report is more effective if you include a minimal example file that reproduces the problem. Try to trim out as much as possible, until you have the smallest possible file that still reproduces the issue. Paste the example inline into your issue report, quoted using four spaces at the beginning of each line, like this example from issue [#189](https://github.com/plasticboy/vim-markdown/issues/189): + +``` +Minimal example: + + ``` + = + ``` + bad! +``` -- 2.39.2 From 88cdc1f523cbd9af2d4d375d13e22488ee08fb64 Mon Sep 17 00:00:00 2001 From: hori-ryota Date: Wed, 17 Jun 2015 15:42:54 +0900 Subject: [PATCH 12/16] Use compound filetype for plugins using "markdown" filetype --- ftdetect/mkd.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftdetect/mkd.vim b/ftdetect/mkd.vim index 9696cac..fab3ab0 100644 --- a/ftdetect/mkd.vim +++ b/ftdetect/mkd.vim @@ -1,3 +1,3 @@ " markdown filetype file -au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=mkd -au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} set filetype=mkd +au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=mkd.markdown +au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} set filetype=mkd.markdown -- 2.39.2 From ef44c9e7fc839bec7bb17f8264442912f38c903c Mon Sep 17 00:00:00 2001 From: Yue Xin Date: Sun, 16 Aug 2015 19:50:10 +0800 Subject: [PATCH 13/16] swap out mkd, successfully... Signed-off-by: yuexin --- Makefile | 10 +++---- README.md | 2 +- after/ftplugin/{mkd.vim => markdown.vim} | 0 ftdetect/{mkd.vim => markdown.vim} | 0 ftplugin/{mkd.vim => markdown.vim} | 0 indent/{mkd.vim => markdown.vim} | 6 ++-- registry/markdown.yaml | 7 +++++ registry/mkd.yaml | 7 ----- syntax/{mkd.vim => markdown.vim} | 0 test/map.vader | 26 ++++++++--------- test/syntax.vader | 36 ++++++++++++------------ 11 files changed, 47 insertions(+), 47 deletions(-) rename after/ftplugin/{mkd.vim => markdown.vim} (100%) rename ftdetect/{mkd.vim => markdown.vim} (100%) rename ftplugin/{mkd.vim => markdown.vim} (100%) rename indent/{mkd.vim => markdown.vim} (90%) create mode 100644 registry/markdown.yaml delete mode 100644 registry/mkd.yaml rename syntax/{mkd.vim => markdown.vim} (100%) diff --git a/Makefile b/Makefile index a39492a..d929849 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ all: install: mkdir -pv ${ADDONS}/ftdetect - cp -v ftdetect/mkd.vim ${ADDONS}/ftdetect/mkd.vim + cp -v ftdetect/markdown.vim ${ADDONS}/ftdetect/markdown.vim mkdir -pv ${ADDONS}/ftplugin - cp -v ftplugin/mkd.vim ${ADDONS}/ftplugin/mkd.vim + cp -v ftplugin/markdown.vim ${ADDONS}/ftplugin/markdown.vim mkdir -pv ${ADDONS}/syntax - cp -v syntax/mkd.vim ${ADDONS}/syntax/mkd.vim + cp -v syntax/markdown.vim ${ADDONS}/syntax/markdown.vim mkdir -pv ${ADDONS}/after/ftplugin - cp -v after/ftplugin/mkd.vim ${ADDONS}/after/ftplugin/mkd.vim + cp -v after/ftplugin/markdown.vim ${ADDONS}/after/ftplugin/markdown.vim mkdir -pv ${REGISTRY} - cp -v registry/mkd.yaml ${REGISTRY}/mkd.yaml + cp -v registry/markdown.yaml ${REGISTRY}/markdown.yaml diff --git a/README.md b/README.md index a5bdbbe..5ddf6ed 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ To install without Pathogen using the Debian [vim-addon-manager](http://packages git clone https://github.com/plasticboy/vim-markdown.git cd vim-markdown sudo make install -vim-addon-manager install mkd +vim-addon-manager install markdown ``` If you are not using any package manager, download the [tarball](https://github.com/plasticboy/vim-markdown/archive/master.tar.gz) and do this: diff --git a/after/ftplugin/mkd.vim b/after/ftplugin/markdown.vim similarity index 100% rename from after/ftplugin/mkd.vim rename to after/ftplugin/markdown.vim diff --git a/ftdetect/mkd.vim b/ftdetect/markdown.vim similarity index 100% rename from ftdetect/mkd.vim rename to ftdetect/markdown.vim diff --git a/ftplugin/mkd.vim b/ftplugin/markdown.vim similarity index 100% rename from ftplugin/mkd.vim rename to ftplugin/markdown.vim diff --git a/indent/mkd.vim b/indent/markdown.vim similarity index 90% rename from indent/mkd.vim rename to indent/markdown.vim index 68e385a..fb8d95d 100755 --- a/indent/mkd.vim +++ b/indent/markdown.vim @@ -1,12 +1,12 @@ if exists("b:did_indent") | finish | endif let b:did_indent = 1 -setlocal indentexpr=GetMkdIndent() +setlocal indentexpr=GetMarkdownIndent() setlocal nolisp setlocal autoindent " Only define the function once -if exists("*GetMkdIndent") | finish | endif +if exists("*GetMarkdownIndent") | finish | endif function! s:is_li_start(line) return a:line !~ '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' && @@ -25,7 +25,7 @@ function! s:prevnonblank(lnum) return i endfunction -function GetMkdIndent() +function GetMarkdownIndent() let list_ind = 4 " Find a non-blank line above the current line. let lnum = prevnonblank(v:lnum - 1) diff --git a/registry/markdown.yaml b/registry/markdown.yaml new file mode 100644 index 0000000..63648a3 --- /dev/null +++ b/registry/markdown.yaml @@ -0,0 +1,7 @@ +addon: markdown +description: "Markdown syntax highlighting" +files: + - ftdetect/markdown.vim + - ftplugin/markdown.vim + - syntax/markdown.vim + - after/ftplugin/markdown.vim diff --git a/registry/mkd.yaml b/registry/mkd.yaml deleted file mode 100644 index d0ea467..0000000 --- a/registry/mkd.yaml +++ /dev/null @@ -1,7 +0,0 @@ -addon: mkd -description: "Markdown syntax highlighting" -files: - - ftdetect/mkd.vim - - ftplugin/mkd.vim - - syntax/mkd.vim - - after/ftplugin/mkd.vim diff --git a/syntax/mkd.vim b/syntax/markdown.vim similarity index 100% rename from syntax/mkd.vim rename to syntax/markdown.vim diff --git a/test/map.vader b/test/map.vader index ea96182..e6d2dff 100644 --- a/test/map.vader +++ b/test/map.vader @@ -1,46 +1,46 @@ -Given mkd; +Given markdown; a c Execute (gx autolink): let b:url = 'http://b' let b:line = getline(1) - let b:func = Markdown_GetFunc('vim-markdown/ftplugin/mkd.vim', 'Markdown_GetUrlForPosition') + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'Markdown_GetUrlForPosition') AssertEqual b:func(1, match(b:line, 'a') + 1), '' AssertEqual b:func(1, match(b:line, '<') + 1), b:url AssertEqual b:func(1, match(b:line, 'h') + 1), b:url AssertEqual b:func(1, match(b:line, '>') + 1), b:url AssertEqual b:func(1, match(b:line, 'c') + 1), '' -Given mkd; +Given markdown; a http://b.bb c Execute (gx implicit autolink): let b:url = 'http://b.bb' let b:line = getline(1) - let b:func = Markdown_GetFunc('vim-markdown/ftplugin/mkd.vim', 'Markdown_GetUrlForPosition') + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'Markdown_GetUrlForPosition') AssertEqual b:func(1, match(b:line, 'a') + 1), '' AssertEqual b:func(1, match(b:line, 'h') + 1), b:url AssertEqual b:func(1, match(b:line, 'c') + 1), '' -Given mkd; +Given markdown; [a]: http://b "c" Execute (gx link reference definition): let b:url = 'http://b' let b:line = getline(1) - let b:func = Markdown_GetFunc('vim-markdown/ftplugin/mkd.vim', 'Markdown_GetUrlForPosition') + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'Markdown_GetUrlForPosition') " TODO would be cool if all of the following gave the link. AssertEqual b:func(1, match(b:line, 'a') + 1), '' AssertEqual b:func(1, match(b:line, 'h') + 1), b:url AssertEqual b:func(1, match(b:line, 'c') + 1), '' -Given mkd; +Given markdown; a [b](c) d Execute (gx autolink): let b:url = 'c' let b:line = getline(1) - let b:func = Markdown_GetFunc('vim-markdown/ftplugin/mkd.vim', 'Markdown_GetUrlForPosition') + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'Markdown_GetUrlForPosition') AssertEqual b:func(1, match(b:line, 'a') + 1), '' AssertEqual b:func(1, match(b:line, '[') + 1), b:url AssertEqual b:func(1, match(b:line, 'b') + 1), b:url @@ -50,7 +50,7 @@ Execute (gx autolink): AssertEqual b:func(1, match(b:line, ')') + 1), b:url AssertEqual b:func(1, match(b:line, 'd') + 1), '' -Given mkd; +Given markdown; # a b @@ -66,7 +66,7 @@ Execute (]] same level): normal [[ AssertEqual line('.'), 1 -Given mkd; +Given markdown; # a b @@ -82,7 +82,7 @@ Execute (]] different levels level): normal [[ AssertEqual line('.'), 1 -Given mkd; +Given markdown; # a b @@ -102,7 +102,7 @@ Execute (][ different levels level): normal [] AssertEqual line('.'), 1 -Given mkd; +Given markdown; # a b @@ -113,7 +113,7 @@ Execute (]c): normal ]c AssertEqual line('.'), 1 -Given mkd; +Given markdown; # a Execute (Toc does not set nomodifiable on other files): diff --git a/test/syntax.vader b/test/syntax.vader index c3dc02d..bb9ef2f 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -1,4 +1,4 @@ -Given mkd; +Given markdown; a **b** c Execute (bold): @@ -6,7 +6,7 @@ Execute (bold): AssertEqual SyntaxOf('b'), 'htmlBold' AssertNotEqual SyntaxOf('c'), 'htmlBold' -Given mkd; +Given markdown; a *b* c Execute (italic): @@ -16,14 +16,14 @@ Execute (italic): # Links -Given mkd; +Given markdown; [a](b) Execute (link with title): AssertEqual SyntaxOf('a'), 'mkdLink' AssertEqual SyntaxOf('b'), 'mkdURL' -Given mkd; +Given markdown; (a) (b) @@ -32,7 +32,7 @@ Execute (parenthesis not in link): AssertNotEqual SyntaxOf('a'), 'mkdURL' AssertNotEqual SyntaxOf('b'), 'mkdURL' -Given mkd; +Given markdown; [a](b) c [d](e) Execute (multiple links on a line): @@ -40,7 +40,7 @@ Execute (multiple links on a line): # Autolinks -Given mkd; +Given markdown; a c Execute (autolink): @@ -50,25 +50,25 @@ Execute (autolink): AssertEqual SyntaxOf('>'), 'mkdDelimiter' AssertNotEqual SyntaxOf('c'), 'mkdInlineURL' -Given mkd; +Given markdown; Execute (autolink with scheme case is insensitive): AssertEqual SyntaxOf('a'), 'mkdInlineURL' -Given mkd; +Given markdown; Execute (autolink without known scheme is not a link): AssertNotEqual SyntaxOf('n'), 'mkdInlineURL' -Given mkd; +Given markdown; Execute (autolink without scheme is not a link): AssertNotEqual SyntaxOf('a'), 'mkdInlineURL' -Given mkd; +Given markdown; < http://a > Execute (autolinks can be backslash escaped): @@ -89,7 +89,7 @@ Execute (autolinks can be backslash escaped): # Code Blocks -Given mkd; +Given markdown; ~~~ code ~~~ @@ -97,7 +97,7 @@ code Execute (code blocks can be fenced with tildes): AssertEqual SyntaxOf('c'), 'mkdCode' -Given mkd; +Given markdown; ~~~ruby code ~~~ @@ -107,7 +107,7 @@ Execute (code blocks can have a language specifier): # Math -Given mkd; +Given markdown; a $x$ b c $$y$$ d \$e\$ @@ -131,7 +131,7 @@ Execute (math): AssertNotEqual SyntaxOf('x'), 'mkdMath' AssertNotEqual SyntaxOf('y'), 'mkdMath' -Given mkd; +Given markdown; a $ @@ -149,7 +149,7 @@ Execute (multiline math): # YAML frontmatter -Given mkd; +Given markdown; --- a: b --- @@ -163,7 +163,7 @@ Execute (YAML frontmatter is controlled by the option): syn off | syn on AssertNotEqual SyntaxOf('a'), 'yamlBlockMappingKey' -Given mkd; +Given markdown; --- a: b @@ -174,7 +174,7 @@ Execute (YAML frontmatter only works if it's the first thing in the file): syn off | syn on AssertNotEqual SyntaxOf('a'), 'yamlBlockMappingKey' -Given mkd; +Given markdown; --- a: b --- -- 2.39.2 From 45e9f308082ce98a8a429f21e09e03918a9d4403 Mon Sep 17 00:00:00 2001 From: Eugene Yunak Date: Sun, 4 Oct 2015 03:22:10 +0300 Subject: [PATCH 14/16] add new indent part of the plugin to the registry --- registry/markdown.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/registry/markdown.yaml b/registry/markdown.yaml index 63648a3..00c6b9f 100644 --- a/registry/markdown.yaml +++ b/registry/markdown.yaml @@ -5,3 +5,4 @@ files: - ftplugin/markdown.vim - syntax/markdown.vim - after/ftplugin/markdown.vim + - indent/markdown.vim -- 2.39.2 From 0ef08f71f6325e24ede2195f83c6d5fd02bb6a8d Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 6 Oct 2015 13:26:05 +0200 Subject: [PATCH 15/16] Use just markdown as filetype. . for multiple filetypes does not work with autocmd. There seems to be no known workaround: http://vi.stackexchange.com/questions/4893 This is a breaking change as it would break user scripts who used autocmd, but we have already broken them with this compound filetype, so let's just finish the job. Semi-reverses: https://github.com/plasticboy/vim-markdown/pull/217 --- ftdetect/markdown.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftdetect/markdown.vim b/ftdetect/markdown.vim index fab3ab0..611ecaa 100644 --- a/ftdetect/markdown.vim +++ b/ftdetect/markdown.vim @@ -1,3 +1,3 @@ " markdown filetype file -au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=mkd.markdown -au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} set filetype=mkd.markdown +au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=markdown +au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} set filetype=markdown -- 2.39.2 From 642730fccce7e78c995389f3c430747d266efa96 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Mon, 16 Nov 2015 15:43:39 +0900 Subject: [PATCH 16/16] Fix indent with syntax off Move indent related settings from syntax to index. Fix #126 --- indent/markdown.vim | 10 ++++++++++ syntax/markdown.vim | 10 ---------- test/indent.vader | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 test/indent.vader diff --git a/indent/markdown.vim b/indent/markdown.vim index fb8d95d..23944f2 100755 --- a/indent/markdown.vim +++ b/indent/markdown.vim @@ -5,6 +5,16 @@ setlocal indentexpr=GetMarkdownIndent() setlocal nolisp setlocal autoindent +" Automatically insert bullets +setlocal formatoptions+=r +" Do not automatically insert bullets when auto-wrapping with text-width +setlocal formatoptions-=c +" Accept various markers as bullets +setlocal comments=b:*,b:+,b:- + +" Automatically continue blockquote on line break +setlocal comments+=b:> + " Only define the function once if exists("*GetMarkdownIndent") | finish | endif diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 60a675d..bacb5a1 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -130,16 +130,6 @@ HtmlHiLink mkdLinkTitle htmlString HtmlHiLink mkdMath Statement HtmlHiLink mkdDelimiter Delimiter -" Automatically insert bullets -setlocal formatoptions+=r -" Do not automatically insert bullets when auto-wrapping with text-width -setlocal formatoptions-=c -" Accept various markers as bullets -setlocal comments=b:*,b:+,b:- - -" Automatically continue blockquote on line break -setlocal comments+=b:> - let b:current_syntax = "mkd" delcommand HtmlHiLink diff --git a/test/indent.vader b/test/indent.vader new file mode 100644 index 0000000..76f4990 --- /dev/null +++ b/test/indent.vader @@ -0,0 +1,24 @@ +Given markdown; +* item1 + +Do (Insert enter at list end): + A\item2 + +Expect (auto insert * and indent level is same): + * item1 + * item2 + +Given markdown; + +Execute: + syntax off + +Do (Insert enter at list end with syntax off): + i* item1\item2 + +Expect (auto insert * and indent level is same): + * item1 + * item2 + +Execute: + syntax on -- 2.39.2