scratch.vim icon indicating copy to clipboard operation
scratch.vim copied to clipboard

Weird scratch_persistence_file behavior

Open ljohnston opened this issue 5 years ago • 6 comments

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

ljohnston avatar May 14 '20 18:05 ljohnston

@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)

emilford avatar May 15 '20 02:05 emilford

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

ljohnston avatar May 15 '20 03:05 ljohnston

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

jalberto avatar Aug 14 '20 11:08 jalberto

@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?

shuyangsun avatar Jan 08 '21 03:01 shuyangsun

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 avatar Dec 08 '21 23:12 addcninblue

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

addcninblue avatar Dec 08 '21 23:12 addcninblue