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.
1 "TODO print messages when on visual mode. I only see VISUAL, not the messages.
3 "this is how you should view things:
30 let s:headerExpr = '\v^#'
33 fu! b:Markdown_GetLineNumCurHeader()
34 retu search( s:headerExpr, 'bcnW' )
37 "- if inside a header goes to it
39 "- if on top level outside any headers,
42 fu! b:Markdown_GoCurHeaderGetHashes()
43 let l:lineNum = b:Markdown_GetLineNumCurHeader()
45 cal cursor( l:lineNum, 1 )
46 retu matchstr( getline( lineNum ), '\v^#+' )
52 "- if inside a header goes to it
53 " returns its line number
54 "- if on top level outside any headers,
57 fu! b:Markdown_GoCurHeader()
58 let l:lineNum = b:Markdown_GetLineNumCurHeader()
60 cal cursor( l:lineNum, 1 )
62 ec 'outside any header'
68 "goes to next header of any level
70 "if no there are no more headers print a warning
71 fu! b:Markdown_GoNextHeader()
72 if search( s:headerExpr, 'W' ) == 0
78 "goes to previous header of any level
80 "if it does not exist, print a warning
81 fu! b:Markdown_GoPreviousHeader()
82 let l:oldPos = getpos('.')
83 let l:curHeaderLineNumber = b:Markdown_GoCurHeader()
84 if l:curHeaderLineNumber == 0
85 cal setpos('.',l:oldPos)
87 if search( s:headerExpr, 'bW' ) == 0
89 cal setpos('.',l:oldPos)
90 ec 'no previous header'
94 "goes to previous header of any level
96 "if it exists, return its lines number
98 "otherwise, print a warning and return 0
99 fu! b:Markdown_GoHeaderUp()
100 let l:oldPos = getpos('.')
101 let l:hashes = b:Markdown_GoCurHeaderGetHashes()
102 if len( l:hashes ) > 1
103 cal search( '^' . l:hashes[1:] . '[^#]', 'b' )
105 cal setpos('.',l:oldPos)
106 ec 'already at top level'
110 "if no more next siblings, print error message and do nothing.
111 fu! b:Markdown_GoNextSiblingHeader()
112 let l:oldPos = getpos('.')
113 let l:hashes = b:Markdown_GoCurHeaderGetHashes()
119 let l:nhashes = len(l:hashes)
121 "special case, just add the largest possible value
122 let l:nextLowerLevelLine = line('$') + 1
124 let l:nextLowerLevelLine = search( '\v^#{1,' . ( l:nhashes - 1 ) . '}[^#]' , 'nW' )
127 let l:nextSameLevelLine = search( '\v^' . l:hashes . '[^#]', 'nW' )
129 \ l:nextSameLevelLine > 0
132 \ l:nextLowerLevelLine == 0
134 \ l:nextLowerLevelLine > l:nextSameLevelLine
137 cal cursor( l:nextSameLevelLine, 1 )
144 cal setpos('.',l:oldPos)
149 "if no more next siblings, print error message and do nothing.
150 fu! b:Markdown_GoPreviousSiblingHeader()
151 let l:oldPos = getpos('.')
152 let l:hashes = b:Markdown_GoCurHeaderGetHashes()
158 let l:nhashes = len(l:hashes)
160 "special case, just add the largest possible value
161 let l:prevLowerLevelLine = -1
163 let l:prevLowerLevelLine = search( '\v^#{1,' . ( l:nhashes - 1 ) . '}[^#]' , 'bnW' )
166 let l:prevSameLevelLine = search( '\v^' . l:hashes . '[^#]', 'bnW' )
168 \ l:prevSameLevelLine > 0
171 \ l:prevLowerLevelLine == 0
173 \ l:prevLowerLevelLine < l:prevSameLevelLine
176 cal cursor( l:prevSameLevelLine, 1 )
183 cal setpos('.',l:oldPos)
184 ec 'no previous sibling'
189 "wrapper to do move commands in visual mode
195 "map in both normal and visual modes
196 fu! s:MapNormVis(rhs,lhs)
197 exe 'nn <buffer><silent> ' . a:rhs . ' :cal ' . a:lhs . '()<cr>'
198 exe 'vn <buffer><silent> ' . a:rhs . ' <esc>:cal <sid>VisMove(''' . a:lhs . ''')<cr>'
201 cal <sid>MapNormVis( ']]', 'b:Markdown_GoNextHeader' )
202 cal <sid>MapNormVis( '[[', 'b:Markdown_GoPreviousHeader' )
203 cal <sid>MapNormVis( '][', 'b:Markdown_GoNextSiblingHeader' )
204 cal <sid>MapNormVis( '[]', 'b:Markdown_GoPreviousSiblingHeader' )
206 cal <sid>MapNormVis( ']u', 'b:Markdown_GoHeaderUp' )
208 cal <sid>MapNormVis( ']c', 'b:Markdown_GoCurHeader' )