Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vim modeline to EDITOR_INPUT_INSTRUCTIONS #231 #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sharils
Copy link

@sharils sharils commented Dec 3, 2022

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.

To solve ihabunek#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.

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
Copy link
Author

sharils commented Dec 4, 2022

@ihabunek Would you mind reviewing this? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant