Compare commits

...

8 Commits
v0.2 ... master

3 changed files with 29 additions and 17 deletions

View File

@ -1,8 +1,9 @@
TARGET := gvim-wrapper
CFLAGS := -mno-cygwin -std=gnu99 -mwindows
LDFLAGS := -mno-cygwin -mwindows
CFLAGS := -std=gnu99 -mwindows
LDFLAGS := -mwindows -static-libgcc -static-libstdc++
INSTALL_DIR ?= /c/apps/bin
CXX := i686-pc-mingw32-g++
all: $(TARGET)

View File

@ -1,4 +1,5 @@
#include <unistd.h>
#include <string.h>
#include <string>
using namespace std;
@ -11,12 +12,12 @@ int main(int argc, char *argv[])
(pos != string::npos)
? program_name.substr(0, pos) + "/gvim-wrapper.py"
: "gvim-wrapper.py";
const char **new_argv = new const char *[argc + 2];
char **new_argv = new char *[argc + 2];
memcpy(&new_argv[2], &argv[1], argc * sizeof(new_argv[0]));
new_argv[0] = "pythonw.exe";
new_argv[1] = script_path.c_str();
new_argv[0] = (char *)"pythonw.exe";
new_argv[1] = (char *)script_path.c_str();
new_argv[argc + 1] = NULL;
argv[0] = "gvim-wrapper.py";
argv[0] = (char *)"gvim-wrapper.py";
execvp("pythonw.exe", new_argv);
return -1;
}

View File

@ -1,9 +1,16 @@
import os
import sys
if os.path.exists('C:\\apps\\Vim\\vim74\\gvim.exe'):
vimdir = 'C:\\apps\\Vim\\vim74'
elif os.path.exists('C:\\apps\\Vim\\vim73\\gvim.exe'):
vimdir = 'C:\\apps\\Vim\\vim73'
else:
raise "Could not find Vim directory, update script"
config = {
# path to directory containing vim.exe and gvim.exe
'vimdir': 'C:\\apps\\Vim\\vim73',
'vimdir': vimdir,
# list of (path, name) tuples defining gvim contexts
'servers': [],
# default server name to use if no server paths match
@ -39,23 +46,26 @@ def get_server_name(config, fname):
path = path.replace('\\', '/')
if path.endswith('/*'):
path = path[:-2]
for dirent in os.listdir(path):
query_path = os.path.join(path, dirent)
if os.path.isdir(query_path) and path_contains_file(query_path, fname):
return name.replace('*', dirent)
try:
for dirent in os.listdir(path):
query_path = os.path.join(path, dirent)
if os.path.isdir(query_path) and path_contains_file(query_path, fname):
return name.replace('*', dirent)
except:
pass
else:
if path_contains_file(path, fname):
return name.replace('*', os.path.basename(path))
return config['default_server']
def main(argv):
if (len(argv) < 2):
return -1
read_config_file(config, os.path.expanduser('~/.gvim-wrapper'))
for fname in argv[1:]:
servername = get_server_name(config, fname)
os.execv(config['vimdir'] + '\\gvim.exe',
['gvim', '--servername', servername, '--remote-tab-silent', fname])
fname = ' '.join(argv[1:]) if len(argv) >= 2 else ''
servername = get_server_name(config, fname if fname != '' else os.getcwd() + '/dum')
cmd = ['gvim', '--servername', '"%s"' % servername]
if fname != '':
cmd += ['--remote-tab-silent', '"%s"' % fname]
os.execv(config['vimdir'] + '\\gvim.exe', cmd)
if __name__ == '__main__':
sys.exit(main(sys.argv))