From 49b2fed31a5664956d4c1d00c82cddecbc6b8055 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 13 Jun 2014 12:32:12 +0200 Subject: load rc file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/editor.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 3 deletions(-) (limited to 'src/editor.py') diff --git a/src/editor.py b/src/editor.py index 5148bac..17c7969 100644 --- a/src/editor.py +++ b/src/editor.py @@ -58,6 +58,11 @@ ALERT_COLOUR = None :str? The colour of the alert message ''' +KILLRING_LIMIT = 50 +''' +:int The maximum size of the killring +''' + atleast = lambda x, minimum : (x is not None) and (x >= minimum) ''' @@ -80,6 +85,73 @@ Check if a key stroke is a backspace key stroke ''' +g, l = globals(), dict(locals()) +for key in l: + g[key] = l[key] + + +## Load extension and configurations via pytagomacsrc. +config_file = None +# Possible auto-selected configuration scripts, +# earlier ones have precedence, we can only select one. +files = [] +def add_files(var, *ps, multi = False): + if var == '~': + try: + # Get the home (also known as initial) directory of the real user + import pwd + var = pwd.getpwuid(os.getuid()).pw_dir + except: + return + else: + # Resolve environment variable or use empty string if none is selected + if (var is None) or (var in os.environ) and (not os.environ[var] == ''): + var = '' if var is None else os.environ[var] + else: + return + paths = [var] + # Split environment variable value if it is a multi valeu variable + if multi and os.pathsep in var: + paths = [v for v in var.split(os.pathsep) if not v == ''] + # Add files according to patterns + for p in ps: + p = p.replace('/', os.sep).replace('%', 'pytagomacs') + for v in paths: + files.append(v + p) +add_files('XDG_CONFIG_HOME', '/%/%rc', '/%rc') +add_files('HOME', '/.config/%/%rc', '/.config/%rc', '/.%rc') +add_files('~', '/.config/%/%rc', '/.config/%rc', '/.%rc') +add_files('XDG_CONFIG_DIRS', '/%rc', multi = True) +add_files(None, '/etc/%rc') +for file in files: + # If the file we exists, + if os.path.exists(file): + # select it, + config_file = file + # and stop trying files with lower precedence. + break +# As the zeroth argument for the configuration script, +# add the configurion script file. Just like the zeroth +# command line argument is the invoked command. +conf_opts = [config_file] + conf_opts +if config_file is not None: + code = None + # Read configuration script file + with open(config_file, 'rb') as script: + code = script.read() + # Decode configurion script file and add a line break + # at the end to ensure that the last line is empty. + # If it is not, we will get errors. + code = code.decode('utf-8', 'error') + '\n' + # Compile the configuration script, + code = compile(code, config_file, 'exec') + # and run it, with it have the same + # globals as this module, so that it can + # not only use want we have defined, but + # also redefine it for us. + exec(code, g) + + class Jump(): ''' @@ -98,8 +170,6 @@ class Jump(): print(self.string, end = '') -## 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 @@ -133,7 +203,7 @@ class TextArea(): if height <= 0: height += int(screen_size[0]) - top + 1 self.fields, self.datamap, self.left, self.top, self.width, self.height = fields, datamap, left, top, width - 1, height self.innerleft = len(max(self.fields, key = len)) + 3 - self.killring, self.editring = Killring(), Editring() + self.killring, self.editring = Killring(limit = KILLRING_LIMIT), Editring() data = lambda field : datamap[field] if field in datamap else '' self.lines = [Line(self, self.fields[y], data(self.fields[y]), y) for y in range(len(self.fields))] self.areawidth = self.width - self.innerleft -- cgit v1.2.3-70-g09d2 From c901adccac0df375d367e0e59706736d504fd1e7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 13 Jun 2014 12:32:57 +0200 Subject: bump year MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- COPYING | 2 +- src/editor.py | 2 +- src/editring.py | 2 +- src/killring.py | 2 +- src/line.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/editor.py') diff --git a/COPYING b/COPYING index 2a5cf61..65e240b 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,6 @@ pytagomacs – An Emacs like key–value editor library for Python -Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) +Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/editor.py b/src/editor.py index 17c7969..d5fb96a 100644 --- a/src/editor.py +++ b/src/editor.py @@ -3,7 +3,7 @@ ''' pytagomacs – An Emacs like key–value editor library for Python -Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) +Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/editring.py b/src/editring.py index a71700c..3dcee08 100644 --- a/src/editring.py +++ b/src/editring.py @@ -3,7 +3,7 @@ ''' pytagomacs – An Emacs like key–value editor library for Python -Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) +Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/killring.py b/src/killring.py index b5275ac..eb80f27 100644 --- a/src/killring.py +++ b/src/killring.py @@ -3,7 +3,7 @@ ''' pytagomacs – An Emacs like key–value editor library for Python -Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) +Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/line.py b/src/line.py index 843e913..1355a38 100644 --- a/src/line.py +++ b/src/line.py @@ -3,7 +3,7 @@ ''' pytagomacs – An Emacs like key–value editor library for Python -Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) +Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit v1.2.3-70-g09d2 From cf2af6ef4a6754f324706d55aaf011f9e15e7ce7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 13 Jun 2014 12:35:09 +0200 Subject: make editring limit configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/editor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/editor.py') diff --git a/src/editor.py b/src/editor.py index d5fb96a..af1055f 100644 --- a/src/editor.py +++ b/src/editor.py @@ -63,6 +63,11 @@ KILLRING_LIMIT = 50 :int The maximum size of the killring ''' +EDITRING_LIMIT = 100 +''' +:int The maximum size of the editring +''' + atleast = lambda x, minimum : (x is not None) and (x >= minimum) ''' @@ -203,7 +208,7 @@ class TextArea(): if height <= 0: height += int(screen_size[0]) - top + 1 self.fields, self.datamap, self.left, self.top, self.width, self.height = fields, datamap, left, top, width - 1, height self.innerleft = len(max(self.fields, key = len)) + 3 - self.killring, self.editring = Killring(limit = KILLRING_LIMIT), Editring() + self.killring, self.editring = Killring(limit = KILLRING_LIMIT), Editring(limit = EDITRING_LIMIT) data = lambda field : datamap[field] if field in datamap else '' self.lines = [Line(self, self.fields[y], data(self.fields[y]), y) for y in range(len(self.fields))] self.areawidth = self.width - self.innerleft -- cgit v1.2.3-70-g09d2 From 69611077175687cc768b3b568b734f9f4ae721e2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 13 Jun 2014 12:40:30 +0200 Subject: m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/editor.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/editor.py') diff --git a/src/editor.py b/src/editor.py index af1055f..93b0bf7 100644 --- a/src/editor.py +++ b/src/editor.py @@ -18,6 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ''' +import os import sys import string from subprocess import Popen, PIPE @@ -90,11 +91,6 @@ Check if a key stroke is a backspace key stroke ''' -g, l = globals(), dict(locals()) -for key in l: - g[key] = l[key] - - ## Load extension and configurations via pytagomacsrc. config_file = None # Possible auto-selected configuration scripts, @@ -135,10 +131,9 @@ for file in files: config_file = file # and stop trying files with lower precedence. break -# As the zeroth argument for the configuration script, -# add the configurion script file. Just like the zeroth -# command line argument is the invoked command. -conf_opts = [config_file] + conf_opts +#g, l = globals(), dict(locals()) +#for key in l: +# g[key] = l[key] if config_file is not None: code = None # Read configuration script file @@ -154,7 +149,7 @@ if config_file is not None: # globals as this module, so that it can # not only use want we have defined, but # also redefine it for us. - exec(code, g) + exec(code, globals()) -- cgit v1.2.3-70-g09d2 From becdae4094c40e99d217c76c110e67d0506543ec Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 13 Jun 2014 12:45:09 +0200 Subject: m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/editor.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/editor.py') diff --git a/src/editor.py b/src/editor.py index 93b0bf7..0b49e77 100644 --- a/src/editor.py +++ b/src/editor.py @@ -131,9 +131,6 @@ for file in files: config_file = file # and stop trying files with lower precedence. break -#g, l = globals(), dict(locals()) -#for key in l: -# g[key] = l[key] if config_file is not None: code = None # Read configuration script file @@ -581,7 +578,7 @@ if __name__ == '__main__': # For testing return True area = None try: - area = TextArea(('a be se de e eff ge hå i ji kå ell emm enn o pe ku ärr ess te u ve dubbel-ve eks y säta å ä ö').split(' '), {}, 6, 4, 40, 10) + area = TextArea(('a be se de e eff ge hå i ji kå ell emm enn o pe ku ärr ess te u ve dubbel-ve eks y säta å ä ö').split(' '), {}, 6, 4, -6, -4) area.initialise(True) area.run(phonysaver) finally: -- cgit v1.2.3-70-g09d2