vim-pencil icon indicating copy to clipboard operation
vim-pencil copied to clipboard

Un-Initialize (Save + Restore Settings)

Open orbisvicis opened this issue 10 years ago • 4 comments

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.

orbisvicis avatar Apr 01 '15 05:04 orbisvicis

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?

reedes avatar Apr 01 '15 19:04 reedes

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 avatar Apr 01 '15 23:04 orbisvicis

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

orbisvicis avatar Apr 02 '15 19:04 orbisvicis

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.

reedes avatar Apr 03 '15 06:04 reedes