Show More
@@ -1,37 +1,38 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 |
|
2 | |||
3 |
|
3 | |||
4 | """ |
|
4 | """ | |
5 | Add %global magic for GNU Global usage. |
|
5 | Add %global magic for GNU Global usage. | |
6 |
|
6 | |||
7 | http://www.gnu.org/software/global/ |
|
7 | http://www.gnu.org/software/global/ | |
8 |
|
8 | |||
9 | """ |
|
9 | """ | |
10 |
|
10 | |||
11 | import IPython.ipapi |
|
11 | import IPython.ipapi | |
12 | ip = IPython.ipapi.get() |
|
12 | ip = IPython.ipapi.get() | |
13 | import os |
|
13 | import os | |
14 |
|
14 | |||
15 | # alter to your liking |
|
15 | # alter to your liking | |
16 | global_bin = 'd:/opt/global/bin/global' |
|
16 | global_bin = 'd:/opt/global/bin/global' | |
17 |
|
17 | |||
18 | def global_f(self,cmdline): |
|
18 | def global_f(self,cmdline): | |
19 | simple = 0 |
|
19 | simple = 0 | |
20 | if '-' not in cmdline: |
|
20 | if '-' not in cmdline: | |
21 | cmdline = '-rx ' + cmdline |
|
21 | cmdline = '-rx ' + cmdline | |
22 | simple = 1 |
|
22 | simple = 1 | |
23 |
|
23 | |||
24 | lines = os.popen( global_bin + ' ' + cmdline ).readlines() |
|
24 | lines = [l.rstrip() for l in os.popen( global_bin + ' ' + cmdline ).readlines()] | |
|
25 | ||||
25 | if simple: |
|
26 | if simple: | |
26 | parts = [l.split(None,3) for l in lines] |
|
27 | parts = [l.split(None,3) for l in lines] | |
27 | lines = ['%s [%s]\n%s' % (p[2].rjust(70),p[1],p[3].rstrip()) for p in parts] |
|
28 | lines = ['%s [%s]\n%s' % (p[2].rjust(70),p[1],p[3].rstrip()) for p in parts] | |
28 | print "\n".join(lines) |
|
29 | print "\n".join(lines) | |
29 |
|
30 | |||
30 | ip.expose_magic('global', global_f) |
|
31 | ip.expose_magic('global', global_f) | |
31 |
|
32 | |||
32 | def global_completer(self,event): |
|
33 | def global_completer(self,event): | |
33 | compl = [l.rstrip() for l in os.popen(global_bin + ' -c ' + event.symbol).readlines()] |
|
34 | compl = [l.rstrip() for l in os.popen(global_bin + ' -c ' + event.symbol).readlines()] | |
34 | return compl |
|
35 | return compl | |
35 |
|
36 | |||
36 | ip.set_hook('complete_command', global_completer, str_key = '%global') |
|
37 | ip.set_hook('complete_command', global_completer, str_key = '%global') | |
37 |
|
38 |
General Comments 0
You need to be logged in to leave comments.
Login now