diff options
-rw-r--r-- | editor.py | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -14,6 +14,7 @@ | |||
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | import os | 16 | import os |
17 | import re | ||
17 | import sys | 18 | import sys |
18 | import subprocess | 19 | import subprocess |
19 | import tempfile | 20 | import tempfile |
@@ -38,9 +39,10 @@ class Editor(object): | |||
38 | if e: | 39 | if e: |
39 | return e | 40 | return e |
40 | 41 | ||
41 | e = cls.globalConfig.GetString('core.editor') | 42 | if cls.globalConfig: |
42 | if e: | 43 | e = cls.globalConfig.GetString('core.editor') |
43 | return e | 44 | if e: |
45 | return e | ||
44 | 46 | ||
45 | e = os.getenv('VISUAL') | 47 | e = os.getenv('VISUAL') |
46 | if e: | 48 | if e: |
@@ -69,21 +71,32 @@ least one of these before using this command.""" | |||
69 | Returns: | 71 | Returns: |
70 | new value of edited text; None if editing did not succeed | 72 | new value of edited text; None if editing did not succeed |
71 | """ | 73 | """ |
72 | editor = cls._GetEditor().split() | 74 | editor = cls._GetEditor() |
75 | if editor == ':': | ||
76 | return data | ||
77 | |||
73 | fd, path = tempfile.mkstemp() | 78 | fd, path = tempfile.mkstemp() |
74 | try: | 79 | try: |
75 | os.write(fd, data) | 80 | os.write(fd, data) |
76 | os.close(fd) | 81 | os.close(fd) |
77 | fd = None | 82 | fd = None |
78 | 83 | ||
84 | if re.compile("^.*[$ \t'].*$").match(editor): | ||
85 | args = [editor + ' "$@"'] | ||
86 | shell = True | ||
87 | else: | ||
88 | args = [editor] | ||
89 | shell = False | ||
90 | args.append(path) | ||
91 | |||
79 | try: | 92 | try: |
80 | rc = subprocess.Popen(editor + [path]).wait() | 93 | rc = subprocess.Popen(args, shell=shell).wait() |
81 | except OSError, e: | 94 | except OSError, e: |
82 | raise EditorError('editor failed, %s: %s %s' | 95 | raise EditorError('editor failed, %s: %s %s' |
83 | % (str(e), cls._GetEditor(), path)) | 96 | % (str(e), editor, path)) |
84 | if rc != 0: | 97 | if rc != 0: |
85 | raise EditorError('editor failed with exit status %d: %s %s' | 98 | raise EditorError('editor failed with exit status %d: %s %s' |
86 | % (rc, cls._GetEditor(), path)) | 99 | % (rc, editor, path)) |
87 | 100 | ||
88 | fd2 = open(path) | 101 | fd2 = open(path) |
89 | try: | 102 | try: |