~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/msgeditor.py

  • Committer: Martin Pool
  • Date: 2005-09-22 12:12:53 UTC
  • Revision ID: mbp@sourcefrog.net-20050922121253-eae2a3240ea5e493
- upgrade can no longer be done in current version branches
  so don't test it

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
"""Commit message editor support."""
21
21
 
22
22
import os
23
 
from subprocess import call
24
23
from bzrlib.errors import BzrError
25
24
 
26
25
def _get_editor():
27
26
    """Return a sequence of possible editor binaries for the current platform"""
28
27
    from bzrlib.osutils import _read_config_value
29
28
    
30
 
    try:
31
 
        yield os.environ["BZR_EDITOR"]
32
 
    except KeyError:
33
 
        pass
34
 
 
35
29
    e = _read_config_value("editor")
36
30
    if e is not None:
37
31
        yield e
38
32
        
39
 
    try:
40
 
        yield os.environ["EDITOR"]
41
 
    except KeyError:
42
 
        pass
43
 
 
44
 
    if os.name == "nt":
 
33
    if os.name == "windows":
45
34
        yield "notepad.exe"
46
35
    elif os.name == "posix":
47
 
        yield "/usr/bin/vi"
 
36
        try:
 
37
            yield os.environ["EDITOR"]
 
38
        except KeyError:
 
39
            yield "/usr/bin/vi"
48
40
 
49
41
 
50
42
def _run_editor(filename):
51
43
    """Try to execute an editor to edit the commit message."""
52
44
    for e in _get_editor():
53
45
        edargs = e.split(' ')
54
 
        x = call(edargs + [filename])
 
46
        x = os.spawnvp(os.P_WAIT, edargs[0],
 
47
                       edargs + [filename])
55
48
        if x == 0:
56
49
            return True
57
50
        elif x == 127: