Monday, October 24, 2011

Re: Ask ViM Process for open documents

#!/usr/bin/python
# Author: Marcin Szamotulski
# The script lists files hosted on all running vim servers.
# Star before file indicates that the buffer is loaded.

import subprocess, re, sys

# [1] The script hungs up when vim is suspended.

servers=subprocess.Popen(['gvim', '--serverlist'], stdout=subprocess.PIPE ).communicate()[0].decode()
# match=re.match('(b\')?(.*)(\')?$',servers)
server_ls=servers.split("\n")
def nonempty(entry):
if entry == "":
return 0
else:
return 1
server_ls=list(filter(nonempty, server_ls))
if len(server_ls) == 0:
print("no vim/gvim instance is running")
sys.exit(0)
for server in server_ls:
if server != '':
print("*** "+server+" ***")
cmd=['vim', '--servername', server, '--remote-expr \"vim#ls()\"']
subprocess.call(['vim', '--servername', server, '--remote-expr', 'vim#ls()'])

" This is set of vim standard functions to call them from
" command line (terminal)
" vim --servername "<server>" --remote-expr "<func_name>"
function! vim#ls()
let list=[]
for i in range(1, bufnr('$'))
call add(list, ( bufloaded(i) ? "(".i.") " . fnamemodify(bufname(i), ':p') : " ". fnamemodify(:bufname(i), ':p')))
endfor
return list
endfunction
On 14:38 Mon 24 Oct , Wael Nasreddine wrote:
> Hello,
>
> I'm trying to find a way to support ViM in WatchTower, a project of mine to track spent time per project per file, and to do that I have to know which documents are currently open in all ViM processes, so is there a way (or a plugin) that can provide me with absolute paths to all open documents in all buffers ?
>
> Best Regards,
> Wael Nasreddine
>
> --
> Wael Nasreddine: Design & Coding at TechnoGate
> contact | wael.nasreddine@gmail.com - +33.6.41.68.38.35 | skype - eMxyzptlk
>
> --
> 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

Hi,

I wrote myself a small script to list all buffers opened in all running vim's.
It consists of two files
bls which is a python script
vim.vim which should be put in $VIM_RUNTIME/autoload directory.

Hope this will help you.
Best,
Marcin Szamotulski

--
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

No comments: