Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Last active May 22, 2016 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRadev/c62132f96deca165b8969eba7bc1dc13 to your computer and use it in GitHub Desktop.
Save AndrewRadev/c62132f96deca165b8969eba7bc1dc13 to your computer and use it in GitHub Desktop.
An example for a custom ember_tools gf callback
" This is a project-specific Vim file that boosts ember_tools' gf mapping to
" follow translation keys to their yaml files.
let g:ember_tools_custom_gf_callbacks = [
\ 'EmberGfTranslations'
\ ]
function! EmberGfTranslations()
" only emblem files in this project
if &filetype != 'emblem'
return ''
endif
" position the cursor in the right place, or bail out
if !ember_tools#search#UnderCursor('i18n [''"]\zs\k\+[''"]')
return ''
endif
let translation_key = expand('<cword>')
" Translations are in the rails project one level up
let translations_file = fnamemodify('../config/locales/en.yml', ':p')
" Use ember_tools' file open callback mechanism to search for the right key
" once the translation file is open
let callback_args = [translations_file]
call extend(callback_args, map(split(translation_key, '\.'), '"^\\s*\\zs".v:val.":"'))
call call('ember_tools#SetFileOpenCallback', callback_args)
return translations_file
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment