diff options
| author | Mattias Andrée <maandree@operamail.com> | 2013-09-23 08:33:36 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2013-09-23 08:33:36 +0200 |
| commit | 240c405d78121400404344f3ba8f943043789f57 (patch) | |
| tree | e4cd20ab0d5cd734d08491a16236369b52e51b21 | |
| parent | only remove on up and down when needed (diff) | |
| download | pytagomacs-240c405d78121400404344f3ba8f943043789f57.tar.gz pytagomacs-240c405d78121400404344f3ba8f943043789f57.tar.bz2 pytagomacs-240c405d78121400404344f3ba8f943043789f57.tar.xz | |
rcfile support
Signed-off-by: Mattias Andrée <maandree@operamail.com>
| -rw-r--r-- | src/common.py | 45 | ||||
| -rw-r--r-- | src/editor.py | 2 |
2 files changed, 45 insertions, 2 deletions
diff --git a/src/common.py b/src/common.py index 3e4ee7b..1c25342 100644 --- a/src/common.py +++ b/src/common.py @@ -85,3 +85,48 @@ class Jump(): def __call__(self): print(self.string, end = '') + +def parsefile(file): + ''' + Parse a file name encoded with environment variables + + @param file The encoded file name + @return The target file name, None if the environment variables are not declared + ''' + if '$' in file: + buf = '' + esc = False + var = None + for c in file: + if esc: + buf += c + esc = False + elif var is not None: + if c == '/': + var = os.environ[var] if var in os.environ else '' + if len(var) == 0: + return None + buf += var + c + var = None + else: + var += c + elif c == '$': + var = '' + elif c == '\\': + esc = True + else: + buf += c + return buf + return file + + +for file in ('$XDG_CONFIG_HOME/%/%rc', '$HOME/.config/%/%rc', '$HOME/.%rc', '/etc/%rc'): + file = parsefile(file.replace('%', 'pytagomacs')) + if (file is not None) and os.path.exists(file): + with open(file, 'rb') as rcfile: + code = rcfile.read().decode('utf8', 'replace') + '\n' + env = os.environ + code = compile(code, file, 'exec') + exec(code, globals()) # TODO do the globals need to be set explicitly? + break + diff --git a/src/editor.py b/src/editor.py index a7dce59..c889cd7 100644 --- a/src/editor.py +++ b/src/editor.py @@ -34,8 +34,6 @@ from line import * -## TODO colours should be configurable with rc file -## TODO ring limits should be configurable with rc file ## TODO widthless characters should be ignored when calculating the size a text ## TODO implement undo history |
