| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | " Vim ftplugin file | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | " Language:     Erlang (http://www.erlang.org) | 
					
						
							|  |  |  | " Maintainer:   Csaba Hoch <csaba.hoch@gmail.com> | 
					
						
							| 
									
										
										
										
											2020-10-26 21:12:46 +01:00
										 |  |  | " Author:       Oscar Hellström <oscar@oscarh.net> | 
					
						
							|  |  |  | " Contributors: Ricardo Catalinas Jiménez <jimenezrick@gmail.com> | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | "               Eduardo Lopez (http://github.com/tapichu) | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | "               Arvid Bjurklint (http://github.com/slarwise) | 
					
						
							| 
									
										
										
										
											2023-12-21 17:16:28 +01:00
										 |  |  | "               Paweł Zacharek (http://github.com/subc2) | 
					
						
							| 
									
										
										
										
											2024-06-03 20:40:45 +02:00
										 |  |  | "               Riley Bruins (http://github.com/ribru17) ('commentstring') | 
					
						
							|  |  |  | " Last Update:  2024 May 23 | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | " License:      Vim license | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | " URL:          https://github.com/vim-erlang/vim-erlang-runtime | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | if exists('b:did_ftplugin') | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  |   finish | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | endif | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | let b:did_ftplugin = 1 | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 15:57:40 +01:00
										 |  |  | let s:cpo_save = &cpo | 
					
						
							|  |  |  | set cpo&vim | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man') | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | if get(g:, 'erlang_folding', 0) | 
					
						
							|  |  |  |   setlocal foldmethod=expr | 
					
						
							|  |  |  |   setlocal foldexpr=GetErlangFold(v:lnum) | 
					
						
							|  |  |  |   setlocal foldtext=ErlangFoldText() | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | setlocal comments=:%%%,:%%,:% | 
					
						
							| 
									
										
										
										
											2024-06-03 20:40:45 +02:00
										 |  |  | setlocal commentstring=%\ %s | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | setlocal formatoptions+=ro | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-03 18:04:35 +01:00
										 |  |  | if get(g:, 'erlang_extend_path', 1) | 
					
						
							|  |  |  |   " typical erlang.mk paths | 
					
						
							|  |  |  |   let &l:path = join([ | 
					
						
							|  |  |  |         \ 'deps/*/include', | 
					
						
							|  |  |  |         \ 'deps/*/src', | 
					
						
							|  |  |  |         \ 'deps/*/test', | 
					
						
							|  |  |  |         \ 'deps/*/apps/*/include', | 
					
						
							|  |  |  |         \ 'deps/*/apps/*/src', | 
					
						
							|  |  |  |         \ &g:path], ',') | 
					
						
							|  |  |  |   " typical rebar3 paths | 
					
						
							|  |  |  |   let &l:path = join([ | 
					
						
							|  |  |  |         \ 'apps/*/include', | 
					
						
							|  |  |  |         \ 'apps/*/src', | 
					
						
							|  |  |  |         \ '_build/default/lib/*/src', | 
					
						
							|  |  |  |         \ '_build/default/*/include', | 
					
						
							|  |  |  |         \ &l:path], ',') | 
					
						
							|  |  |  |   " typical erlang paths | 
					
						
							|  |  |  |   let &l:path = join(['include', 'src', 'test', &l:path], ',') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   set wildignore+=*/.erlang.mk/*,*.beam | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | setlocal suffixesadd=.erl,.hrl | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")' | 
					
						
							|  |  |  | let &l:define  = '^\s*-\%(define\|record\|type\|opaque\)' | 
					
						
							| 
									
										
										
										
											2012-02-13 00:05:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 17:16:28 +01:00
										 |  |  | let s:erlang_fun_begin = '^\l[A-Za-z0-9_@]*(.*$' | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | let s:erlang_fun_end   = '^[^%]*\.\s*\(%.*\)\?$' | 
					
						
							| 
									
										
										
										
											2012-02-13 00:05:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | if !exists('*GetErlangFold') | 
					
						
							|  |  |  |   function GetErlangFold(lnum) | 
					
						
							|  |  |  |     let lnum = a:lnum | 
					
						
							|  |  |  |     let line = getline(lnum) | 
					
						
							| 
									
										
										
										
											2012-02-13 00:05:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  |     if line =~ s:erlang_fun_end | 
					
						
							|  |  |  |       return '<1' | 
					
						
							|  |  |  |     endif | 
					
						
							| 
									
										
										
										
											2012-02-13 00:05:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  |     if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1 | 
					
						
							|  |  |  |       return '1' | 
					
						
							|  |  |  |     endif | 
					
						
							| 
									
										
										
										
											2012-02-13 00:05:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  |     if line =~ s:erlang_fun_begin | 
					
						
							|  |  |  |       return '>1' | 
					
						
							|  |  |  |     endif | 
					
						
							| 
									
										
										
										
											2012-02-13 00:05:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  |     return '=' | 
					
						
							|  |  |  |   endfunction | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | if !exists('*ErlangFoldText') | 
					
						
							|  |  |  |   function ErlangFoldText() | 
					
						
							|  |  |  |     let line    = getline(v:foldstart) | 
					
						
							|  |  |  |     let foldlen = v:foldend - v:foldstart + 1 | 
					
						
							|  |  |  |     let lines   = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '') | 
					
						
							|  |  |  |     if foldlen < 10 | 
					
						
							|  |  |  |       let lines = ' ' . lines | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  |     let retval = '+' . v:folddashes . lines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return retval | 
					
						
							|  |  |  |   endfunction | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2012-03-11 15:57:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 17:16:28 +01:00
										 |  |  | " The following lines enable the macros/matchit.vim plugin for extended | 
					
						
							|  |  |  | " matching with the % key. | 
					
						
							|  |  |  | let b:match_ignorecase = 0 | 
					
						
							|  |  |  | let b:match_words = | 
					
						
							|  |  |  |   \ '\<\%(begin\|case\|fun\|if\|maybe\|receive\|try\)\>' . | 
					
						
							|  |  |  |   \ ':\<\%(after\|catch\|else\|of\)\>' . | 
					
						
							|  |  |  |   \ ':\<end\>,' . | 
					
						
							|  |  |  |   \ '^\l[A-Za-z0-9_@]*' . | 
					
						
							|  |  |  |   \ ':^\%(\%(\t\| \{' . shiftwidth() . | 
					
						
							|  |  |  |   \ '}\)\%([^\t\ %][^%]*\)\?\)\?;\s*\%(%.*\)\?$\|\.[\t\ %]\|\.$' | 
					
						
							|  |  |  | let b:match_skip = 's:comment\|string\|erlangmodifier\|erlangquotedatom' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<" | 
					
						
							|  |  |  |       \ . " comments< commentstring< formatoptions< suffixesadd< include<" | 
					
						
							|  |  |  |       \ . " define<" | 
					
						
							| 
									
										
										
										
											2023-12-21 17:16:28 +01:00
										 |  |  |       \ . " | unlet b:match_ignorecase b:match_words b:match_skip" | 
					
						
							| 
									
										
										
										
											2012-03-11 15:57:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | let &cpo = s:cpo_save | 
					
						
							|  |  |  | unlet s:cpo_save | 
					
						
							| 
									
										
										
										
											2021-01-11 19:40:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | " vim: sw=2 et |