Tuesday, September 10, 2013

Re: idutils vim integration

Excerpts from sinbad's message of Tue Sep 10 07:34:56 +0200 2013:
> sorry, i don't get it, how am i suppose to use this.
> i find the documentation to be empty.

First learn that you should drop text you're not replying to.

The plugin file cotnains:

noremap \mid :call vim_addon_other#GnuIdutils_Mkid()<cr>
noremap \lid :call vim_addon_other#GnuIdutils_Lid()<cr>

The autoload/vim_addon_other.vim file contains the implementation:

let s:gnu_id_utils_file = fnamemodify(expand('<sfile>'),':h').'/gnu-idutils.config'
fun! vim_addon_other#GnuIdutils_Mkid()
let this_config = s:gnu_id_utils_file
let cmd = funcref#Call( get(s:config,'mkid', funcref#Function('return ["mkid", "-m", ARGS[0]]') ) , [this_config])
let errorFormat = "dummy"
call bg#RunQF(cmd,'c',errorFormat)
endf

fun! vim_addon_other#GnuIdutils_Lid()
"lid","-R","grep","-r",word
let cmd = funcref#Call( get(s:config, 'lid', funcref#Function('return ["lid", "-R", "grep", input("lid -R grep (^word$ for whole word matchr :")]') ) )
let errorFormat = get(s:config,'greplid_ef', '%f:%l:%m')
call bg#RunQF(cmd,'c',errorFormat)
return

" non bg version
exec 'set efm='.errorFormat
exec 'set grepprg='.cmd[0]
exec 'grep '.join(cmd[1:],' ')
endf



What is happening here?
noremap creates the mappings, calling the functions.

The bg#RunQF is a hack allowing to run those commands in the background.
Its tested on linux only. That implementation can be found in
vim-addon-background-cmd. However its trivial to use commands from Vim
instead:

Thus you can paste such in your .vimrc and customize it:

noremap \mid :call GnuIdutils_Mkid()<cr>
noremap \lid :call GnuIdutils_Lid()<cr>

fun! GnuIdutils_Mkid()
let this_config = s:gnu_id_utils_file
" using & to run in background, creating the database takes some time
call system('mkid -m '.g:gnu_id_utils_file.' &')
endf

fun! GnuIdutils_Lid()
let cmd = ["lid", "-R", "grep", input("lid -R grep (^word$ for whole word matchr :")]
exec 'set grepprg='.cmd[0]
" some quoting is still missing here:
exec 'grep '.join(cmd[1:],' ')
" eventually reset grep program here
endf

Marc Weber

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: