Skip to content

Commit

Permalink
Add option to automatically update tags when a buffer is saved
Browse files Browse the repository at this point in the history
  • Loading branch information
zengda authored and hcs42 committed Oct 2, 2017
1 parent a758dec commit 17bd1c0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -62,6 +62,30 @@ Or within Vim by executing the following command:
Note that for the latter command, the current working directory will be used
(`:help pwd` to find out more).

### Options

#### `g:erlang_tags_ignore`

Add ignore path for tags generation. Use a string or list of strings like:

let g:erlang_tags_ignore = 'rel'
let g:erlang_tags_ignore = ['rel']

Default: doesn't exist.

#### `g:erlang_tags_auto_update`

If exists and set to 1, this plugin will be triggered when an Erlang buffer is
written. Warning: this may cost lots of CPU if you have a large project. Note
that it might not work on Windows.

Default: doesn't exist.

#### `g:erlang_tags_outfile`

This option specifies the name of the generated tags file. By default, the
output file will be `./tags`.

### Automating generating tags

To keep the tags file up-to-date you can re-run these commands periodically, or
Expand Down
18 changes: 16 additions & 2 deletions plugin/vim-erlang-tags.vim
Expand Up @@ -23,7 +23,7 @@ autocmd FileType erlang call VimErlangTagsDefineMappings()

let s:exec_script = expand('<sfile>:p:h') . "/../bin/vim-erlang-tags.erl"

function! VimErlangTags()
function! s:GetExecuteCmd()
let script_opts = ""

if exists("g:erlang_tags_ignore")
Expand All @@ -39,17 +39,31 @@ function! VimErlangTags()
if exists("g:erlang_tags_outfile") && g:erlang_tags_outfile != ""
let script_opts = script_opts . " --output " . g:erlang_tags_outfile
endif
return s:exec_script . script_opts
endfunction

function! VimErlangTags()
let exec_cmd = s:GetExecuteCmd()

let script_output = system(s:exec_script . script_opts)
let script_output = system(exec_cmd)
if !v:shell_error
return 0
else
echoerr "vim-erlang-tag " . script_output
endif
endfunction

function! AsyncVimErlangTags()
let exec_cmd = s:GetExecuteCmd()
call system(exec_cmd . '&')
endfunction

command! ErlangTags call VimErlangTags()

if exists("g:erlang_tags_auto_update") && g:erlang_tags_auto_update == 1
au BufWritePost *.erl,*.hrl call AsyncVimErlangTags()
endif

function! VimErlangTagsSelect(split)
if a:split
split
Expand Down

0 comments on commit 17bd1c0

Please sign in to comment.