Skip to content

Commit

Permalink
Cosmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
jimenezrick committed Mar 12, 2011
1 parent 59e7c83 commit 8828ed0
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 92 deletions.
4 changes: 2 additions & 2 deletions README
Expand Up @@ -73,8 +73,8 @@ differently.
-- Syntax options:
The options expect a 0 value for disabling and a non-zero (e.g. 1) for enabling.

* Highlight all Erlang bifs as keywords: (default: 0)
g:erlangHighlightBif
* Highlight all Erlang BIFs (functions from `erlang' module) as keywords: (default: 0)
g:erlangHighlightBIFs

-- Folding options:
The option expects a 0 value for disabling and a non-zero (e.g. 1) for enabling.
Expand Down
4 changes: 1 addition & 3 deletions autoload/erlang_complete.erl
@@ -1,5 +1,4 @@
#!/usr/bin/env escript
-export([main/1]).

main([ModuleName]) ->
Module = erlang:list_to_atom(ModuleName),
Expand All @@ -9,8 +8,7 @@ main([ModuleName]) ->
fun({FunctionName, ArgumentsCount}) ->
io:format("~s/~B~n", [FunctionName, ArgumentsCount])
end,
Functions
)
Functions)
catch
error:undef ->
bad_module
Expand Down
39 changes: 18 additions & 21 deletions autoload/erlangcomplete.vim
@@ -1,13 +1,11 @@
" ------------------------------------------------------------------------------
" Vim omni-completion script
" Author: Oscar Hellström
" Email: oscar@oscarh.net
" Version: 2010-08-10
" Vim omni completion file
" Language: Erlang
" Author: Oscar Hellström <oscar@oscarh.net>
" Version: 2010-08-10
" Contributors: kTT (http://github.com/kTT)
" Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
" ------------------------------------------------------------------------------
" Ricardo Catalinas Jiménez <jimenezrick@gmail.com>

" Patterns for completions {{{1
" Patterns for completions
let s:erlangLocalFuncBeg = '\(\<[0-9A-Za-z_-]*\|\s*\)$'
let s:erlangExternalFuncBeg = '\<[0-9A-Za-z_-]\+:[0-9A-Za-z_-]*$'
let s:ErlangBlankLine = '^\s*\(%.*\)\?$'
Expand All @@ -32,21 +30,21 @@ if !exists('g:erlangCompletionDisplayDoc')
let g:erlangCompletionDisplayDoc = 1
endif

" Main function for completion {{{1
" Main function for completion
function! erlangcomplete#Complete(findstart, base)
" 0) Init {{{2
" 0) Init
let lnum = line('.')
let column = col('.')
let line = strpart(getline('.'), 0, column - 1)

" 1) First, check if completion is impossible {{{2
" 1) First, check if completion is impossible
if line =~ '[^~\\]%'
return -1
endif

"echo "line[col - 1]:" . line[column - 1] . " line[col - 2]:" . line[column - 2] . "\n" . line . "\n"

" 2) Check if the char to the left of us are part of a function call {{{2
" 2) 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
Expand All @@ -64,7 +62,7 @@ function! erlangcomplete#Complete(findstart, base)
endif


" 3) Function in external module {{{2
" 3) Function in external module
if line =~ s:erlangExternalFuncBeg
let delimiter = match(line, ':[0-9A-Za-z_-]*$') + 1
if a:findstart
Expand All @@ -75,7 +73,7 @@ function! erlangcomplete#Complete(findstart, base)
endif
endif

" 4) Local function {{{2
" 4) Local function
if line =~ s:erlangLocalFuncBeg
let funcstart = match(line, ':\@<![0-9A-Za-z_-]*$')
if a:findstart
Expand All @@ -85,16 +83,16 @@ function! erlangcomplete#Complete(findstart, base)
endif
endif

" 5) Unhandled situation {{{2
" 5) Unhandled situation
if a:findstart
return -1
else
return []
endif
endfunction

" Auxiliary functions for completion {{{1
" Find the next non-blank line {{{2
" Auxiliary functions for completion
" Find the next non-blank line
function s:erlangFindNextNonBlank(lnum)
let lnum = nextnonblank(a:lnum + 1)
let line = getline(lnum)
Expand All @@ -104,9 +102,8 @@ function s:erlangFindNextNonBlank(lnum)
endwhile
return lnum
endfunction

" vim: foldmethod=marker:
" Find external function names {{{2

" Find external function names
function s:erlangFindExternalFunc(module, base)
" If it's a local module, try to compile it
if filereadable(a:module . '.erl') && !filereadable(a:module . '.beam')
Expand Down Expand Up @@ -142,7 +139,7 @@ function s:erlangFindExternalFunc(module, base)
return []
endfunction

" Find local function names {{{2
" Find local function names
function s:erlangFindLocalFunc(base)
" begin at line 1
let lnum = s:erlangFindNextNonBlank(1)
Expand Down
3 changes: 1 addition & 2 deletions compiler/erlang.vim
@@ -1,7 +1,6 @@
" Erlang compiler file
" Vim compiler file
" Language: Erlang
" Maintainer: Pawel 'kTT' Salata <rockplayer.pl@gmail.com>
" URL: http://ktototaki.info

if exists("current_compiler")
finish
Expand Down
21 changes: 4 additions & 17 deletions ftplugin/erlang.vim
Expand Up @@ -4,22 +4,7 @@
" Contributors: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
" Eduardo Lopez (http://github.com/tapichu)
" Version: 2011/03/10
" ------------------------------------------------------------------------------
" Usage:
"
" To enable folding put in your vimrc:
" set foldenable
"
" Folding will make only one fold for a complete function, even though it has
" more than one function head and body.
"
" To change this behaviour put in your vimrc file:
" let g:erlangFoldSplitFunction=1
"
" To use the default program for the `K' command put in your vimrc:
" let g:erlangKCommand='man'
"
" ------------------------------------------------------------------------------

" Plugin init
if exists("b:did_ftplugin")
finish
Expand Down Expand Up @@ -54,7 +39,9 @@ function s:SetErlangOptions()
setlocal commentstring=%%s
setlocal formatoptions+=ro

let &l:keywordprg=g:erlangKCommand
if g:erlangKCommand != ''
let &l:keywordprg=g:erlangKCommand
endif
endfunction

" Define folding functions
Expand Down
5 changes: 1 addition & 4 deletions ftplugin/erlang_refactor.vim
@@ -1,7 +1,6 @@
" Erlang refactor file
" Vim refactor file
" Language: Erlang
" Maintainer: Pawel 'kTT' Salata <rockplayer.pl@gmail.com>
" URL: http://ktototaki.info

if exists("b:did_ftplugin_erlang")
finish
Expand Down Expand Up @@ -291,5 +290,3 @@ function! ErlangTupleFunArgs(mode)
endfunction
nmap <A-r>t :call ErlangTupleFunArgs("n")<ENTER>
vmap <A-r>t :call ErlangTupleFunArgs("v")<ENTER>
" vim: set foldmethod=marker:
20 changes: 1 addition & 19 deletions indent/erlang.vim
Expand Up @@ -35,7 +35,7 @@ function s:ErlangIndentAfterLine(l)

" ignore type annotation lines
if a:l =~# '^\s*-type'
return 0
return 0
endif

while 0<= i && i < length
Expand Down Expand Up @@ -140,7 +140,6 @@ function s:FindPrevNonBlankNonComment(lnum)
endfunction

function ErlangIndent()

" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)

Expand Down Expand Up @@ -187,21 +186,4 @@ function ErlangIndent()
let ind = 0
endif
return ind

endfunction

" TODO:
"
" f() ->
" x("foo
" bar")
" ,
" bad_indent.
"
" fun
" init/0,
" bad_indent
"
" #rec
" .field,
" bad_indent
34 changes: 10 additions & 24 deletions syntax/erlang.vim
Expand Up @@ -3,29 +3,20 @@
" Maintainer: Oscar Hellström <oscar@oscarh.net>
" URL: http://oscar.hellstrom.st
" Version: 2010-08-09
" ------------------------------------------------------------------------------
" {{{1
" Options:
"
" Erlang BIFs
" g:erlangHighlightBif - highlight erlang built in functions (default: off)
"
" }}}
" -----------------------------------------------------------------------------

" Setup {{{1

" Setup
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
syntax clear
elseif exists("b:current_syntax")
finish
finish
endif

" Erlang is case sensitive
syn case match

" Match groups {{{1
" Match groups
syn match erlangStringModifier /\\./ contained
syn match erlangStringModifier /\~\%(-\?[0-9*]\+\)\?\%(\.[0-9*]\+\..\?\)\?\%(c\|f\|e\|g\|s\|w\|p\|W\|P\|B\|X\|#\|b\|+\|n\|i\)/ contained
syn match erlangModifier /\$\\\?./
Expand Down Expand Up @@ -79,13 +70,12 @@ syn match erlangBitSize /:\@<=[0-9]\+/

syn match erlangBinary /<<\|>>/

" BIFS
" BIFs
syn match erlangBIF /\%([^:0-9A-Za-z_]\|\<erlang:\)\@<=\%(abs\|apply\|atom_to_list\|binary_to_list\|binary_to_term\|check_process_code\|concat_binary\|date\|delete_module\|disconnect_node\|element\|erase\|exit\|float\|float_to_list\|garbage_collect\|get\|get_keys\|group_leader\|halt\|hd\|integer_to_list\|iolist_to_binary\|iolist_size\|length\|link\|list_to_atom\|list_to_binary\|list_to_existing_atom\|list_to_float\|list_to_integer\|list_to_pid\|list_to_tuple\|load_module\|make_ref\|monitor_node\|node\|nodes\|now\|open_port\|pid_to_list\|port_close\|port_command\|port_connect\|port_control\|pre_loaded\|process_flag\|process_info\|processes\|purge_module\|put\|register\|registered\|round\|self\|setelement\|size\|bit_size\|spawn\|spawn_link\|spawn_opt\|split_binary\|statistics\|term_to_binary\|throw\|time\|tl\|trunc\|tuple_to_list\|unlink\|unregister\|whereis\)\((\|\/[0-9]\)\@=/
syn match erlangBIF /\<\%(erlang:\)\@<=\%(append_element\|bump_reductions\|cancel_timer\|demonitor\|display\|error\|fault\|fun_info\|fun_to_list\|function_exported\|get_cookie\|get_stacktrace\|hash\|hibernate\|info\|is_builtin\|loaded\|localtime\|localtime_to_universaltime\|localtime_to_universaltime\|make_tuple\|md5\|md5_init\|md5_update\|memory\|monitor\|monitor_node\|phash\|phash2\|port_call\|port_info\|port_to_list\|ports\|process_display\|raise\|read_timer\|ref_to_list\|resume_process\|send\|send_after\|send_nosuspend\|set_cookie\|spawn_monitor\|start_timer\|suspend_process\|system_flag\|system_info\|system_monitor\|trace\|trace_delivered\|trace_info\|trace_pattern\|universaltime\|universaltime_to_localtime\|yield\)(\@=/
syn match erlangGBIF /erlang\(:\w\)\@=/
" }}}

" Link Erlang stuff to Vim groups {{{1
" Link Erlang stuff to Vim groups
hi link erlangTodo Todo
hi link erlangString String
hi link erlangNoSpellString String
Expand Down Expand Up @@ -124,14 +114,10 @@ hi link erlangBitVariable Identifier
hi link erlangBitType Type
hi link erlangType Type
hi link erlangBitSize Number
" }}}

" Optional linkings {{{1
if exists("g:erlangHighlightBif") && g:erlangHighlightBif
hi link erlangGBIF Keyword
" Optional linking
if exists("g:erlangHighlightBIFs") && g:erlangHighlightBIFs
hi link erlangGBIF Keyword
endif
" }}}

let b:current_syntax = "erlang"

" vim: set foldmethod=marker:

0 comments on commit 8828ed0

Please sign in to comment.