mirror of
https://github.com/neovim/neovim.git
synced 2026-04-02 13:49:27 +00:00
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>
41 lines
1014 B
VimL
41 lines
1014 B
VimL
" Tutor filetype plugin
|
|
" Language: Tutor (the new tutor plugin)
|
|
" Maintainer: This runtime file is looking for a new maintainer.
|
|
" Last Change: 2025 May 10
|
|
" Contributors: Phạm Bình An <phambinhanctb2004@gmail.com>
|
|
" Original Author: Felipe Morales <hel.sheep@gmail.com>
|
|
" Last Change:
|
|
" 2025 May 10 set b:undo_ftplugin
|
|
" 2025 May 12 update b:undo_ftplugin
|
|
|
|
" Base: {{{1
|
|
call tutor#SetupVim()
|
|
|
|
" Buffer Settings: {{{1
|
|
setlocal noreadonly
|
|
setlocal noundofile
|
|
|
|
setlocal keywordprg=:help
|
|
setlocal iskeyword=@,-,_
|
|
|
|
" The user will have to enable the folds themself, but we provide the foldexpr
|
|
" function.
|
|
setlocal foldmethod=manual
|
|
setlocal foldexpr=tutor#TutorFolds()
|
|
setlocal foldlevel=4
|
|
|
|
|
|
" Mappings: {{{1
|
|
|
|
call tutor#SetNormalMappings()
|
|
|
|
" Checks: {{{1
|
|
|
|
sign define tutorok text=✓ texthl=tutorOK
|
|
sign define tutorbad text=✗ texthl=tutorX
|
|
|
|
let b:undo_ftplugin = "setl foldmethod< foldexpr< foldlevel< undofile< keywordprg< iskeyword< |"
|
|
\ . "call tutor#EnableInteractive(v:false) |"
|
|
|
|
" vim: fdm=marker
|