Alternative solution for ftplugin
Closed this issue · 12 comments
Hi,
Instead of removing the default values of tabstop, etc. from ftplugin, I suggest instead to add a global variable that can be set by the user in the vimrc. Maybe something like this:
if !exists('g:vim_scala_own_settings') || !g:vim_scala_own_settings
setlocal textwidth=140
setlocal shiftwidth=2
setlocal softtabstop=2
setlocal expandtab
setlocal formatoptions=tcqr
endif
Thanks.
Would you be willing to set up a PR for this, and include what to do in the doc/scala.txt file?
Hi,
I have a simpler idea: why not just re-source
the user settings, if it exists.
let user_ftplugin = split(&rtp, ',')[0] . '/ftplugin/scala.vim'
if filereadable(user_ftplugin)
exec 'so ' . substitute(user_ftplugin, ' ', '\\ ', 'g')
endif
I'm not sure that's going to work. It assumes that people have the settings they want in their /ftplugin/scala.vim
. They could easily be global settings in their .vimrc
, or /after/ftplugin/scala.vim
.
Actually, there is even a simpler and idiomatic solution:
Consider java
, even if I create an ftplugin/java.vim
in my user directory containing set ts=8
, it will still be overriden by the distributed java ftplugin and the final result will still be set ts=4
. The only way to override ftplugin is to put the settings in after/ftplugin
.
So if vim already works that way, why should we create another solution.
The Java plugin in Vim distribution (or at least the 7.4 on my system) doesn't set tabstop.
You're right. The case still apply however, if the distributed ftplugin set tabstop, it cannot be overriden by the user ftplugin.
Is your argument that all user-specific configuration should go into ftplugins in after?
Since unlike indent and syntax, distributed ftplugin has no guard, it can only be overriden in after/ftplugins. I'm just saying that after/ftplugins is a working solution to override runtime or plugin ftplugins so no need to invent another method.
after/ftplugin/scala.vim is not a solution, at least, it does not work for me. Indent from scala-vim is evaluated after after/ftplugin/scala.vim which can easily be tested by putting echoes in both of them.
It prints out:
This is after/ftplugin
This is scala-vim
@ivan-cukic Have you tried with after/indent/scala.vim
?
after/indent/ works.
Still, I don't quite get the reasoning for this to be in the indent file. The only indentation specification that does this in vim's default package is ada, with clojure srtting the softtabstop.
I'd agree the tab settings aren't typically in the indent files, changed in 1f90f5e.
Re: the original issue suggestion, after/ftplugin/scala.vim
is definitely the usual way to achieve this, and/or autocmd FileType scala
if it's small stuff you'd keep in vimrc instead of more files. These should both now be possible following the change.
I think that makes everyone happy here, so closing.