Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
17f99805f0 | |||
e959d11cd0 | |||
6bd67c3d1f | |||
2ab0455034 | |||
871e581509 | |||
2a11c032eb | |||
67248fc4b9 | |||
1a52a4a59a | |||
fd51fcac51 | |||
cae6118e1d | |||
f7784fc76a | |||
665209bb33 | |||
c11a4fe8ca | |||
545ce108f1 | |||
26b713807a |
10
Makefile
10
Makefile
@ -1,6 +1,12 @@
|
||||
|
||||
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)
|
||||
|
||||
install: $(TARGET)
|
||||
cp $(TARGET) $(INSTALL_DIR)
|
||||
cp $(TARGET).py $(INSTALL_DIR)
|
||||
|
@ -1,20 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char **new_argv = malloc(sizeof(char *) * (argc + 2));
|
||||
int i = 0;
|
||||
new_argv[i++] = "gvim";
|
||||
new_argv[i++] = "--remote-tab-silent";
|
||||
for (int n = 1; n < argc; n++, i++)
|
||||
{
|
||||
new_argv[i] = malloc(strlen(argv[n]) + 3);
|
||||
sprintf(new_argv[i], "\"%s\"", argv[n]);
|
||||
}
|
||||
new_argv[i++] = NULL;
|
||||
execv("C:\\apps\\Vim\\vim73\\gvim.exe", (const char * const *) new_argv);
|
||||
return -1;
|
||||
}
|
23
gvim-wrapper.cc
Normal file
23
gvim-wrapper.cc
Normal file
@ -0,0 +1,23 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
string program_name = argv[0];
|
||||
size_t pos = program_name.find_last_of("/\\");
|
||||
string script_path =
|
||||
(pos != string::npos)
|
||||
? program_name.substr(0, pos) + "/gvim-wrapper.py"
|
||||
: "gvim-wrapper.py";
|
||||
char **new_argv = new char *[argc + 2];
|
||||
memcpy(&new_argv[2], &argv[1], argc * sizeof(new_argv[0]));
|
||||
new_argv[0] = (char *)"pythonw.exe";
|
||||
new_argv[1] = (char *)script_path.c_str();
|
||||
new_argv[argc + 1] = NULL;
|
||||
argv[0] = (char *)"gvim-wrapper.py";
|
||||
execvp("pythonw.exe", new_argv);
|
||||
return -1;
|
||||
}
|
71
gvim-wrapper.py
Normal file
71
gvim-wrapper.py
Normal file
@ -0,0 +1,71 @@
|
||||
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': vimdir,
|
||||
# list of (path, name) tuples defining gvim contexts
|
||||
'servers': [],
|
||||
# default server name to use if no server paths match
|
||||
'default_server': 'GVIM',
|
||||
}
|
||||
|
||||
def read_config_file(config, path):
|
||||
if os.path.exists(path):
|
||||
fh = open(path, 'r')
|
||||
script = fh.read()
|
||||
fh.close()
|
||||
try:
|
||||
exec(script, config)
|
||||
except:
|
||||
sys.stderr.write('Configuration file error in "%s":\n' % path)
|
||||
traceback.print_exception(sys.exc_info()[0], sys.exc_info()[1],
|
||||
None)
|
||||
tb = traceback.extract_tb(sys.exc_info()[2])
|
||||
for ent in tb[1:]:
|
||||
lineno, fn = ent[1:3]
|
||||
sys.stderr.write(' File "%s", line %d, in %s\n'
|
||||
% (path, lineno, fn))
|
||||
|
||||
def path_contains_file(path, fname):
|
||||
path = path.replace('\\', '/')
|
||||
fname = fname.replace('\\', '/')
|
||||
if path.endswith('/'):
|
||||
path = path[:-1]
|
||||
return fname.startswith(path + '/')
|
||||
|
||||
def get_server_name(config, fname):
|
||||
for path, name in config['servers']:
|
||||
path = path.replace('\\', '/')
|
||||
if path.endswith('/*'):
|
||||
path = path[:-2]
|
||||
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):
|
||||
read_config_file(config, os.path.expanduser('~/.gvim-wrapper'))
|
||||
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))
|
Loading…
x
Reference in New Issue
Block a user