Load JOY_HOME/definitions.txt
You still can't edit other text files from within the UI, but at least now you have a place to persist your own definitions over restarts. I thought about having a [definitions] section in the config INI file, but for some reason I prefer a separate definitions.txt file. I dunno. Might change it in future.
This commit is contained in:
parent
17b9fba65e
commit
4ed8422258
|
|
@ -29,7 +29,7 @@ _log.info('Starting with JOY_HOME=%s', JOY_HOME)
|
|||
|
||||
from joy.gui.textwidget import TextViewerWidget, tk, get_font
|
||||
from joy.gui.world import StackDisplayWorld
|
||||
from joy.library import initialize
|
||||
from joy.library import initialize, DefinitionWrapper
|
||||
from joy.utils.stack import stack_to_string
|
||||
|
||||
|
||||
|
|
@ -48,7 +48,6 @@ def repo_relative_path(path):
|
|||
os.path.commonprefix((repo.controldir(), path))
|
||||
)
|
||||
|
||||
|
||||
def commands():
|
||||
# pylint: disable=unused-variable
|
||||
|
||||
|
|
@ -112,6 +111,7 @@ JOY_FN = os.path.join(JOY_HOME, 'scratch.txt')
|
|||
LOG_FN = os.path.join(JOY_HOME, 'log.txt')
|
||||
D = initialize()
|
||||
D.update(commands())
|
||||
DefinitionWrapper.load_definitions(os.path.join(JOY_HOME, 'definitions.txt'), D)
|
||||
world = StackDisplayWorld(repo, STACK_FN, REL_STACK_FN, dictionary=D)
|
||||
defaults = dict(width=80, height=25)
|
||||
t = TextViewerWidget(world, **defaults)
|
||||
|
|
|
|||
|
|
@ -380,6 +380,13 @@ class DefinitionWrapper(object):
|
|||
_log.info('Adding definition %s := %s', F.name, expression_to_string(F.body))
|
||||
dictionary[F.name] = F
|
||||
|
||||
@classmethod
|
||||
def load_definitions(class_, filename, dictionary):
|
||||
with open(filename) as f:
|
||||
lines = [line for line in f if '==' in line]
|
||||
for line in lines:
|
||||
class_.add_def(line, dictionary)
|
||||
|
||||
|
||||
def _text_to_defs(text):
|
||||
return (line.strip() for line in text.splitlines() if '==' in line)
|
||||
|
|
|
|||
Loading…
Reference in New Issue