toot
toot copied to clipboard
Add vim modeline to EDITOR_INPUT_INSTRUCTIONS #231
To solve #231, there are three options I can think of:
- Open the temp file again after calling
subprocess.run
, which adds overhead to all other text editors - Ask individual vim users to add
set backupcopy=yes
to their vimrc file, which requires every vim users to set backupcopy which isn't default - Change vim setting by adding modeline to the EDITOR_INPUT_INSTRUCTIONS, which adds couple more characters to EDITOR_INPUT_INSTRUCTIONS
It seems that option 3 is a middle ground between overhead and user experience, thus this PR.
To test:
#!/usr/bin/env python3
import subprocess
import tempfile
with tempfile.NamedTemporaryFile() as f:
f.write('\nvim:backupcopy=yes'.encode())
f.flush()
subprocess.call(['vim', f.name])
f.seek(0)
text = f.read().decode()
print(text)
P.s. Instead of rename the file and write a new one, backupcopy=yes
forces vim to make a copy of the file and overwrite the original one.
@ihabunek Would you mind reviewing this? Thanks.