pax_global_header00006660000000000000000000000064117516127020014514gustar00rootroot0000000000000052 comment=89111c7d054a1e40b751295e8371ced53a868d94 jimenezrick-vimerl-89111c7/000077500000000000000000000000001175161270200156015ustar00rootroot00000000000000jimenezrick-vimerl-89111c7/.gitignore000066400000000000000000000000171175161270200175670ustar00rootroot00000000000000*~ .*.swp tags jimenezrick-vimerl-89111c7/LICENSE000066400000000000000000000010741175161270200166100ustar00rootroot00000000000000Vimerl is released under Vim license (see :help license). This is the list of people who have contributed to this plugin: Copyright (C) 2007-2011 Oscar Hellström Copyright (C) 2008 Csaba Hoch Copyright (C) 2010 Martin Carlson Copyright (C) 2010 Phillip Toland Copyright (C) 2010 Jonas Ådahl Copyright (C) 2010-2011 Pawel Salata Copyright (C) 2010-2012 Ricardo Catalinas Jiménez (current maintainer) Copyright (C) 2011 Edwin Fine Copyright (C) 2011 Eduardo Lopez Copyright (C) 2011 Ryosuke Nakai Copyright (C) 2011 Per Andersson jimenezrick-vimerl-89111c7/README000066400000000000000000000021661175161270200164660ustar00rootroot00000000000000 _ ___ __ | | / (_)___ ___ ___ _____/ / | | / / / __ `__ \/ _ \/ ___/ / | |/ / / / / / / / __/ / / / |___/_/_/ /_/ /_/\___/_/ /_/ ==================================== The Erlang plugin for Vim. Features ---------- - Syntax highlighting - Code indenting - Code folding - Code omni completion - Syntax checking with quickfix support - Code skeletons for the OTP behaviours - Uses configuration from Rebar - Pathogen compatible (http://github.com/tpope/vim-pathogen) How to install it ------------------- Copy the content of the tarball to your `.vim'. Don't forget to run `:helptags' if you are not using Pathogen. Vimerl requires to have a recent version of Erlang installed in your system with `escript' in your $PATH. With a Vim version older than 7.3 syntax checking will be disabled as some required features won't be available. How to use it --------------- Start with `:help vimerl'. How to contribute or report bugs ---------------------------------- Send it to me: Ricardo Catalinas Jiménez Or use GitHub: http://github.com/jimenezrick/vimerl jimenezrick-vimerl-89111c7/autoload/000077500000000000000000000000001175161270200174115ustar00rootroot00000000000000jimenezrick-vimerl-89111c7/autoload/erlang_complete.erl000077500000000000000000000124441175161270200232650ustar00rootroot00000000000000#!/usr/bin/env escript -include_lib("xmerl/include/xmerl.hrl"). main([ModName]) -> case file:consult("rebar.config") of {ok, Terms} -> RebarLibDirs = proplists:get_value(lib_dirs, Terms, []), lists:foreach( fun(LibDir) -> code:add_pathsa(filelib:wildcard(LibDir ++ "/*/ebin")) end, RebarLibDirs), RebarDepsDir = proplists:get_value(deps_dir, Terms, "deps"), code:add_pathsa(filelib:wildcard(RebarDepsDir ++ "/*/ebin")); {error, _} -> true end, code:add_patha("ebin"), Mod = list_to_atom(ModName), Edoc = try module_edoc(Mod) catch throw:not_found -> []; error:{badmatch, _} -> []; exit:error -> [] end, Info = try module_info2(Mod) catch error:undef -> [] end, FunSpecs = merge_functions(Edoc, Info), lists:foreach(fun(Fun) -> print_function(Fun) end, FunSpecs); main(_) -> io:format("Usage: ~s ~n", [escript:script_name()]), halt(1). module_edoc(Mod) -> File = case filename:find_src(Mod) of {error, _} -> BeamFile = atom_to_list(Mod) ++ ".beam", case code:where_is_file(BeamFile) of non_existing -> throw(not_found); BeamPath -> SrcPath = beam_to_src_path(BeamPath), case filelib:is_regular(SrcPath) of true -> SrcPath; false -> throw(not_found) end end; {File0, _} -> File0 ++ ".erl" end, {_, Doc} = edoc:get_doc(File), Funs = xmerl_xpath:string("/module/functions/function", Doc), FunSpecs = map_functions(fun(Fun) -> analyze_function(Fun) end, Funs), lists:keysort(1, FunSpecs). beam_to_src_path(BeamPath) -> PathParts = filename:split(BeamPath), {Dirs, [BeamFile]} = lists:split(length(PathParts) - 1, PathParts), {Dirs2, [DirsLast]} = lists:split(length(Dirs) - 1, Dirs), case filename:pathtype(BeamPath) of absolute -> Dirs3 = case DirsLast of "ebin" -> Dirs2 ++ ["src"]; _ -> Dirs end; relative -> Dirs3 = Dirs end, filename:join(Dirs3 ++ [beam_to_src_file(BeamFile)]). beam_to_src_file(BeamFile) -> [ModName, "beam"] = string:tokens(BeamFile, "."), ModName ++ ".erl". map_functions(_, []) -> []; map_functions(F, [H | T]) -> try [F(H) | map_functions(F, T)] catch throw:no_spec -> map_functions(F, T) end. analyze_function(Fun) -> Name = list_to_atom(get_attribute(Fun, "name")), Args0 = xmerl_xpath:string("typespec/type/fun/argtypes/type", Fun), Args = lists:map(fun(Arg) -> get_attribute(Arg, "name") end, Args0), Return = analyze_return(Fun), {Name, Args, Return}. analyze_return(Fun) -> case xmerl_xpath:string("typespec/type/fun/type/*", Fun) of [Return] -> simplify_return(xmerl_lib:simplify_element(Return)); [] -> throw(no_spec) end. simplify_return({typevar, [{name, Name}], _}) -> Name; simplify_return({type, _, [Type]}) -> simplify_return(Type); simplify_return({abstype, _, [Type]}) -> {erlangName, Attrs, _} = Type, Name = proplists:get_value(name, Attrs), Name ++ "()"; simplify_return({record, _, [Type]}) -> simplify_return(Type) ++ "()"; simplify_return({nonempty_list, _, [Type]}) -> "[" ++ simplify_return(Type) ++ "]"; simplify_return({tuple, _, Types}) -> Elems = lists:map(fun(Type) -> simplify_return(Type) end, Types), "{" ++ string:join(Elems, ", ") ++ "}"; simplify_return({list, _, Types}) -> Elems = lists:map(fun(Type) -> simplify_return(Type) end, Types), "[" ++ string:join(Elems, ", ") ++ "]"; simplify_return({paren, _, Types}) -> Elems = lists:map(fun(Type) -> simplify_return(Type) end, Types), "(" ++ string:join(Elems, ", ") ++ ")"; simplify_return({union, _, Types}) -> Elems = lists:map(fun(Type) -> simplify_return(Type) end, Types), string:join(Elems, " | "); simplify_return({atom, [{value, Val}], _}) -> Val; simplify_return({nil, _, _}) -> "[]". get_attribute(Elem, AttrName) -> [Attr] = xmerl_xpath:string("@" ++ AttrName, Elem), Attr#xmlAttribute.value. module_info2(Mod) -> lists:keysort(1, Mod:module_info(exports)). merge_functions(Edoc, Info) -> merge_functions(Edoc, Info, []). merge_functions([], [], Funs) -> lists:reverse(Funs); merge_functions([], Info, Funs) -> lists:reverse(Funs, Info); merge_functions(Edoc, [], Funs) -> lists:reverse(Funs, Edoc); merge_functions(Edoc, Info, Funs) -> [H1 = {K1, _, _} | T1] = Edoc, [H2 = {K2, _} | T2] = Info, if K1 == K2 -> merge_functions(T1, T2, [H1 | Funs]); K1 < K2 -> merge_functions(T1, Info, [H1 | Funs]); K1 > K2 -> merge_functions(Edoc, T2, [H2 | Funs]) end. print_function({Name, Arity}) -> io:format("~s/~B~n", [Name, Arity]); print_function({Name, Args, Return}) -> io:format("~s(~s) -> ~s~n", [Name, string:join(Args, ", "), Return]). jimenezrick-vimerl-89111c7/autoload/erlang_complete.vim000066400000000000000000000104421175161270200232670ustar00rootroot00000000000000" Vim omni completion file " Language: Erlang " Author: Oscar Hellström " Contributors: kTT (http://github.com/kTT) " Ricardo Catalinas Jiménez " Eduardo Lopez (http://github.com/tapichu) " License: Vim license " Version: 2012/01/14 " Completion program path let s:erlang_complete_file = expand(':p:h') . '/erlang_complete.erl' if !exists('g:erlang_completion_cache') let g:erlang_completion_cache = 1 endif " Modules cache used to speed up the completion let s:modules_cache = {} " Patterns for completions let s:erlang_local_func_beg = '\(\<[0-9A-Za-z_-]*\|\s*\)$' let s:erlang_external_func_beg = '\<[0-9A-Za-z_-]\+:[0-9A-Za-z_-]*$' let s:erlang_blank_line = '^\s*\(%.*\)\?$' " Main function for completion function erlang_complete#Complete(findstart, base) let lnum = line('.') let column = col('.') let line = strpart(getline('.'), 0, column - 1) " 1) Check if the char to the left of us are part of a function call " " Nothing interesting is written at the char just before the cursor " This means _anything_ could be started here " In this case, keyword completion should probably be used, " for now we'll only try and complete local functions. " " TODO: Examine if we can stare Identifiers end complete on them " Is this worth it? Is /completion/ of a "blank" wanted? Can we consider " `(' interesting and check if we are in a function call etc.? if line[column - 2] !~ '[0-9A-Za-z:_-]' if a:findstart return column else return s:ErlangFindLocalFunc(a:base) endif endif " 2) Function in external module if line =~ s:erlang_external_func_beg let delimiter = match(line, ':[0-9A-Za-z_-]*$') + 1 if a:findstart return delimiter else let module = matchstr(line[:-2], '\<\k*\>$') return s:ErlangFindExternalFunc(module, a:base) endif endif " 3) Local function if line =~ s:erlang_local_func_beg let funcstart = match(line, ':\@ " Contributors: Ricardo Catalinas Jiménez " License: Vim license " Version: 2012/02/08 if exists("current_compiler") || v:version < 703 finish else let current_compiler = "erlang" endif let b:error_list = {} let b:is_showing_msg = 0 let b:next_sign_id = 1 if exists(":CompilerSet") != 2 command -nargs=* CompilerSet setlocal endif CompilerSet makeprg=make CompilerSet errorformat=%f:%l:\ %tarning:\ %m,%f:%l:\ %m " Only define functions and script scope variables once if exists("*s:ShowErrors") finish endif if !exists("g:erlang_show_errors") let g:erlang_show_errors = 1 endif let s:erlang_check_file = expand(":p:h") . "/erlang_check.erl" let s:autocmds_defined = 0 sign define ErlangError text=>> texthl=Error sign define ErlangWarning text=>> texthl=Todo command ErlangDisableShowErrors silent call s:DisableShowErrors() command ErlangEnableShowErrors silent call s:EnableShowErrors() function s:ShowErrors() setlocal shellpipe=> if match(getline(1), "#!.*escript") != -1 setlocal makeprg=escript\ -s\ % else execute "setlocal makeprg=" . s:erlang_check_file . "\\ \%" endif silent make! call s:ClearErrors() for error in getqflist() let item = {} let item["lnum"] = error.lnum let item["text"] = error.text let b:error_list[error.lnum] = item let type = error.type == "W" ? "ErlangWarning" : "ErlangError" execute "sign place" b:next_sign_id "line=" . item.lnum "name=" . type "file=" . expand("%:p") let b:next_sign_id += 1 endfor setlocal shellpipe& setlocal makeprg=make endfunction function s:ShowErrorMsg() let pos = getpos(".") if has_key(b:error_list, pos[1]) let item = get(b:error_list, pos[1]) echo item.text let b:is_showing_msg = 1 else if b:is_showing_msg echo let b:is_showing_msg = 0 endif endif endf function s:ClearErrors() sign unplace * let b:error_list = {} let b:next_sign_id = 1 if b:is_showing_msg echo let b:is_showing_msg = 0 endif endfunction function s:EnableShowErrors() if !s:autocmds_defined autocmd BufWritePost *.erl call s:ShowErrors() autocmd CursorHold *.erl call s:ShowErrorMsg() autocmd CursorMoved *.erl call s:ShowErrorMsg() let s:autocmds_defined = 1 endif endfunction function s:DisableShowErrors() sign unplace * autocmd! BufWritePost *.erl autocmd! CursorHold *.erl autocmd! CursorMoved *.erl let s:autocmds_defined = 0 endfunction if g:erlang_show_errors call s:EnableShowErrors() endif jimenezrick-vimerl-89111c7/compiler/erlang_check.erl000077500000000000000000000022301175161270200225240ustar00rootroot00000000000000#!/usr/bin/env escript main([File]) -> Dir = filename:dirname(File), Defs = [strong_validation, warn_export_all, warn_export_vars, warn_shadow_vars, warn_obsolete_guard, warn_unused_import, report, {i, Dir ++ "/include"}, {i, Dir ++ "/../include"}, {i, Dir ++ "/../../include"}, {i, Dir ++ "/../../../include"}], case file:consult("rebar.config") of {ok, Terms} -> RebarLibDirs = proplists:get_value(lib_dirs, Terms, []), lists:foreach( fun(LibDir) -> code:add_pathsa(filelib:wildcard(LibDir ++ "/*/ebin")) end, RebarLibDirs), RebarDepsDir = proplists:get_value(deps_dir, Terms, "deps"), code:add_pathsa(filelib:wildcard(RebarDepsDir ++ "/*/ebin")), RebarOpts = proplists:get_value(erl_opts, Terms, []); {error, _} -> RebarOpts = [] end, code:add_patha("ebin"), compile:file(File, Defs ++ RebarOpts); main(_) -> io:format("Usage: ~s ~n", [escript:script_name()]), halt(1). jimenezrick-vimerl-89111c7/doc/000077500000000000000000000000001175161270200163465ustar00rootroot00000000000000jimenezrick-vimerl-89111c7/doc/vimerl.txt000066400000000000000000000225731175161270200204160ustar00rootroot00000000000000*vimerl.txt* The Erlang plugin for Vim _ ___ __ | | / (_)___ ___ ___ _____/ / | | / / / __ `__ \/ _ \/ ___/ / | |/ / / / / / / / __/ / / / |___/_/_/ /_/ /_/\___/_/ /_/ http://github.com/jimenezrick/vimerl ============================================================================== Contents *vimerl* 1. Intro |vimerl-intro| 2. Usage |vimerl-usage| 2.1 Code indenting |vimerl-indenting| 2.2 Code folding |vimerl-folding| 2.3 Code omni completion |vimerl-omni-completion| 2.4 Syntax checking |vimerl-syntax-checking| 2.5 Code skeletons |vimerl-skeletons| 3. Commands |vimerl-commands| 4. Options |vimerl-options| 5. License |vimerl-license| ============================================================================== 1. Intro *vimerl-intro* Vimerl is a plugin for programming in Erlang. It provides several nice features to make your life easier when writing code. The plugin offers the following features: - Syntax highlighting - Code indenting - Code folding - Code omni completion - Syntax checking with |quickfix| support - Code skeletons for the OTP behaviours - Uses configuration from Rebar - Pathogen compatible (http://github.com/tpope/vim-pathogen) ============================================================================== 2. Usage *vimerl-usage* In this section it is explained how to use the features of this plugin. ------------------------------------------------------------------------------ 2.1 Code indenting *vimerl-indenting* All the code you write is automatically indented. To reindent a block of code use the |=| or |v_=| command. The code indenting feature it's implemented as an Erlang escript that helps Vim parsing code and calculating the indentation level of each line. This escript communicates with Vim through a pair of named pipes located in the "indent/" directory where Vimerl is installed or in "/tmp" if "indent/" is not writeable. It is recommended to enable the Vim option |'expandtab'|, with it the code will be indented more nicely lining up columns when possible. If Vim freezes while editing an Erlang code file, it's probably caused by a bug in the escript which crashed and Vim is waiting for it to respond. So, if that happens to you, kill Vim and reopen the file. It also would be nice to report the bug to me :-) Note: indenting a large block of lines with the |=| or |v_=| command will take some time to finish. ------------------------------------------------------------------------------ 2.2 Code folding *vimerl-folding* In order to enable/disable code folding see the |'foldenable'| Vim option and also enable the |'erlang_folding'| option. ------------------------------------------------------------------------------ 2.3 Code omni completion *vimerl-omni-completion* The omni completion may be used after writing the name of a module followed by a colon (e.g. "lists:") pressing afterwards CTRL-X CTRL-O. The omni completion can be used with functions from the OTP or from your local modules. Using omni completion not after a module name, will make it show local functions from the current module. Vimerl will use to suggest function names, EDoc and "mod:module_info/1" from the target module. Thus searching for the .beam and .erl files will be necessary. For that, the default Erlang code path will be used, including the current directory, plus "ebin/" and "src/". If your project uses Rebar, Vimerl will search the value of "deps_dir" in "rebar.config", with "deps/" as default, to also let you use omni completion on dependency modules. Note: the user is responsible for having compiled his project so that Vimerl finds the .beam files. Note: it is recommended to start Vim on the project's root directory, which should have the standard directory structure for an OTP application. ------------------------------------------------------------------------------ 2.4 Syntax checking with quickfix support *vimerl-syntax-checking* When syntax checking is enabled, whenever the file is written, it is checked for syntax errors using the Erlang compiler. The error message of the current line is shown at the bottom. |signs| are used to indicate lines with errors and warnings. Vimerl will search for your modules source code in the current directory and "src/". It also will use "include/" directory for the headers. If your project uses Rebar, Vimerl will search the value of "erl_opts" in "rebar.config" to know how to compile your modules. You can also use the |quickfix| commands to navigate through the errors list. Note: look in the commands section how to enable/disable the syntax checking. ------------------------------------------------------------------------------ 2.5 Code skeletons *vimerl-skeletons* It is possible to load a code skeleton for one of the OTP behaviours. Note: look in the commands section how to load a skeleton. ============================================================================== 3. Commands *vimerl-commands* *:ErlangEnableShowErrors* Enables syntax checking: > :ErlangEnableShowErrors < *:ErlangDisableShowErrors* Disables syntax checking and hides current errors: > :ErlangDisableShowErrors < *:ErlangApplication* Loads an OTP application skeleton: > :ErlangApplication < *:ErlangSupervisor* Loads an OTP supervisor skeleton: > :ErlangSupervisor < *:ErlangGenServer* Loads an OTP gen_server skeleton: > :ErlangGenServer < *:ErlangGenFsm* Loads an OTP gen_fsm skeleton: > :ErlangGenFsm < *:ErlangGenEvent* Loads an OTP gen_event skeleton: > :ErlangGenEvent Note: all the previous commands are applied to the current buffer. ============================================================================== 4. Options *vimerl-options* The following options offer the possibility to customize the plugin behaviour. ------------------------------------------------------------------------------ *'erlang_folding'* This option controls whether automatic code folding is enabled or disabled (default: 0, values: 0 or 1): > :let erlang_folding = 0 ------------------------------------------------------------------------------ *'erlang_highlight_bif'* This option controls whether BIF functions are highlighted as keywords including functions from the erlang module (default: 1, values: 0 or 1): > :let erlang_highlight_bif = 1 ------------------------------------------------------------------------------ *'erlang_skel_replace'* This option controls whether loading a code skeleton implies replacing the content of the current buffer (default: 1, values: 0 or 1): > :let erlang_skel_replace = 1 ------------------------------------------------------------------------------ *'erlang_skel_header'* This option defines the information used to fill the skeleton header. If this variable is not defined, then the header is not included (default: undefined, values: dictionary): > :let erlang_skel_header = {"author": "Foo Bar", "owner" : "Fubar", "year" : "2000"} Note: the "year" key may be omitted, in that case the current year is used. ------------------------------------------------------------------------------ *'erlang_keywordprg'* This option defines the command used to show man pages with the |K| command (default: "erl -man", values: string): > :let erlang_keywordprg = "erl -man" ------------------------------------------------------------------------------ *'erlang_show_errors'* This option controls if the syntax checking is enabled or disabled (default: 1, values: 0 or 1): > :let erlang_show_errors = 1 ------------------------------------------------------------------------------ *'erlang_completion_cache'* This option controls if the omni completion uses a cache to speed up the process (default: 1, values: 0 or 1): > :let erlang_completion_cache = 1 Note: it could be useful to disable this cache in order to get always fresh info whenever a module is recompiled. ============================================================================== 5. License *vimerl-license* Vimerl is released under Vim |license|. Several people have contributed to this plugin (see LICENSE file). vim: tw=78 ts=8 ft=help jimenezrick-vimerl-89111c7/ftplugin/000077500000000000000000000000001175161270200174315ustar00rootroot00000000000000jimenezrick-vimerl-89111c7/ftplugin/erlang.vim000066400000000000000000000032601175161270200214170ustar00rootroot00000000000000" Vim ftplugin file " Language: Erlang " Author: Oscar Hellström " Contributors: Ricardo Catalinas Jiménez " Eduardo Lopez (http://github.com/tapichu) " License: Vim license " Version: 2012/01/25 if exists('b:did_ftplugin') finish else let b:did_ftplugin = 1 endif if exists('s:did_function_definitions') call s:SetErlangOptions() finish else let s:did_function_definitions = 1 endif if !exists('g:erlang_keywordprg') let g:erlang_keywordprg = 'erl -man' endif if !exists('g:erlang_folding') let g:erlang_folding = 0 endif let s:erlang_fun_begin = '^\a\w*(.*$' let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$' function s:SetErlangOptions() compiler erlang if version >= 700 setlocal omnifunc=erlang_complete#Complete endif if g:erlang_folding setlocal foldmethod=expr setlocal foldexpr=GetErlangFold(v:lnum) setlocal foldtext=ErlangFoldText() endif setlocal comments=:%%%,:%%,:% setlocal commentstring=%%s setlocal formatoptions+=ro let &l:keywordprg = g:erlang_keywordprg endfunction function GetErlangFold(lnum) let lnum = a:lnum let line = getline(lnum) if line =~ s:erlang_fun_end return '<1' endif if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1 return '1' endif if line =~ s:erlang_fun_begin return '>1' endif return '=' endfunction 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 call s:SetErlangOptions() jimenezrick-vimerl-89111c7/indent/000077500000000000000000000000001175161270200170625ustar00rootroot00000000000000jimenezrick-vimerl-89111c7/indent/erlang.vim000066400000000000000000000024421175161270200210510ustar00rootroot00000000000000" Vim indent file " Language: Erlang " Author: Ricardo Catalinas Jiménez " License: Vim license " Version: 2012/03/28 if exists('b:did_indent') finish else let b:did_indent = 1 endif setlocal indentexpr=ErlangIndent() setlocal indentkeys=!^F,o,O,=),=},=],=>>,=of,=catch,=after,=end if exists('*ErlangIndent') finish endif let s:erlang_indent_file = expand(':p:h') . '/erlang_indent.erl' if filewritable(expand(':p:h')) == 2 let s:in_fifo = expand(':p:h') . '/in_fifo.' . getpid() let s:out_fifo = expand(':p:h') . '/out_fifo.' . getpid() else let s:in_fifo = '/tmp/vimerl-in_fifo.' . getpid() let s:out_fifo = '/tmp/vimerl-out_fifo.' . getpid() endif execute 'silent !mkfifo' s:in_fifo execute 'silent !mkfifo' s:out_fifo execute 'silent !' . s:erlang_indent_file s:out_fifo s:in_fifo '&' autocmd VimLeave * call StopIndenter() function s:StopIndenter() call writefile([], s:out_fifo) call delete(s:in_fifo) call delete(s:out_fifo) endfunction function ErlangIndent() if v:lnum == 1 return 0 else call writefile([v:lnum] + getline(1, v:lnum), s:out_fifo) let indent = split(readfile(s:in_fifo)[0]) if len(indent) == 1 || !&expandtab return indent[0] * &shiftwidth else return indent[1] endif endif endfunction jimenezrick-vimerl-89111c7/indent/erlang_indent.erl000077500000000000000000000306161175161270200224100ustar00rootroot00000000000000#!/usr/bin/env escript %%! -detached -mode(compile). %-define(DEBUG, true). -ifdef(DEBUG). -define(PRINT_ERROR(T, S, L), io:format("Error: line ~B token ~p state ~p~n", [L, T, S])). -define(PRINT_STATE(S), io:format("Debug: state ~p~n", [S])). -else. -define(PRINT_ERROR(T, S, L), true). -define(PRINT_STATE(S), true). -endif. -define(IS(T, C), (element(1, T) == C)). -define(OPEN_BRACKET(T), ?IS(T, '('); ?IS(T, '{'); ?IS(T, '['); ?IS(T, '<<')). -define(CLOSE_BRACKET(T), ?IS(T, ')'); ?IS(T, '}'); ?IS(T, ']'); ?IS(T, '>>')). -define(BRANCH_EXPR(T), ?IS(T, 'fun'); ?IS(T, 'receive'); ?IS(T, 'if'); ?IS(T, 'case'); ?IS(T, 'try')). -record(state, {stack = [], tabs = [0], cols = [none]}). main(["-f", File, Line]) -> Source = read_file(File), Indent = format_indentation(source_indentation(Source, list_to_integer(Line))), io:format("~s~n", [Indent]); main([InFifo, OutFifo]) -> case read_fifo(InFifo) of [] -> halt(0); Input -> {ok, [Line], [$\n | Source]} = io_lib:fread("~d", Input), Indent = format_indentation(source_indentation(Source, Line)), write_fifo(OutFifo, lists:flatten(Indent)), main([InFifo, OutFifo]) end; main(_) -> io:format("Usage: ~s | -f ~n", [escript:script_name()]), halt(1). read_fifo(Fifo) -> os:cmd("cat " ++ Fifo). write_fifo(Fifo, Str) -> os:cmd("echo " ++ Str ++ " > " ++ Fifo). read_file(File) -> {ok, Bin} = file:read_file(File), binary_to_list(Bin). format_indentation({Tab, none}) -> io_lib:format("~B", [Tab]); format_indentation({Tab, Col}) -> io_lib:format("~B ~B", [Tab, Col]). source_indentation(Source, Line) -> try Tokens = tokenize_source(Source), {PrevToks, NextToks} = split_prev_block(Tokens, Line), indentation_between(PrevToks, NextToks) catch throw:scan_error -> {-1, none} end. tokenize_source(Source) -> eat_shebang(tokenize_source2(Source)). tokenize_source2(Source) -> case erl_scan:string(Source, {1, 1}) of {ok, Tokens, _} -> Tokens; {error, _, _} -> throw(scan_error) end. eat_shebang([{'#', {N, _}}, {'!', {N, _}} | Tokens]) -> lists:dropwhile(fun(T) -> line(T) == N end, Tokens); eat_shebang(Tokens) -> Tokens. split_prev_block(Tokens, Line) when Line < 1 -> error(badarg, [Tokens, Line]); split_prev_block(Tokens, Line) -> {PrevToks, NextToks} = lists:splitwith(fun(T) -> line(T) < Line end, Tokens), PrevToks2 = lists:reverse(PrevToks), PrevToks3 = lists:takewhile(fun(T) -> category(T) /= dot end, PrevToks2), {lists:reverse(PrevToks3), NextToks}. category(Token) -> {category, Cat} = erl_scan:token_info(Token, category), Cat. line(Token) -> {line, Line} = erl_scan:token_info(Token, line), Line. column(Token) -> {column, Col} = erl_scan:token_info(Token, column), Col. indentation_between([], _) -> {0, none}; indentation_between(PrevToks, NextToks) -> try State = parse_tokens(PrevToks), ?PRINT_STATE(State), State2 = case State#state.stack of [{'=', _} | _] -> pop(State); _ -> State end, #state{tabs = [Tab | _], cols = [Col | _]} = State, Tab2 = hd(State2#state.tabs), case {State2#state.stack, NextToks} of {_, [T | _]} when ?CLOSE_BRACKET(T) -> case Col of none -> {Tab, Col}; _ when ?IS(T, '>>') -> {Tab, Col - 2}; _ -> {Tab, Col - 1} end; {[{'try', _} | _], [T | _]} when ?IS(T, 'catch'); ?IS(T, 'after') -> {Tab2 - 1, none}; {[{'receive', _} | _], [T | _]} when ?IS(T, 'after') -> {Tab2 - 1, none}; {[{'->', _}, {'try', _} | _], [T | _]} when ?IS(T, 'catch') -> {Tab2 - 2, none}; {[{'->', _} | _], [T | _]} when ?IS(T, 'after') -> {Tab2 - 2, none}; {[T1 | _], [T2 | _]} when ?IS(T1, 'begin'), ?IS(T2, 'end') -> {Tab2 - 1, none}; {[T1 | _], [T2 | _]} when ?IS(T1, 'try'), ?IS(T2, 'end') -> {Tab2 - 1, none}; {[T1 | _], [T2 | _]} when ?IS(T1, '->'), ?IS(T2, 'end') -> {Tab2 - 2, none}; {_, [T | _]} when ?IS(T, 'of') -> {Tab2 - 1, none}; _ -> {Tab, Col} end catch throw:{parse_error, LastToks, LastState, _Line} -> case LastToks of [] -> _LastTok = eof; [_LastTok | _] -> _LastTok end, ?PRINT_ERROR(_LastTok, LastState, _Line), {hd(LastState#state.tabs), hd(LastState#state.cols)} end. parse_tokens(Tokens = [{'-', _} | _]) -> parse_attribute(Tokens, #state{}); parse_tokens(Tokens = [{atom, _, _} | _]) -> parse_function(Tokens, #state{}); parse_tokens(Tokens) -> throw({parse_error, Tokens, #state{}, ?LINE}). parse_attribute([T = {'-', _}, {atom, _, export} | Tokens], State = #state{stack = []}) -> parse_next(Tokens, push(State, T, -1)); parse_attribute([T1 = {'-', _}, T2, T3 | Tokens], State = #state{stack = []}) when ?IS(T2, atom), ?IS(T3, atom) -> parse_next(Tokens, push(State, T1, 1)); parse_attribute([T = {'-', _} | Tokens], State = #state{stack = []}) -> parse_next(Tokens, push(State, T, 0)); parse_attribute(Tokens, State) -> throw({parse_error, Tokens, State, ?LINE}). parse_function([T = {atom, _, _} | Tokens], State = #state{stack = []}) -> parse_next(Tokens, indent(push(State, T, 1), 1)); parse_function([], State) -> State; parse_function(Tokens, State) -> throw({parse_error, Tokens, State, ?LINE}). parse_next(Tokens, State) -> parse_next2(next_relevant_token(Tokens), State). parse_next2([T | Tokens], State) when ?IS(T, '<<') -> case same_line(T, Tokens) of true -> parse_next(Tokens, push(State, T, 1, column(T) + 1)); false -> parse_next(Tokens, push(State, T, 1)) end; parse_next2([T | Tokens], State) when ?OPEN_BRACKET(T) -> case same_line(T, Tokens) of true -> parse_next(Tokens, push(State, T, 1, column(T))); false -> parse_next(Tokens, push(State, T, 1)) end; parse_next2([T1 | Tokens], State = #state{stack = [T2 | _]}) when ?CLOSE_BRACKET(T1) -> case symmetrical(category(T1)) == category(T2) of true -> parse_next(Tokens, pop(State)); false -> throw({parse_error, [T1 | Tokens], State, ?LINE}) end; parse_next2([T1 = {'||', _} | Tokens], State = #state{stack = [T2 | _]}) when ?IS(T2, '['); ?IS(T2, '<<') -> case same_line(T1, Tokens) of true -> parse_next(Tokens, reindent(State, 1, column(T1) + 2)); false -> parse_next(Tokens, reindent(State, 0)) end; parse_next2([{'=', _} | Tokens], State = #state{stack = [T | _]}) when ?OPEN_BRACKET(T) -> parse_next(Tokens, State); parse_next2([T1 = {'=', _} | Tokens], State = #state{stack = [T2 | _]}) when ?IS(T2, '=') -> parse_next(Tokens, push(pop(State), T1, 1, column(T1) + 1)); parse_next2([T = {'=', _} | Tokens], State) -> parse_next(Tokens, push(State, T, 1, column(T) + 1)); parse_next2(Tokens = [T1 | _], State = #state{stack = [T2 | _]}) when ?IS(T2, '='), not ?IS(T1, ','), not ?IS(T1, ';') -> parse_next2(Tokens, pop(State)); parse_next2([{',', _} | Tokens], State = #state{stack = [T | _]}) when ?IS(T, '=') -> parse_next(Tokens, pop(State)); parse_next2([{',', _} | Tokens], State) -> parse_next(Tokens, State); parse_next2(Tokens = [{';', _} | _], State = #state{stack = [T | _]}) when ?IS(T, '=') -> parse_next2(Tokens, pop(State)); parse_next2([{';', _} | Tokens], State = #state{stack = [T1, T2 | _]}) when ?IS(T1, '->'), ?IS(T2, atom) -> parse_function(Tokens, pop(pop(State))); parse_next2([{';', _} | Tokens], State = #state{stack = [{'->', _}, T | _]}) when ?BRANCH_EXPR(T) -> parse_next(Tokens, indent_after(Tokens, pop(State), 2)); parse_next2([{';', _} | Tokens], State) -> parse_next(Tokens, State); parse_next2([{'fun', _}, T | Tokens], State) when not ?IS(T, '(') -> parse_next(Tokens, State); parse_next2([T | Tokens], State) when ?IS(T, 'fun'); ?IS(T, 'receive'); ?IS(T, 'if') -> parse_next(Tokens, indent_after(Tokens, push(State, T, 1), 2)); parse_next2([T | Tokens], State) when ?BRANCH_EXPR(T) -> parse_next(Tokens, push(State, T, 1)); parse_next2([T | Tokens], State) when ?IS(T, 'of') -> parse_next(Tokens, indent_after(Tokens, State, 2)); parse_next2([T1 = {'->', _} | Tokens], State = #state{stack = [T2]}) when ?IS(T2, '-') -> parse_next(Tokens, push(State, T1, 0)); parse_next2([T1 = {'->', _} | Tokens], State = #state{stack = [T2]}) when ?IS(T2, atom) -> parse_next(Tokens, push(unindent(State), T1, 0)); parse_next2([T1 = {'->', _} | Tokens], State = #state{stack = [T2 | _]}) when ?BRANCH_EXPR(T2) -> parse_next(Tokens, push(unindent(State), T1, 1)); parse_next2([{'catch', _} | Tokens], State = #state{stack = [T1, T2 | _]}) when not ?IS(T1, 'try'), not (?IS(T1, '->') and ?IS(T2, 'try')) -> parse_next(Tokens, State); parse_next2([T | Tokens], State = #state{stack = [{'try', _} | _]}) when ?IS(T, 'catch') -> parse_next(Tokens, indent_after(Tokens, State, 2)); parse_next2([T | Tokens], State = #state{stack = [{'->', _}, {'try', _} | _]}) when ?IS(T, 'catch') -> parse_next(Tokens, indent_after(Tokens, pop(State), 2)); parse_next2([T | Tokens], State = #state{stack = [{'try', _} | _]}) when ?IS(T, 'after') -> parse_next(Tokens, State); parse_next2([T | Tokens], State = #state{stack = [{'receive', _} | _]}) when ?IS(T, 'after') -> parse_next(Tokens, indent_after(Tokens, unindent(State), 2)); parse_next2([T | Tokens], State = #state{stack = [{'->', _}, {'receive', _} | _]}) when ?IS(T, 'after') -> parse_next(Tokens, indent_after(Tokens, pop(State), 2)); parse_next2([T | Tokens], State = #state{stack = [{'->', _} | _]}) when ?IS(T, 'after') -> parse_next(Tokens, pop(State)); parse_next2([T | Tokens], State) when ?IS(T, 'begin') -> parse_next(Tokens, push(State, T, 1)); parse_next2([{'end', _} | Tokens], State = #state{stack = [T | _]}) when ?IS(T, 'begin'); ?IS(T, 'try') -> parse_next(Tokens, pop(State)); parse_next2([{'end', _} | Tokens], State = #state{stack = [{'->', _} | _]}) -> parse_next(Tokens, pop(pop(State))); parse_next2([{dot, _} | Tokens], State = #state{stack = [T]}) when ?IS(T, '-') -> parse_next(Tokens, pop(State)); parse_next2([{dot, _} | Tokens], State = #state{stack = [T, _]}) when ?IS(T, '->') -> parse_next(Tokens, pop(pop(State))); parse_next2([], State) -> State; parse_next2(Tokens, State) -> throw({parse_error, Tokens, State, ?LINE}). indent(State, OffTab) -> indent(State, OffTab, none). indent(State, OffTab, Col) -> Tabs = State#state.tabs, Cols = State#state.cols, State#state{tabs = [hd(Tabs) + OffTab | Tabs], cols = [Col | Cols]}. indent_after([], State, _) -> State; indent_after(_Tokens, State, OffTab) -> indent(State, OffTab). reindent(State, OffTab) -> reindent(State, OffTab, none). reindent(State, OffTab, Col) -> [Tab | Tabs] = State#state.tabs, [_ | Cols] = State#state.cols, State#state{tabs = [Tab + OffTab | Tabs], cols = [Col | Cols]}. unindent(State = #state{tabs = Tabs, cols = Cols}) -> State#state{tabs = tl(Tabs), cols = tl(Cols)}. push(State, Token, OffTab) -> push(State, Token, OffTab, none). push(State = #state{stack = Stack}, Token, OffTab, Col) -> indent(State#state{stack = [Token | Stack]}, OffTab, Col). pop(State = #state{stack = Stack}) -> unindent(State#state{stack = tl(Stack)}). next_relevant_token(Tokens) -> lists:dropwhile(fun(T) -> irrelevant_token(T) end, Tokens). irrelevant_token(Token) -> Chars = ['(', ')', '{', '}', '[', ']', '<<', '>>', '=', '->', '||', ',', ';', dot], Keywords = ['fun', 'receive', 'if', 'case', 'try', 'of', 'catch', 'after', 'begin', 'end'], Cat = category(Token), not lists:member(Cat, Chars ++ Keywords). same_line(_, []) -> false; same_line(Token, [NextTok | _]) -> case line(Token) == line(NextTok) of true -> true; false -> false end. symmetrical(')') -> '('; symmetrical('}') -> '{'; symmetrical(']') -> '['; symmetrical('>>') -> '<<'. jimenezrick-vimerl-89111c7/plugin/000077500000000000000000000000001175161270200170775ustar00rootroot00000000000000jimenezrick-vimerl-89111c7/plugin/erlang_skel.vim000066400000000000000000000030051175161270200221000ustar00rootroot00000000000000" Vim plugin file " Language: Erlang " Author: Ricardo Catalinas Jiménez " License: Vim license " Version: 2011/09/10 if exists('g:loaded_erlang_skel') || v:version < 700 || &compatible finish else let g:loaded_erlang_skel = 1 endif if !exists('g:erlang_skel_replace') let g:erlang_skel_replace = 1 endif let s:skels_dir = expand(':p:h') . '/erlang_skels' function s:LoadSkeleton(skel_name) if g:erlang_skel_replace %delete else let current_line = line('.') call append(line('$'), '') normal G endif if exists('g:erlang_skel_header') execute 'read' s:skels_dir . '/' . 'header' for [name, value] in items(g:erlang_skel_header) call s:SubstituteField(name, value) endfor if !has_key(g:erlang_skel_header, 'year') call s:SubstituteField('year', strftime('%Y')) endif call append(line('$'), '') normal G endif execute 'read' s:skels_dir . '/' . a:skel_name call s:SubstituteField('modulename', expand('%:t:r')) if g:erlang_skel_replace normal gg delete else call cursor(current_line, 1) endif endfunction function s:SubstituteField(name, value) execute '%substitute/\$' . toupper(a:name) . '/' . a:value . '/' endfunction command ErlangApplication silent call s:LoadSkeleton('application') command ErlangSupervisor silent call s:LoadSkeleton('supervisor') command ErlangGenServer silent call s:LoadSkeleton('gen_server') command ErlangGenFsm silent call s:LoadSkeleton('gen_fsm') command ErlangGenEvent silent call s:LoadSkeleton('gen_event') jimenezrick-vimerl-89111c7/plugin/erlang_skels/000077500000000000000000000000001175161270200215505ustar00rootroot00000000000000jimenezrick-vimerl-89111c7/plugin/erlang_skels/application000066400000000000000000000032061175161270200237770ustar00rootroot00000000000000-module($MODULENAME). -behaviour(application). %% Application callbacks -export([start/2, stop/1]). %%%=================================================================== %%% Application callbacks %%%=================================================================== %%-------------------------------------------------------------------- %% @private %% @doc %% This function is called whenever an application is started using %% application:start/[1,2], and should start the processes of the %% application. If the application is structured according to the OTP %% design principles as a supervision tree, this means starting the %% top supervisor of the tree. %% %% @spec start(StartType, StartArgs) -> {ok, Pid} | %% {ok, Pid, State} | %% {error, Reason} %% StartType = normal | {takeover, Node} | {failover, Node} %% StartArgs = term() %% @end %%-------------------------------------------------------------------- start(_StartType, _StartArgs) -> 'TopSupervisor':start_link(). %%-------------------------------------------------------------------- %% @private %% @doc %% This function is called whenever an application has stopped. It %% is intended to be the opposite of Module:start/2 and should do %% any necessary cleaning up. The return value is ignored. %% %% @spec stop(State) -> void() %% @end %%-------------------------------------------------------------------- stop(_State) -> ok. %%%=================================================================== %%% Internal functions %%%=================================================================== jimenezrick-vimerl-89111c7/plugin/erlang_skels/gen_event000066400000000000000000000104101175161270200234410ustar00rootroot00000000000000-module($MODULENAME). -behaviour(gen_event). %% API -export([start_link/0, add_handler/2]). %% gen_event callbacks -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). -record(state, {}). %%%=================================================================== %%% gen_event callbacks %%%=================================================================== %%-------------------------------------------------------------------- %% @doc %% Creates an event manager %% %% @spec start_link() -> {ok, Pid} | {error, Error} %% @end %%-------------------------------------------------------------------- start_link() -> gen_event:start_link({local, ?MODULE}). %%-------------------------------------------------------------------- %% @doc %% Adds an event handler %% %% @spec add_handler(Handler, Args) -> ok | {'EXIT', Reason} | term() %% @end %%-------------------------------------------------------------------- add_handler(Handler, Args) -> gen_event:add_handler(?MODULE, Handler, Args). %%%=================================================================== %%% gen_event callbacks %%%=================================================================== %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever a new event handler is added to an event manager, %% this function is called to initialize the event handler. %% %% @spec init(Args) -> {ok, State} %% @end %%-------------------------------------------------------------------- init([]) -> {ok, #state{}}. %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever an event manager receives an event sent using %% gen_event:notify/2 or gen_event:sync_notify/2, this function is %% called for each installed event handler to handle the event. %% %% @spec handle_event(Event, State) -> %% {ok, State} | %% {swap_handler, Args1, State1, Mod2, Args2} | %% remove_handler %% @end %%-------------------------------------------------------------------- handle_event(_Event, State) -> {ok, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever an event manager receives a request sent using %% gen_event:call/3,4, this function is called for the specified %% event handler to handle the request. %% %% @spec handle_call(Request, State) -> %% {ok, Reply, State} | %% {swap_handler, Reply, Args1, State1, Mod2, Args2} | %% {remove_handler, Reply} %% @end %%-------------------------------------------------------------------- handle_call(_Request, State) -> Reply = ok, {ok, Reply, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% This function is called for each installed event handler when %% an event manager receives any other message than an event or a %% synchronous request (or a system message). %% %% @spec handle_info(Info, State) -> %% {ok, State} | %% {swap_handler, Args1, State1, Mod2, Args2} | %% remove_handler %% @end %%-------------------------------------------------------------------- handle_info(_Info, State) -> {ok, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever an event handler is deleted from an event manager, this %% function is called. It should be the opposite of Module:init/1 and %% do any necessary cleaning up. %% %% @spec terminate(Reason, State) -> void() %% @end %%-------------------------------------------------------------------- terminate(_Reason, _State) -> ok. %%-------------------------------------------------------------------- %% @private %% @doc %% Convert process state when code is changed %% %% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} %% @end %%-------------------------------------------------------------------- code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== jimenezrick-vimerl-89111c7/plugin/erlang_skels/gen_fsm000066400000000000000000000146541175161270200231230ustar00rootroot00000000000000-module($MODULENAME). -behaviour(gen_fsm). %% API -export([start_link/0]). %% gen_fsm callbacks -export([init/1, state_name/2, state_name/3, handle_event/3, handle_sync_event/4, handle_info/3, terminate/3, code_change/4]). -record(state, {}). %%%=================================================================== %%% API %%%=================================================================== %%-------------------------------------------------------------------- %% @doc %% Creates a gen_fsm process which calls Module:init/1 to %% initialize. To ensure a synchronized start-up procedure, this %% function does not return until Module:init/1 has returned. %% %% @spec start_link() -> {ok, Pid} | ignore | {error, Error} %% @end %%-------------------------------------------------------------------- start_link() -> gen_fsm:start_link({local, ?MODULE}, ?MODULE, [], []). %%%=================================================================== %%% gen_fsm callbacks %%%=================================================================== %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever a gen_fsm is started using gen_fsm:start/[3,4] or %% gen_fsm:start_link/[3,4], this function is called by the new %% process to initialize. %% %% @spec init(Args) -> {ok, StateName, State} | %% {ok, StateName, State, Timeout} | %% ignore | %% {stop, StopReason} %% @end %%-------------------------------------------------------------------- init([]) -> {ok, state_name, #state{}}. %%-------------------------------------------------------------------- %% @private %% @doc %% There should be one instance of this function for each possible %% state name. Whenever a gen_fsm receives an event sent using %% gen_fsm:send_event/2, the instance of this function with the same %% name as the current state name StateName is called to handle %% the event. It is also called if a timeout occurs. %% %% @spec state_name(Event, State) -> %% {next_state, NextStateName, NextState} | %% {next_state, NextStateName, NextState, Timeout} | %% {stop, Reason, NewState} %% @end %%-------------------------------------------------------------------- state_name(_Event, State) -> {next_state, state_name, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% There should be one instance of this function for each possible %% state name. Whenever a gen_fsm receives an event sent using %% gen_fsm:sync_send_event/[2,3], the instance of this function with %% the same name as the current state name StateName is called to %% handle the event. %% %% @spec state_name(Event, From, State) -> %% {next_state, NextStateName, NextState} | %% {next_state, NextStateName, NextState, Timeout} | %% {reply, Reply, NextStateName, NextState} | %% {reply, Reply, NextStateName, NextState, Timeout} | %% {stop, Reason, NewState} | %% {stop, Reason, Reply, NewState} %% @end %%-------------------------------------------------------------------- state_name(_Event, _From, State) -> Reply = ok, {reply, Reply, state_name, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever a gen_fsm receives an event sent using %% gen_fsm:send_all_state_event/2, this function is called to handle %% the event. %% %% @spec handle_event(Event, StateName, State) -> %% {next_state, NextStateName, NextState} | %% {next_state, NextStateName, NextState, Timeout} | %% {stop, Reason, NewState} %% @end %%-------------------------------------------------------------------- handle_event(_Event, StateName, State) -> {next_state, StateName, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever a gen_fsm receives an event sent using %% gen_fsm:sync_send_all_state_event/[2,3], this function is called %% to handle the event. %% %% @spec handle_sync_event(Event, From, StateName, State) -> %% {next_state, NextStateName, NextState} | %% {next_state, NextStateName, NextState, Timeout} | %% {reply, Reply, NextStateName, NextState} | %% {reply, Reply, NextStateName, NextState, Timeout} | %% {stop, Reason, NewState} | %% {stop, Reason, Reply, NewState} %% @end %%-------------------------------------------------------------------- handle_sync_event(_Event, _From, StateName, State) -> Reply = ok, {reply, Reply, StateName, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% This function is called by a gen_fsm when it receives any %% message other than a synchronous or asynchronous event %% (or a system message). %% %% @spec handle_info(Info,StateName,State)-> %% {next_state, NextStateName, NextState} | %% {next_state, NextStateName, NextState, Timeout} | %% {stop, Reason, NewState} %% @end %%-------------------------------------------------------------------- handle_info(_Info, StateName, State) -> {next_state, StateName, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% This function is called by a gen_fsm when it is about to %% terminate. It should be the opposite of Module:init/1 and do any %% necessary cleaning up. When it returns, the gen_fsm terminates with %% Reason. The return value is ignored. %% %% @spec terminate(Reason, StateName, State) -> void() %% @end %%-------------------------------------------------------------------- terminate(_Reason, _StateName, _State) -> ok. %%-------------------------------------------------------------------- %% @private %% @doc %% Convert process state when code is changed %% %% @spec code_change(OldVsn, StateName, State, Extra) -> %% {ok, StateName, NewState} %% @end %%-------------------------------------------------------------------- code_change(_OldVsn, StateName, State, _Extra) -> {ok, StateName, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== jimenezrick-vimerl-89111c7/plugin/erlang_skels/gen_server000066400000000000000000000074371175161270200236450ustar00rootroot00000000000000-module($MODULENAME). -behaviour(gen_server). %% API -export([start_link/0]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -record(state, {}). %%%=================================================================== %%% API %%%=================================================================== %%-------------------------------------------------------------------- %% @doc %% Starts the server %% %% @spec start_link() -> {ok, Pid} | ignore | {error, Error} %% @end %%-------------------------------------------------------------------- start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). %%%=================================================================== %%% gen_server callbacks %%%=================================================================== %%-------------------------------------------------------------------- %% @private %% @doc %% Initializes the server %% %% @spec init(Args) -> {ok, State} | %% {ok, State, Timeout} | %% ignore | %% {stop, Reason} %% @end %%-------------------------------------------------------------------- init([]) -> {ok, #state{}}. %%-------------------------------------------------------------------- %% @private %% @doc %% Handling call messages %% %% @spec handle_call(Request, From, State) -> %% {reply, Reply, State} | %% {reply, Reply, State, Timeout} | %% {noreply, State} | %% {noreply, State, Timeout} | %% {stop, Reason, Reply, State} | %% {stop, Reason, State} %% @end %%-------------------------------------------------------------------- handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% Handling cast messages %% %% @spec handle_cast(Msg, State) -> {noreply, State} | %% {noreply, State, Timeout} | %% {stop, Reason, State} %% @end %%-------------------------------------------------------------------- handle_cast(_Msg, State) -> {noreply, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% Handling all non call/cast messages %% %% @spec handle_info(Info, State) -> {noreply, State} | %% {noreply, State, Timeout} | %% {stop, Reason, State} %% @end %%-------------------------------------------------------------------- handle_info(_Info, State) -> {noreply, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% This function is called by a gen_server when it is about to %% terminate. It should be the opposite of Module:init/1 and do any %% necessary cleaning up. When it returns, the gen_server terminates %% with Reason. The return value is ignored. %% %% @spec terminate(Reason, State) -> void() %% @end %%-------------------------------------------------------------------- terminate(_Reason, _State) -> ok. %%-------------------------------------------------------------------- %% @private %% @doc %% Convert process state when code is changed %% %% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} %% @end %%-------------------------------------------------------------------- code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== jimenezrick-vimerl-89111c7/plugin/erlang_skels/header000066400000000000000000000003241175161270200227220ustar00rootroot00000000000000%%%------------------------------------------------------------------- %%% @author $AUTHOR %%% @copyright $YEAR $OWNER %%% @doc %%% %%% @end %%%------------------------------------------------------------------- jimenezrick-vimerl-89111c7/plugin/erlang_skels/supervisor000066400000000000000000000032231175161270200237140ustar00rootroot00000000000000-module($MODULENAME). -behaviour(supervisor). %% API -export([start_link/0]). %% Supervisor callbacks -export([init/1]). -define(CHILD(Id, Mod, Type, Args), {Id, {Mod, start_link, Args}, permanent, 5000, Type, [Mod]}). %%%=================================================================== %%% API functions %%%=================================================================== %%-------------------------------------------------------------------- %% @doc %% Starts the supervisor %% %% @spec start_link() -> {ok, Pid} | ignore | {error, Error} %% @end %%-------------------------------------------------------------------- start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). %%%=================================================================== %%% Supervisor callbacks %%%=================================================================== %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever a supervisor is started using supervisor:start_link/[2,3], %% this function is called by the new process to find out about %% restart strategy, maximum restart frequency and child %% specifications. %% %% @spec init(Args) -> {ok, {SupFlags, [ChildSpec]}} | %% ignore | %% {error, Reason} %% @end %%-------------------------------------------------------------------- init([]) -> {ok, {{one_for_one, 5, 10}, [?CHILD('SomeChild', 'SomeModule', worker, [])]}}. %%%=================================================================== %%% Internal functions %%%=================================================================== jimenezrick-vimerl-89111c7/syntax/000077500000000000000000000000001175161270200171275ustar00rootroot00000000000000jimenezrick-vimerl-89111c7/syntax/erlang.vim000066400000000000000000000162571175161270200211270ustar00rootroot00000000000000" Vim syntax file " Language: Erlang " Author: Oscar Hellström (http://oscar.hellstrom.st) " Contributors: Ricardo Catalinas Jiménez " License: Vim license " Version: 2012/05/07 if exists("b:current_syntax") finish else let b:current_syntax = "erlang" endif if !exists("g:erlang_highlight_bif") let g:erlang_highlight_bif = 1 endif " Erlang is case sensitive syn case match " Match groups syn match erlangStringModifier /\\./ contained syn match erlangStringModifier /\~\%(-\?[0-9*]\+\)\?\%(\.[0-9*]*\%(\..\?t\?\)\?\)\?\%(\~\|c\|f\|e\|g\|s\|w\|p\|W\|P\|B\|X\|#\|b\|x\|+\|n\|i\)/ contained syn match erlangModifier /\$\\\?./ syn match erlangInteger /\<\%([0-9]\+#[0-9a-fA-F]\+\|[0-9]\+\)\>/ syn match erlangFloat /\<[0-9]\+\.[0-9]\+\%(e-\?[0-9]\+\)\?\>/ syn keyword erlangTodo TODO FIXME XXX contained syn match erlangComment /%.*$/ contains=@Spell,erlangTodo,erlangAnnotation syn match erlangAnnotation /\%(%\s\)\@<=@\%(author\|clear\|copyright\|deprecated\|doc\|docfile\|end\|equiv\|headerfile\|hidden\|private\|reference\|see\|since\|spec\|throws\|title\|todo\|TODO\|type\|version\)/ contained syn match erlangAnnotation /`[^']\+'/ contained syn keyword erlangKeyword band bor bnot bsl bsr bxor div rem xor syn keyword erlangKeyword try catch begin receive after cond fun let query syn keyword erlangConditional case if of end syn keyword erlangConditional not and or andalso orelse syn keyword erlangConditional when syn keyword erlangBoolean true false syn keyword erlangGuard is_list is_alive is_atom is_binary is_bitstring is_boolean is_tuple is_number is_integer is_float is_function is_constant is_pid is_port is_reference is_record is_process_alive syn match erlangOperator /\/\|*\|+\|-\|++\|--/ syn match erlangOperator /->\|<-\|||\||\|!\|=/ syn match erlangOperator /=:=\|==\|\/=\|=\/=\|<\|>\|=<\|>=/ syn keyword erlangOperator div rem syn region erlangString start=/"/ end=/"/ skip=/\\/ contains=@Spell,erlangStringModifier syn match erlangVariable /\<[A-Z_]\w*\>/ syn match erlangAtom /\%(\%(^-\)\|#\)\@\%(\s*[(:]\)\@!/ syn match erlangAtom /\\\@/ syn match erlangBitSize /:\@<=[0-9]\+/ syn match erlangBinary /<<\|>>/ " BIFs syn match erlangBIF /\%([^:0-9A-Za-z_]\|\" >&2 exit 1 fi INDENTER=$(dirname $0)/../indent/erlang_indent.erl LAST_LINE=$(wc -l $1 | cut -d ' ' -f 1) for LINE in $(seq 1 $LAST_LINE) do echo -n Line: $LINE '==> ' $INDENTER -f $1 $LINE done jimenezrick-vimerl-89111c7/test/test_spaces.erl000066400000000000000000000101601175161270200215770ustar00rootroot00000000000000%%% vim: expandtab tabstop=4 shiftwidth=4 -module(test). -export([foo/0, baaaaar/2, baaaaaaaaa/4 ]). -export([ foo/1, baaaaar/2, baaaaaaaaa/4]). -define(FOO, 666 + 777). -vsn( "My beta version" ). -spec foo(X) -> {ok, Key} | {false, X} when X :: iter(), Key :: integer(). bar() -> begin more(), any() end. bar() -> Foo = begin more(), begin no() end, any() end, case neee() of 1 -> begin more() end; _ -> fdf end. foo() -> L = [1, 2 3 ], L2 = lists:map(fun(N) -> N + 1 end, L), L3 = lists:map( fun(N) -> N + 2 end, L), L4 = lists:map( fun (1) -> N + 1; (2) -> N + 2; (_) -> N end, L). foo() -> case {foooooooooooooooooo, baaaaaaaaaaaaaaaaar} of ok -> ok end, X = [{a, b}, c, {d, e, f, g}], Y = <>, [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], Foo = [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], Foo = [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], Foo = [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], Z = [ begin some(X, Y) end || X <- L1, Y <- L2]. foo() -> bar(fun foo/0, 1, 2, 3 ), X = 1 + 2 + 3 + 4, Y = case foo() of foo -> bar() end, ok. foo() -> fuuuuuuuuuuuuur( 1, 2 ), ok. fooooooooo(X, Y) when X =:= Y -> ok. foo() -> case foo() of bar -> catch fii(); fuu() -> ber() end. foo() -> case foo() of bar -> X = catch fii(); fuu() -> ber() end. foo() -> X = try foo() catch foo when foo -> bar() after bar() end. foo() -> try foo() catch foo when foo -> bar() after bar() end. foo() -> try foo(), bar() of foo when bar == 2 -> foo(), bar(); bar -> foo end. foo() -> try foo(), bar() of foo when bar == 2 -> foo(), bar(); bar -> foo after foo(), bar() end. foo() -> try foo(), bar() of foo when bar == 2 -> foo(), bar(); bar -> foo after foo(), bar() end. foo() -> try foo(), bar() of foo when bar == 2 -> foo(), bar(); bar -> foo catch foo when foo -> foo after foo(), bar() end. foo() -> receive after 1000 -> bar() end. foo() -> receive foo when foo -> foo() end. foo() -> receive foo when foo -> foo() after 1000 -> bar() end. foo() -> if foo -> bar(); bar -> foo() end. foo() -> case foo() of foo when bar -> foo(); bar -> end. foo() -> case foo() of foo when bar -> foo(); bar -> end. jimenezrick-vimerl-89111c7/test/test_tabs.erl000066400000000000000000000052221175161270200212550ustar00rootroot00000000000000%%% vim: noexpandtab tabstop=8 shiftwidth=8 -module(test). -export([foo/0, baaaaar/2, baaaaaaaaa/4 ]). -export([ foo/1, baaaaar/2, baaaaaaaaa/4]). -define(FOO, 666 + 777). -vsn( "My beta version" ). -spec foo(X) -> {ok, Key} | {false, X} when X :: iter(), Key :: integer(). bar() -> begin more(), any() end. bar() -> Foo = begin more(), begin no() end, any() end, case neee() of 1 -> begin more() end; _ -> fdf end. foo() -> L = [1, 2 3 ], L2 = lists:map(fun(N) -> N + 1 end, L), L3 = lists:map( fun(N) -> N + 2 end, L), L4 = lists:map( fun (1) -> N + 1; (2) -> N + 2; (_) -> N end, L). foo() -> case {foooooooooooooooooo, baaaaaaaaaaaaaaaaar} of ok -> ok end, X = [{a, b}, c, {d, e, f, g}], Y = <>, [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], Foo = [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], Foo = [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], Foo = [{X, Y, Z} || X <- L1, Y <- L2, Z <- L3], Z = [ begin some(X, Y) end || X <- L1, Y <- L2]. foo() -> bar(fun foo/0, 1, 2, 3 ), X = 1 + 2 + 3 + 4, Y = case foo() of foo -> bar() end, ok. foo() -> fuuuuuuuuuuuuur( 1, 2 ), ok. fooooooooo(X, Y) when X =:= Y -> ok. foo() -> case foo() of bar -> catch fii(); fuu() -> ber() end. foo() -> case foo() of bar -> X = catch fii(); fuu() -> ber() end. foo() -> X = try foo() catch foo when foo -> bar() after bar() end. foo() -> try foo() catch foo when foo -> bar() after bar() end. foo() -> try foo(), bar() of foo when bar == 2 -> foo(), bar(); bar -> foo end. foo() -> try foo(), bar() of foo when bar == 2 -> foo(), bar(); bar -> foo after foo(), bar() end. foo() -> try foo(), bar() of foo when bar == 2 -> foo(), bar(); bar -> foo after foo(), bar() end. foo() -> try foo(), bar() of foo when bar == 2 -> foo(), bar(); bar -> foo catch foo when foo -> foo after foo(), bar() end. foo() -> receive after 1000 -> bar() end. foo() -> receive foo when foo -> foo() end. foo() -> receive foo when foo -> foo() after 1000 -> bar() end. foo() -> if foo -> bar(); bar -> foo() end. foo() -> case foo() of foo when bar -> foo(); bar -> end. foo() -> case foo() of foo when bar -> foo(); bar -> end.