diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index 1fb2dd9..f53f4a6 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -32,9 +32,7 @@ def bibentry_from_editor(conf, ui, rp): bibstr = templates.add_bib while again: try: - bibstr = content.editor_input(conf['main']['edit_cmd'], - bibstr, - suffix='.bib') + bibstr = ui.editor_input(initial=bibstr, suffix='.bib') if bibstr == templates.add_bib: again = ui.input_yn( question='Bibfile not edited. Edit again ?', diff --git a/pubs/config/spec.py b/pubs/config/spec.py index f13398c..50d2693 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -20,7 +20,7 @@ open_cmd = string(default=None) # if using a graphical editor, use the --wait or --block option, i.e.: # "atom --wait" # "kate --block" -edit_cmd = string(default=None) +edit_cmd = string(default='') [formating] diff --git a/pubs/uis.py b/pubs/uis.py index 0fb354d..d4eab53 100644 --- a/pubs/uis.py +++ b/pubs/uis.py @@ -1,5 +1,6 @@ from __future__ import print_function +import os import sys import locale import codecs @@ -29,6 +30,14 @@ def _get_encoding(conf): return conf.get('terminal-encoding', enc or 'utf-8') +def _get_local_editor(): + """Get the editor from environment variables. + + Use vi as a default. + """ + return os.environ.get('EDITOR', 'vi') + + def get_ui(): if _ui is None: return PrintUI(config.load_default_conf()) # no editor support. (#FIXME?) @@ -80,7 +89,7 @@ class InputUI(PrintUI): def __init__(self, conf): super(InputUI, self).__init__(conf) - self.editor = conf['main']['edit_cmd'] + self.editor = conf['main']['edit_cmd'] or _get_local_editor() def input(self): try: