| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  | " Vim indent file | 
					
						
							|  |  |  | " Language:	J | 
					
						
							|  |  |  | " Maintainer:	David Bürgin <676c7473@gmail.com> | 
					
						
							| 
									
										
										
										
											2014-03-22 21:02:50 +01:00
										 |  |  | " URL:		https://github.com/glts/vim-j | 
					
						
							| 
									
										
										
										
											2015-01-14 19:42:21 +01:00
										 |  |  | " Last Change:	2015-01-11 | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-22 21:02:50 +01:00
										 |  |  | if exists('b:did_indent') | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | let b:did_indent = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | setlocal indentexpr=GetJIndent() | 
					
						
							| 
									
										
										
										
											2014-04-06 14:09:13 +02:00
										 |  |  | setlocal indentkeys-=0{,0},:,0# | 
					
						
							|  |  |  | setlocal indentkeys+=0),0<:>,=case.,=catch.,=catchd.,=catcht.,=do.,=else.,=elseif.,=end.,=fcase. | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-22 21:02:50 +01:00
										 |  |  | let b:undo_indent = 'setlocal indentkeys< indentexpr<' | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-22 21:02:50 +01:00
										 |  |  | if exists('*GetJIndent') | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-06 14:09:13 +02:00
										 |  |  | " If g:j_indent_definitions is true, the bodies of explicit definitions of | 
					
						
							|  |  |  | " adverbs, conjunctions, and verbs will be indented. Default is false (0). | 
					
						
							|  |  |  | if !exists('g:j_indent_definitions') | 
					
						
							|  |  |  |   let g:j_indent_definitions = 0 | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function GetJIndent() abort | 
					
						
							| 
									
										
										
										
											2015-01-14 19:42:21 +01:00
										 |  |  |   let l:prevlnum = prevnonblank(v:lnum - 1) | 
					
						
							|  |  |  |   if l:prevlnum == 0 | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  |     return 0 | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2015-01-14 19:42:21 +01:00
										 |  |  |   let l:indent = indent(l:prevlnum) | 
					
						
							|  |  |  |   let l:prevline = getline(l:prevlnum) | 
					
						
							|  |  |  |   if l:prevline =~# '^\s*\%(case\|catch[dt]\=\|do\|else\%(if\)\=\|fcase\|for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.\%(\%(\<end\.\)\@!.\)*$' | 
					
						
							| 
									
										
										
										
											2014-04-06 14:09:13 +02:00
										 |  |  |     " Increase indentation after an initial control word that starts or | 
					
						
							|  |  |  |     " continues a block and is not terminated by "end." | 
					
						
							| 
									
										
										
										
											2015-01-14 19:42:21 +01:00
										 |  |  |     let l:indent += shiftwidth() | 
					
						
							|  |  |  |   elseif g:j_indent_definitions && (l:prevline =~# '\<\%([1-4]\|13\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\>' || l:prevline =~# '^\s*:\s*$') | 
					
						
							| 
									
										
										
										
											2014-04-06 14:09:13 +02:00
										 |  |  |     " Increase indentation in explicit definitions of adverbs, conjunctions, | 
					
						
							|  |  |  |     " and verbs | 
					
						
							| 
									
										
										
										
											2015-01-14 19:42:21 +01:00
										 |  |  |     let l:indent += shiftwidth() | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2014-04-06 14:09:13 +02:00
										 |  |  |   " Decrease indentation in lines that start with either control words that | 
					
						
							|  |  |  |   " continue or end a block, or the special items ")" and ":" | 
					
						
							|  |  |  |   if getline(v:lnum) =~# '^\s*\%()\|:\|\%(case\|catch[dt]\=\|do\|else\%(if\)\=\|end\|fcase\)\.\)' | 
					
						
							| 
									
										
										
										
											2015-01-14 19:42:21 +01:00
										 |  |  |     let l:indent -= shiftwidth() | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2015-01-14 19:42:21 +01:00
										 |  |  |   return l:indent | 
					
						
							| 
									
										
										
										
											2013-09-22 14:42:24 +02:00
										 |  |  | endfunction |