mirror of
https://github.com/cosmo-sims/cosmICweb-music.git
synced 2024-09-19 16:53:43 +02:00
only run vim-specific arguments with vim
This commit is contained in:
parent
33d12b3082
commit
e011150809
2 changed files with 8 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
.venv
|
.venv
|
||||||
dist
|
dist
|
||||||
|
*.cfg
|
||||||
|
|
|
@ -22,6 +22,7 @@ logger.setLevel("INFO")
|
||||||
# Some constants
|
# Some constants
|
||||||
DEFAULT_URL = "https://cosmicweb.eu"
|
DEFAULT_URL = "https://cosmicweb.eu"
|
||||||
EDITOR = os.environ.get("EDITOR", "vim")
|
EDITOR = os.environ.get("EDITOR", "vim")
|
||||||
|
EDITOR_IS_VIM = EDITOR in {"vim", "nvim"}
|
||||||
|
|
||||||
|
|
||||||
# Types
|
# Types
|
||||||
|
@ -181,11 +182,14 @@ def fetch_publication(cosmicweb_url, publication_name, traceback_radius):
|
||||||
|
|
||||||
|
|
||||||
def edit_template(template):
|
def edit_template(template):
|
||||||
with tempfile.NamedTemporaryFile(suffix=".tmp", mode="r+") as tf:
|
with tempfile.NamedTemporaryFile(suffix=".tmp.conf", mode="r+") as tf:
|
||||||
tf.write(template)
|
tf.write(template)
|
||||||
tf.flush()
|
tf.flush()
|
||||||
# Call the editor. backupcopy=yes prevents vim from creating copy and rename
|
editor_parameters = []
|
||||||
subprocess.call([EDITOR, "+set backupcopy=yes", tf.name])
|
if EDITOR_IS_VIM:
|
||||||
|
# backupcopy=yes prevents vim from creating copy and rename
|
||||||
|
editor_parameters.append("+set backupcopy=yes")
|
||||||
|
subprocess.call([EDITOR] + editor_parameters + [tf.name])
|
||||||
tf.seek(0)
|
tf.seek(0)
|
||||||
template = tf.read()
|
template = tf.read()
|
||||||
return template
|
return template
|
||||||
|
|
Loading…
Reference in a new issue