]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge pull request #312 from memeplex/namedanchor
authorHiroshi Shirosaki <h.shirosaki@gmail.com>
Fri, 15 Dec 2017 04:31:17 +0000 (13:31 +0900)
committerGitHub <noreply@github.com>
Fri, 15 Dec 2017 04:31:17 +0000 (13:31 +0900)
Follow named anchors with ge

README.md
after/ftplugin/markdown.vim
doc/vim-markdown.txt
syntax/markdown.vim
test/folding.vader
test/ge_test.md [new file with mode: 0644]
test/map.vader
test/syntax.vader

index e01ccc32b85443541451d7d603c17effb840131a..ca7eef2be70a10bf9e7d5d2f55fa950fe8e62d35 100644 (file)
--- a/README.md
+++ b/README.md
@@ -150,6 +150,13 @@ To disable conceal regardless of `conceallevel` setting, add the following to yo
 let g:vim_markdown_conceal = 0
 ```
 
+To disable math conceal with LaTeX math syntax enabled, add the following to your `.vimrc`:
+
+```vim
+let g:tex_conceal = ""
+let g:vim_markdown_math = 1
+```
+
 ### Fenced code block languages
 
 You can use filetype name as fenced code block languages for syntax highlighting.
@@ -261,7 +268,7 @@ let g:vim_markdown_new_list_item_indent = 2
 
 ### Do not require .md extensions for Markdown links
 
-If you want to have a link like this `[link text](link-url)` and follow it for editing in vim using the "ge" command, but have it open the file "link-url.md" instead of the file "link-url", then use this option:
+If you want to have a link like this `[link text](link-url)` and follow it for editing in vim using the `ge` command, but have it open the file "link-url.md" instead of the file "link-url", then use this option:
 
 ```vim
 let g:vim_markdown_no_extensions_in_markdown = 1
@@ -272,7 +279,7 @@ Normal behaviour would be that vim-markup required you to do this `[link text](l
 
 ### Auto-write when following link
 
-If you follow a link like this `[link text](link-url)` using the "ge" shortcut, this option will automatically save any edits you made before moving you:
+If you follow a link like this `[link text](link-url)` using the `ge` shortcut, this option will automatically save any edits you made before moving you:
 
 ```vim
 let g:vim_markdown_autowrite = 1
index cdf0a2654a40c037287d0cf3f57ff6d34d7902fb..9ee01006960b118c1a82ddec0958b047496e54db 100644 (file)
@@ -125,7 +125,11 @@ else
         if l1 =~ '^#' && !s:is_mkdCode(a:lnum)
             " fold level according to option
             if s:vim_markdown_folding_level == 1 || matchend(l1, '^#\+') > s:vim_markdown_folding_level
-                return -1
+                if a:lnum == line('$')
+                    return matchend(l1, '^#\+') - 1
+                else
+                    return -1
+                endif
             else
                 " headers are not folded
                 return 0
@@ -133,7 +137,7 @@ else
         endif
 
         if l0 =~ '^#' && !s:is_mkdCode(a:lnum-1)
-            " current line starts with hashes
+            " previous line starts with hashes
             return '>'.matchend(l0, '^#\+')
         else
             " keep previous foldlevel
index 3ee30e6324e69adf1cba9b4ee97ae6f25ff6b025..c6d579e7cc07b9354149411a4ce388d64e2593bf 100644 (file)
@@ -21,6 +21,10 @@ Contents ~
    3. TOML Front Matter                        |vim-markdown-toml-front-matter|
    4. JSON Front Matter                        |vim-markdown-json-front-matter|
   10. Adjust new list item indent    |vim-markdown-adjust-new-list-item-indent|
+  11. Do not require .md extensions for Markdown links
+                |vim-markdown-do-not-require-.md-extensions-for-markdown-links|
+  12. Auto-write when following link
+                                  |vim-markdown-auto-write-when-following-link|
  4. Mappings                                            |vim-markdown-mappings|
  5. Commands                                            |vim-markdown-commands|
  6. Credits                                              |vim-markdown-credits|
@@ -96,10 +100,10 @@ To fold in a style like python-mode [6], add the following to your '.vimrc':
 Level 1 heading which is served as a document title is not folded.
 'g:vim_markdown_folding_level' setting is not active with this fold style.
 
-To prevent foldtext from being overridden, add the following to your '.vimrc':
-
+To prevent foldtext from being set add the following to your '.vimrc':
+>
   let g:vim_markdown_override_foldtext = 0
-
+<
 -------------------------------------------------------------------------------
                                         *vim-markdown-set-header-folding-level*
 Set header folding level ~
@@ -149,10 +153,10 @@ Syntax Concealing ~
 
 Concealing is set for some syntax.
 
-For example, conceal '[link text](link url)' as just 'link text'.
-Also, '_italic_' and '*italic*' will conceal to just 'italic'.
-Similarly '__bold__', '**bold**', '___italic bold___', and '***italic bold***'
-will conceal to 'bold', 'bold', 'italic bold', and 'italic bold' respectively.
+For example, conceal '[link text](link url)' as just 'link text'. Also,
+'_italic_' and '*italic*' will conceal to just _italic_. Similarly '__bold__',
+'**bold**', '___italic bold___', and '***italic bold***' will conceal to just
+**bold**, **bold**, **_italic bold_**, and **_italic bold_** respectively.
 
 To enable conceal use Vim's standard conceal configuration.
 >
@@ -163,6 +167,12 @@ your '.vimrc':
 >
   let g:vim_markdown_conceal = 0
 <
+To disable math conceal with LaTeX math syntax enabled, add the following to
+your '.vimrc':
+>
+  let g:tex_conceal = ""
+  let g:vim_markdown_math = 1
+<
 -------------------------------------------------------------------------------
                                      *vim-markdown-fenced-code-block-languages*
 Fenced code block languages ~
@@ -244,6 +254,31 @@ of indent is 4. If you'd like to change the number as 2, just write:
 >
   let g:vim_markdown_new_list_item_indent = 2
 <
+-------------------------------------------------------------------------------
+                *vim-markdown-do-not-require-.md-extensions-for-markdown-links*
+Do not require .md extensions for Markdown links ~
+
+If you want to have a link like this '[link text](link-url)' and follow it for
+editing in vim using the 'ge' command, but have it open the file "link-url.md"
+instead of the file "link-url", then use this option:
+>
+  let g:vim_markdown_no_extensions_in_markdown = 1
+<
+This is super useful for GitLab and GitHub wiki repositories.
+
+Normal behaviour would be that vim-markup required you to do this '[link text
+](link-url.md)', but this is not how the Gitlab and GitHub wiki repositories
+work. So this option adds some consistency between the two.
+
+-------------------------------------------------------------------------------
+                                  *vim-markdown-auto-write-when-following-link*
+Auto-write when following link ~
+
+If you follow a link like this '[link text](link-url)' using the 'ge' shortcut,
+this option will automatically save any edits you made before moving you:
+>
+  let g:vim_markdown_autowrite = 1
+<
 ===============================================================================
                                                         *vim-markdown-mappings*
 Mappings ~
index 4602d66e4ab92abda93bc1f5e5075f3630a208ff..43cb8988e2265a1060856958ecc7b6db90cf62f0 100644 (file)
@@ -61,7 +61,7 @@ execute 'syn region htmlBoldItalic matchgroup=mkdBoldItalic start="\%(^\|\s\)\zs
 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^"    end="\]"
 execute 'syn region mkdID matchgroup=mkdDelimiter    start="\["    end="\]" contained oneline' . s:conceal
 execute 'syn region mkdURL matchgroup=mkdDelimiter   start="("     end=")"  contained oneline' . s:conceal
-execute 'syn region mkdLink matchgroup=mkdDelimiter  start="\\\@<!!\?\[" end="\n\{-,1}[^]]\{-}\zs\]\ze[[(]" contains=@mkdNonListItem,@Spell nextgroup=mkdURL,mkdID skipwhite oneline' . s:concealends
+execute 'syn region mkdLink matchgroup=mkdDelimiter  start="\\\@<!!\?\[\ze[^]\n]*\n\?[^]\n]*\][[(]" end="\]" contains=@mkdNonListItem,@Spell nextgroup=mkdURL,mkdID skipwhite' . s:concealends
 
 " Autolink without angle brackets.
 " mkd  inline links:      protocol     optional  user:pass@  sub/domain                    .com, .co.uk, etc         optional port   path/querystring/hash fragment
@@ -75,7 +75,7 @@ syn region  mkdInlineURL matchgroup=mkdDelimiter start="(\(https\?:\/\/\(\w\+\(:
 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\ze[a-z][a-z0-9,.-]\{1,22}:\/\/[^> ]*>" end=">"
 
 " Link definitions: [id]: URL (Optional Title)
-syn region mkdLinkDef matchgroup=mkdDelimiter   start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
+syn region mkdLinkDef matchgroup=mkdDelimiter   start="^ \{,3}\zs\[\^\@!" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]"   contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+     end=+"+  contained
 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+     end=+'+  contained
@@ -143,8 +143,8 @@ endif
 
 if get(g:, 'vim_markdown_math', 0)
   syn include @tex syntax/tex.vim
-  syn region mkdMath start="\\\@<!\$" end="\$" contains=@tex keepend
-  syn region mkdMath start="\\\@<!\$\$" end="\$\$" contains=@tex keepend
+  syn region mkdMath start="\\\@<!\$" end="\$" skip="\\\$" contains=@tex keepend
+  syn region mkdMath start="\\\@<!\$\$" end="\$\$" skip="\\\$" contains=@tex keepend
 endif
 
 syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
index adcae5f9b26b165f5f1ace12962785686706cea7..ecf5f9bf2865b7596afa960d8e527bafe9f54ad2 100644 (file)
@@ -36,3 +36,18 @@ Fold Level 2
 Execute (fold level ==, --):
   AssertEqual foldlevel(2), 1, '=='
   AssertEqual foldlevel(4), 2, '--'
+
+Given markdown;
+# H1
+
+## H1.1
+
+## H1.2
+
+# H2
+
+Execute (fold level # in last line):
+  AssertEqual foldlevel(1), 0, '# H1'
+  AssertEqual foldlevel(3), 1, '## H1.1'
+  AssertEqual foldlevel(5), 1, '## H1.2'
+  AssertEqual foldlevel(7), 0, '# H2'
diff --git a/test/ge_test.md b/test/ge_test.md
new file mode 100644 (file)
index 0000000..0f5e100
--- /dev/null
@@ -0,0 +1 @@
+ge test
index 92947f5972a8254c4d485efc5b5daa58521c5c64..7ecdfad188da56b79695f9cf04583ef8f2506aa7 100644 (file)
@@ -50,6 +50,45 @@ Execute (gx autolink):
   AssertEqual b:func(1, match(b:line, ')') + 1), b:url
   AssertEqual b:func(1, match(b:line, 'd') + 1), ''
 
+Given markdown;
+[ge_test.md](ge_test.md)
+
+Execute (ge opens file):
+  normal ge
+  AssertEqual @%, 'ge_test.md'
+  AssertEqual getline(1), 'ge test'
+
+Given markdown;
+[ge_test](ge_test)
+
+Execute (ge opens file without .md extensions):
+  let g:vim_markdown_no_extensions_in_markdown = 1
+  normal ge
+  AssertEqual @%, 'ge_test.md'
+  AssertEqual getline(1), 'ge test'
+  unlet g:vim_markdown_no_extensions_in_markdown
+
+Given markdown;
+[ge_test.md](ge_test.md)
+
+Execute (ge does not write before opening file):
+  normal ia
+  normal l
+  normal ge
+  AssertEqual @%, 'ge_test.md'
+  AssertEqual getline(1), 'ge test'
+
+Given markdown;
+[ge_test.md](ge_test.md)
+
+Execute (ge auto-write before opening file):
+  let g:vim_markdown_autowrite = 1
+  normal ia
+  normal l
+  AssertThrows normal ge
+  AssertEqual g:vader_exception, 'Vim(write):E382: Cannot write, ''buftype'' option is set'
+  unlet g:vim_markdown_autowrite
+
 Given markdown;
 # a
 
index b08a9a068995de7e036b682cc4d1ad028a84a20b..05401551077f2d5a37a84f8eac242e750a3882e9 100644 (file)
@@ -413,6 +413,21 @@ Execute (link text with newline):
   AssertEqual SyntaxOf('b'), 'mkdLink'
   AssertEqual SyntaxOf('c'), 'mkdURL'
 
+Given markdown;
+[a] b [c](d)
+
+Execute (link text with bracket sections):
+  AssertNotEqual SyntaxOf('a'), 'mkdLink'
+  AssertNotEqual SyntaxOf('b'), 'mkdLink'
+  AssertEqual SyntaxOf('c'), 'mkdLink'
+  AssertEqual SyntaxOf('d'), 'mkdURL'
+
+Given markdown;
+[^a]: b
+
+Execute (footnote is not link):
+  AssertNotEqual SyntaxOf('a'), 'mkdLinkDef'
+
 Given markdown;
 (a)