Simple way to add local spell file for a limited set of filesystem locations

237 views
Skip to first unread message

Tobias Klausmann

unread,
Jun 29, 2012, 9:29:35 AM6/29/12
to vim...@googlegroups.com
Hi!

I do a fair amount of LaTeXing, across a wider selection of
subjects. Since most of these subjects have their own jargon, I
usually add quite a few words to my local spell files (using zg).

The problem is that since there are a lot of acronyms, there is a
good chance that the spellchecker misses a typo because it is a
proper word/acronym in a different context/document.

So ideally, I'd be able to have a spell file per directory (this
would also make using version control easier). All this while
still using the user-global spell file in ~/.vim.

Algorithmically:

- Load system-global word lists*
- Load word lists from runtimepath*
- if there is a possibly empty local spellfile conforming to some
naming scheme, load it, implicitly creating the .spl file

When spellchecking
- When using zg/zw, use local-to-directory spell file, keeping
.spl up-to-date, of course.

If there is no dir-local spell file, just use the user-global
file (usually in ~/.vim).

While I'm sure I could come up with a vim script to do all of
this, I'd very much prefer to use something already done. My vim
script skills are waaaay rusty and why reinvent a wheel (badly at
that). Even better would to achieve this (or some close
approximation) using vim options.

Regards,
Tobias

Andy Wokula

unread,
Jul 16, 2012, 12:36:04 PM7/16/12
to vim...@googlegroups.com, klau...@schwarzvogel.de
The following is from the help:

:h 'spellfile'

string (default empty), local to buffer

Name of the word list file where words are added for the |zg|
and |zw| commands.

:h spell-load

Vim searches for spell files in the "spell" subdirectory of the
directories in 'runtimepath' ... Only the first file is loaded
... If this succeeds then additionally files with the name
LL.EEE.add.spl are loaded. All the ones that are found are
used.
LL the language name
EEE the value of 'encoding'

=> what you want should be possible.

You could add to ~/.vim/after/ftplugin/tex.vim:

let b:spellfile = expand('%:p:h'). '/myspell.latin1.add'
if filereadable(b:spellfile)
let &l:spf = b:spellfile
else
setl spf=
endif

This lets each tex file use the spell file myspell.latin1.add from its
directory. Example assumes encoding "latin1", and that setting the
option does not create the spell file yet ...

or (with b:undo_ftplugin):

let b:spellfile = expand('%:p:h'). '/myspell.latin1.add'
if filereadable(b:spellfile)
let &l:spf = b:spellfile
let b:undo_ftplugin .= '|setl spf<'
endif
let b:undo_ftplugin .= '|unlet! b:spellfile'

(warning: almost untested)

Vim automatically creates the .spl files.

--
Andy

Tobias Klausmann

unread,
Jul 16, 2012, 12:43:50 PM7/16/12
to vim...@googlegroups.com
Hi!

On Mon, 16 Jul 2012, Andy Wokula wrote:
> > While I'm sure I could come up with a vim script to do all of
> > this, I'd very much prefer to use something already done. My vim
> > script skills are waaaay rusty and why reinvent a wheel (badly at
> > that). Even better would to achieve this (or some close
> > approximation) using vim options.
>
> The following is from the help:
[...]
> => what you want should be possible.
>
> You could add to ~/.vim/after/ftplugin/tex.vim:
>
> let b:spellfile = expand('%:p:h'). '/myspell.latin1.add'
> if filereadable(b:spellfile)
> let &l:spf = b:spellfile
> else
> setl spf=
> endif
>
> This lets each tex file use the spell file myspell.latin1.add from its
> directory. Example assumes encoding "latin1", and that setting the
> option does not create the spell file yet ...
>
> or (with b:undo_ftplugin):
>
> let b:spellfile = expand('%:p:h'). '/myspell.latin1.add'
> if filereadable(b:spellfile)
> let &l:spf = b:spellfile
> let b:undo_ftplugin .= '|setl spf<'
> endif
> let b:undo_ftplugin .= '|unlet! b:spellfile'
>
> (warning: almost untested)
>
> Vim automatically creates the .spl files.

I'll definitely give it a go this week (yay, vacation time) and
report back.

Thanks a lot for coming up with this :)

Regars,
Tobias

Tobias Klausmann

unread,
Jul 27, 2012, 7:43:21 AM7/27/12
to vim...@googlegroups.com
Hi!

On Mon, 16 Jul 2012, Tobias Klausmann wrote:
> I'll definitely give it a go this week (yay, vacation time) and
> report back.

Definitely works. Had a bit of an issue with filetypes -- the
code for the spell file was not executed for my tex files, even
though syntax highlighting worked correctly. When I hand-added
ft=tex to the file's modeline, the code got executed.

So I checked what auto-detec ft vim used -- plaintex. I'm not
entirely sure what the purpose of this extra filetype is, but I
can live with setting the ft=tex via the modeline.


Regards,
Tobias

--
printk("%s: Boo!\n", dev->name);
linux-2.6.19/drivers/net/depca.c

Gary Johnson

unread,
Jul 27, 2012, 11:42:37 AM7/27/12
to vim...@googlegroups.com
On 2012-07-27, Tobias Klausmann wrote:
> Hi!
>
> On Mon, 16 Jul 2012, Tobias Klausmann wrote:
> > I'll definitely give it a go this week (yay, vacation time) and
> > report back.
>
> Definitely works. Had a bit of an issue with filetypes -- the
> code for the spell file was not executed for my tex files, even
> though syntax highlighting worked correctly. When I hand-added
> ft=tex to the file's modeline, the code got executed.
>
> So I checked what auto-detec ft vim used -- plaintex. I'm not
> entirely sure what the purpose of this extra filetype is, but I
> can live with setting the ft=tex via the modeline.

Put this in your ~/.vimrc,

let g:tex_flavor = "latex"

and Vim will set ft=tex instead of ft=plaintex.

Regards,
Gary

Tobias Klausmann

unread,
Jul 28, 2012, 9:04:53 AM7/28/12
to vim...@googlegroups.com
Hi!
Ah, and with that variable name I was able to find more
documentation about the flavors of TeX vim recognizes.

Thanks!

Regards,
Tobias

--
Sent from aboard the Culture ship
GCU It's Character Forming
Reply all
Reply to author
Forward
0 new messages