Problem:
`:Tutor` should open a copy of the tutor file instead of the original. This is
because edits modify the original file buffer, and crashes or other misuse could
potentially corrupt the original file even if it's WO.
Solution:
Copy the tutor file to a temp path before opening. Store the original path in
`b:tutor_file` so metadata json loading still works.
- `tutor#TutorCmd` will now copy the tutor file to a temp path via `tempname()`
before opening with `drop`. Store the original path in `b:tutor_file` only
after the buffer is created.
- `tutor#LoadMetadata` now uses `b:tutor_file` to resolve the JSON path instead
of `expand('%')`, which now points to the temp copy buffer
- `ftplugin/tutor.vim` does not make the `tutor#LoadMetadata` call anymore. It
was guarded by `filereadable(expand('%').'.json')` which fails for the new
temp copy path logic . Instead, `tutor#LoadMetadata` is already called
directly inside `tutor#TutorCmd` since we are already assumed to enable
interactive.
Co-authored-by: Phạm Bình An <111893501+brianhuster@users.noreply.github.com>
Problem: still some problem with the new tutors filetype plugin
Solution: refactor code to enable/disable tutor mode into
tutor#EnableInteractive() function, include a test
(Phạm Bình An)
I find it annoying that Tutor's interactive mode is always on (or debug
mode is off) even when I open a tutor file with :edit command.
I think it makes more sense to make this "interactive mode":
- Always on when it is opened with :Tutor command
- Off otherwise
For more references, see `:help` feature, it is a much better than
:Tutor, since I don't have to run `:let g:help_debug = 1` just to be able
to edit and save a help file
Therefore, I remove `g:tutor_debug`
closes: vim/vim#1729913bea589a2
Co-authored-by: Phạm Bình An <phambinhanctb2004@gmail.com>
- Set g:tutor_debug on startup if it doesn't exist so that users can get
cmdline completion when interactively setting it.
- set b:undo_ftplugin in filetype plugin
- set default runtime file headers
closes: vim/vim#172743704b5b58a
Co-authored-by: Phạm Bình An <phambinhanctb2004@gmail.com>
vim-tutor-mode provides a mechanism to write and read interactive
tutorials in vim. It's aim is to replace the venerable vimtutor with a
more modern system.
The plugin's development is maintained at https://github.com/fmoralesc
/vim-tutor-mode
Closes#2351.