preservim / vim-pencil

Rethinking Vim as a tool for writing
Other
1.57k stars 38 forks source link

Un-Initialize (Save + Restore Settings) #30

Open orbisvicis opened 9 years ago

orbisvicis commented 9 years ago

If for whatever reason a file has been incorrectly detected as text, changing the filetype won't disable vim-pencil. The previous settings need to be save, then restored.

Perhaps :mkview in init(), with autocmd FileType * loadview followed be a delete-view-file-operation.

Though it might be simpler in the long run to individual save each option to a buffer-local dictionary?

This would also be useful when switching from code to embedded prose.

reedes commented 9 years ago

It's correct that a buffer initialized with pencil won't automatically uninitialize (restore to global settings) when the filetype changes. Currently, only a NoPencil command will do that.

Restoring to pre-initialization buffer settings (rather than global) could be an enhancement, but are there realistic use cases where you will have embedded prose in a code file that you'd be toggling Pencil from its local settings to some other set of local settings?

orbisvicis commented 9 years ago

No, my use case is more along the lines of false positives:

I don't save text files with extensions and I don't want to continuously set ft=text, so I've configured all non-new opened-from-disk files with unknown/undefined filetypes to text.

"Undifferentiated" new files eventually become either code or text on write, the latter after which pencil will kick in.

orbisvicis commented 9 years ago

Plus certain pencil features really would be useful with code if only they could be toggled on/off.

Also some relatively intrusive global settings are modified by pencil (including linebreak, wrap, wrapped-motion, ...). This makes it annoying to switch from prose to code without restarting vim. I assume this applies mostly to documentation writers, as well as those who edit multiple files using vim-internal file browsers and hardly exit vim.

In all, it would be nice if vim-pencil could be un-initialized.

On a side-note, the suggested configuration should be:

" vim-help &ft initially set to text, so test &buftype to avoid
" false-positives
augroup pencil
  autocmd!
  autocmd FileType markdown,mkd if empty(&buftype) | call pencil#init() | endif
  autocmd FileType text         if empty(&buftype) | call pencil#init() | endif
augroup END
reedes commented 9 years ago

While pencil does change a handful of global settings, linebreak and wrap shouldn't be among them. Those should be exclusively local to the current buffer. Are you seeing differently in a way that you can reproduce the problem?

Having to restart vim to disengage pencil would be a serious problem to fix, and so far I haven't experienced it myself or heard reports of it prior to yours.

The buftype check could be part of init to avoid engaging when help files are loaded.

I'll be revisiting pencil later this year to improve the blacklist implementation and will look at adding support for preserving and restoring local buffer settings. That'll be more precise than the crude revert-to-global.