mtth / scratch.vim

Unobtrusive scratch window
MIT License
395 stars 32 forks source link

Weird scratch_persistence_file behavior #36

Open ljohnston opened 4 years ago

ljohnston commented 4 years ago

Hi,

I clearly must be doing something wrong, or I don't understand how persistence is supposed to work.

Given this vimrc:

set runtimepath^=~/.vim/plugged/scratch.vim
set nocompatible
filetype plugin indent on

let g:scratch_persistence_file=$HOME . '/scratch_test'

I can't get anything to show up in ~/scratch_test.

$ vim -u ~/.minimal_vimrc

Open scratch buffer with 'gs' Enter text / esc / c-w o / :q

~/scratch_test remains empty.

I've confirmed g:scratch_persistence_file is getting correctly set to scratch_test in my home directory (as an absolute path).

What am I doing wrong?

Thanks, Lance

emilford commented 4 years ago

@ljohnston Are you receiving an error by chance? I'm not sure if this is related to your issue, but I'm also recently seeing odd save behavior. I'm getting the error below, which is triggered here and I think may related to these lines. I can look at it more closely later.

Error detected while processing function <SNR>145_close_window:
line    3:
E13: File exists (add ! to override)
ljohnston commented 4 years ago

Hey @emilford - Nope, no errors. :messages after closing the scratch window shows nothing. I've also run with vim -V9vimlog -u ~/.minimal_vimrc and have attached the vimlog... no errors.

I did in some of my earlier testing see that same error you show above. Not exactly sure what the state of things was when I saw it though.

Thanks, Lance

vimlog.log

jalberto commented 4 years ago

I have the same issue using ~/.scratch.vim, if I put any content in that file (outside of vim) it shows up in the scratch, but I am not able to add new content

shuyangsun commented 3 years ago

@emilford I was able to resolve the strange saving behavior by changing :w to :w!, this seems to be an easy fix unless this will cause other problems?

addcninblue commented 2 years ago

It seems to me that saving doesn't occur if autosave is disabled. Saving happens in s:close_window 1, which is only called via autoload when autosave is enabled 2. It seems that the proper thing to do is to break out s:close_window into two separate functions that 1) saves and 2) closes if necessary, and have the autoload hooks in the appropriate places.

addcninblue commented 2 years ago

I have a fix here, if anyone wants to try. The fix isn't perfect; there's redundancy in saving files if the autoexit command is used. I'm not good with vimscript, so if anyone would like to refactor this, that would be greatly appreciated!

https://github.com/addcninblue/scratch.vim/commit/1406039d785878cbe7ceea9f0690eaf43d65c6f7