toot icon indicating copy to clipboard operation
toot copied to clipboard

Add vim modeline to EDITOR_INPUT_INSTRUCTIONS #231

Open sharils opened this issue 2 years ago • 1 comments

To solve #231, there are three options I can think of:

  1. Open the temp file again after calling subprocess.run, which adds overhead to all other text editors
  2. 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
  3. 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.

sharils avatar Dec 03 '22 07:12 sharils

@ihabunek Would you mind reviewing this? Thanks.

sharils avatar Dec 04 '22 00:12 sharils