-
Notifications
You must be signed in to change notification settings - Fork 173
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
[Feature Request]: Set code window buffer to nomodifiable #360
Comments
You can do this with these auto commands if you want to. https://github.com/puremourning/vimspector#custom-mappings-while-debugging
In fact, personally I prefer the buffers to be modifiable, for instance so that hot code replacement works |
Here's an extension to the example in
|
I tried this out and I kind of like it. Not sure if that means it should be in the core though. I'm a little torn. will think on it. I've added it to my own custom layer and I'm going to see how I like it. |
Ah, i missed that, will definitely check it out.
That makes sense, but i think it would be neat if it at least was configurable. In my case when i use vimspector the code window is the only window to the source file open so it couldn't affected any other open windows, and being able to modify the source code while debugging statically compiled languages make little, if any, sense as far as i can see. |
it's configurable in the sense that you can customise it as above. it's extremely unlikely that I would make an option for this. I have resisted options for everything else so far :) |
The diff you sent does the trick. Except for that i wanted only the code window to be non-modifiable, which was solved by adding the line call win_gotoid( g:vimspector_session_windows.code ) This what i added to my .vimrc: let s:mapped = {}
function! s:OnJumpToFrame() abort
if has_key( s:mapped, string( bufnr() ) )
return
endif
let s:mapped[ string( bufnr() ) ] = { 'modifiable': &modifiable }
" Set nomodifiable for code window
call win_gotoid( g:vimspector_session_windows.code )
setlocal nomodifiable
endfunction
function! s:OnDebugEnd() abort
try
for bufnr in keys( s:mapped )
try
let &l:modifiable = s:mapped[ bufnr ][ 'modifiable' ]
endtry
endfor
finally
endtry
let s:mapped = {}
endfunction
augroup CodeWindowNoModifiable
au!
autocmd User VimspectorJumpedToFrame call s:OnJumpToFrame()
autocmd User VimspectorDebugEnded call s:OnDebugEnd()
augroup END Although, i'll admit i'm not sure whether or not all the logic around call win_gotoid( g:vimspector_session_windows.code )
setlocal nomodifiable in |
the win_gotoid should not be needed, unless there is a bug, as the current window should be the code window when the autocommand is triggered. Your OnDebugEnd is also busted because it doesn't set the current buffer. Then again, it can be simplified for your case by using function !s:onDebugEnd() abort
for buffer in keys( s:mapped )
call setbufvar( buffer, 'modifiable', s:mapped[ buffer ][ 'modifiable' ] )
endfor
let s:mapped = {}
endfunction |
Ah, yes that works. Thanks a lot :) let s:mapped = {}
function! s:OnJumpToFrame() abort
if has_key( s:mapped, string( bufnr() ) )
return
endif
let s:mapped[ string( bufnr() ) ] = { 'modifiable': &modifiable }
setlocal nomodifiable
endfunction
function! s:OnDebugEnd() abort
for buffer in keys( s:mapped )
call setbufvar( buffer, 'modifiable', s:mapped[ buffer ][ 'modifiable' ] )
endfor
endfunction
augroup CodeWindowNoModifiable
au!
autocmd User VimspectorJumpedToFrame call s:OnJumpToFrame()
autocmd User VimspectorDebugEnded call s:OnDebugEnd()
augroup END I agree that this is the way in which this should be configurable, so i'll go ahead and close this. |
Actually, using it a bit i noticed some strange behavior.
To be clear it works if i don't switch to the output window and enter some input. |
I can't reproduce. Not obvious why you are getting this, but you are certainly missing
Which exact window is this? |
Adding this didn't fix it :(
The one opened in the top right when starting vimspector (i use the default ui), containing the output of the program (i'm not sure how to give an exact answer). Here's a short C program that i am able to reproduce the issue with: #include <stdio.h>
int main(int argc, char *argv[])
{
printf("Please enter a number: ");
int input;
scanf("%d", &input);
printf("I received number %d\n", input);
return 0;
} |
I should aslo probably mention i use neovim.
I also tried disabling all plugins and remove all custom settings i have, but nothing worked. |
Oh sigh. I didn’t try neovim. Do you see the same behaviour in vim? |
Yes, i do :( Edit, vim version:
|
Ok thanks. Let me see if I can repro. |
https://asciinema.org/a/YB650ZRpePHVuG0bQyVCVvajd Sory no matter what I do, I can't repro in vim. If you think this is a vimspector bug, then please re-raise as an issue report, completing the issue template including steps to reproduce using minimal config. |
When starting the debugger the code window is modifiable, making it possible to do accidentaly changes to the code while debugging.
Instead i think the code window should be non modifiable, possibly through the
nomodifiable
option.It could be possible to do this myself automatically using some
autocmd
but i think it makes sense for vimspector to do this automatically.The text was updated successfully, but these errors were encountered: