~jeanfrancois.roy/bzr/url-safe-escape

« back to all changes in this revision

Viewing changes to bzrlib/msgeditor.py

  • Committer: Robert Collins
  • Date: 2005-09-27 07:24:40 UTC
  • mfrom: (1185.1.41)
  • Revision ID: robertc@robertcollins.net-20050927072440-1bf4d99c3e1db5b3
pair programming worx... merge integration and weave

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