Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build OTP tags and add to vim tags path #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ 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).

### Generate OTP tags

Often, you might be curious about the implementation of that function from the
OTP libraries, but `CTRL-t` is not taking you there. We have a solution for
this:

call AsyncBuildOtpTags()

This command will find the path to your otp installation, and inside its `lib/`
folder, it will build a tags file called `otptags`. The next thing you need, is
to make vim aware of this. That's where the next function comes in place:

call GetOtpTagsPath()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use echo instead of call? call won't print anything.


This will return the path to the generated `otptags` file, wherever this file
lives. Extract it, and add it to your tags by doing

let &tags.="," . otptags_path

Where otptags\_path is the expanded path returned previously.

### Options

#### `g:erlang_tags_ignore`
Expand Down
14 changes: 13 additions & 1 deletion plugin/vim-erlang-tags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ endif
autocmd FileType erlang call VimErlangTagsDefineMappings()

let s:exec_script = expand('<sfile>:p:h') . "/../bin/vim_erlang_tags.erl"
let s:otppath_cmd = 'erl -noinput -eval ''io:format("~ts", [code:lib_dir()]), init:stop().'''

function! s:GetExecuteCmd()
let script_opts = ""
Expand All @@ -42,6 +43,17 @@ function! s:GetExecuteCmd()
return s:exec_script . script_opts
endfunction

function! GetOtpTagsPath()
let otppath = system(s:otppath_cmd)
let otptags = otppath . "/otptags"
return otptags
endfunction

function! AsyncBuildOtpTags()
let cmd = '(OTPPATH=`' . s:otppath_cmd . '` && ' . s:exec_script . ' -i $OTPPATH -o $OTPPATH/otptags)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vim cannot necessarily write "$OTPPATH/otptags". For me erl -noinput -eval 'io:format("~ts", [code:lib_dir()]), init:stop().' returns /usr/lib/erlang/lib, which causes AsyncBuildOtpTags to silently fail.

Three suggestions:

  • Some error handling to report this situation.
  • Maybe use the ":terminal" command instead of system + &? (It was added in Vim 8.1.)
  • Maybe make it configurable to put the tags file somewhere else.

call system(cmd . " &")
endfunction

function! VimErlangTags(...)
let param = join(a:000, " ")
let exec_cmd = s:GetExecuteCmd()
Expand Down Expand Up @@ -104,7 +116,7 @@ if !exists("s:os")
endif

" https://vim.fandom.com/wiki/Autocmd_to_update_ctags_file
function! DelTagOfFile(file)
function! s:DelTagOfFile(file)
let fullpath = a:file
let cwd = getcwd()
let tagfilename = cwd . "/tags"
Expand Down