a project-local spell file?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

a project-local spell file?

martin f krafft-2
Dear list,

I am working on a text which has a lot of jargon and words that do
not really exist. I do not want to add them to my own dictionary,
but would rather prefer to keep a local dictionary alongside the
text I am working on. Unfortunately¸ I cannot set spellfile in
a modeline.

Short of using ./.vimrc, which would require me to set exrc
globally, which I obviously don't want, can you think of another way
to achieve what I want? Ideally I would like vim to search for spell
files in the local directory before it consults runtimepath. Is this
possible?

--
martin | http://madduck.net/ | http://two.sentenc.es/
 
"america may be unique in being a country which has leapt
 from barbarism to decadence without touching civilization."
                                                        -- john o'hara
 
spamtraps: [hidden email]

digital_signature_gpg.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: a project-local spell file?

Christian Brabandt

Hi martin!

On Fri, 02 Nov 2007, martin f krafft wrote:

> Short of using ./.vimrc, which would require me to set exrc
> globally, which I obviously don't want, can you think of another way
> to achieve what I want? Ideally I would like vim to search for spell
> files in the local directory before it consults runtimepath. Is this
> possible?

Would something like this work?

,----
|  " source local .vimrc
|  if  filereadable(expand("%:p:h")."/.vimrc")
|      source %:p:h/.vimrc
|  endif
`----

regards,
Christian

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: a project-local spell file?

martin f krafft-2
also sprach Christian Brabandt <[hidden email]> [2007.11.05.2057 +0100]:
> Would something like this work?
>
> ,----
> |  " source local .vimrc
> |  if  filereadable(expand("%:p:h")."/.vimrc")
> |      source %:p:h/.vimrc
> |  endif
> `----

Isn't that what exrc basically does too? The problem is simply with
repositories where others can theoretically smuggle a .vimrc onto my
system and thus get me to execute arbitrary commands. There should
be another check, ideally a GPG signature verification. Can vim run
gpg and only source if the command returns with a zero exit code?
I should probably finally learn scripting, but I just don't have the
time right now...

--
martin | http://madduck.net/ | http://two.sentenc.es/
 
"wer in einem gewissen alter nicht merkt, daß er hauptsächlich von
 idioten umgeben ist, merkt das aus einem gewissen grund nicht."
                                                        -- kurt götz
 
spamtraps: [hidden email]

digital_signature_gpg.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: a project-local spell file?

Andy Kittner
On Mon, Nov 05, 2007 at 09:10:59PM +0100, martin f krafft wrote:

>also sprach Christian Brabandt <[hidden email]> [2007.11.05.2057 +0100]:
>> Would something like this work?
>>
>> ,----
>> |  " source local .vimrc
>> |  if  filereadable(expand("%:p:h")."/.vimrc")
>> |      source %:p:h/.vimrc
>> |  endif
>> `----
>
>Isn't that what exrc basically does too? The problem is simply with
>repositories where others can theoretically smuggle a .vimrc onto my
>system and thus get me to execute arbitrary commands. There should
>be another check, ideally a GPG signature verification. Can vim run
>gpg and only source if the command returns with a zero exit code?
>I should probably finally learn scripting, but I just don't have the
>time right now...
Why not just use something like
   au BufNewFile,BufRead *
      \ if filereadable(expand("%:p:h")."/foo.utf-8.add") |
      \    exe "setlocal spellfile=".expand("%:p:h")."/foo.utf-8.add" |
      \ endif

This would just set spellfile when you start editing a new file.
Also :he 'spellfile' says that spellfile accepts multiple values
separated by a comma, in case you want to use your global spellfile too.

Regards, Andy

--
One can search the brain with a microscope and not find the
mind, and can search the stars with a telescope and not find God.
                -- J. Gustav White

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: a project-local spell file?

Srinath Avadhanula-3
In reply to this post by martin f krafft-2

On Nov 5, 3:10 pm, martin f krafft <[hidden email]> wrote:

> Isn't that what exrc basically does too? The problem is simply with
> repositories where others can theoretically smuggle a .vimrc onto my
> system and thus get me to execute arbitrary commands. There should
> be another check, ideally a GPG signature verification. Can vim run
> gpg and only source if the command returns with a zero exit code?
> I should probably finally learn scripting, but I just don't have the
> time right now...

If you want to restrict it to certain directories, you can put the
following in your global .vimrc

augroup MySpell
  au!
  au BufNew /path/to/my/dir/** setlocal spellfile+=/path/to/my/dir/
spell.txt
augroup END

You can add other directories to it as needed.

HTH
Srinath


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: a project-local spell file?

Matt Wozniski-2
In reply to this post by martin f krafft-2
On Nov 2, 2007 2:02 PM, martin f krafft <[hidden email]> wrote:

> Dear list,
>
> I am working on a text which has a lot of jargon and words that do
> not really exist. I do not want to add them to my own dictionary,
> but would rather prefer to keep a local dictionary alongside the
> text I am working on. Unfortunately¸ I cannot set spellfile in
> a modeline.
>
> Short of using ./.vimrc, which would require me to set exrc
> globally, which I obviously don't want, can you think of another way
> to achieve what I want? Ideally I would like vim to search for spell
> files in the local directory before it consults runtimepath. Is this
> possible?

Perhaps I'm missing something, but isn't putting this into your .vimrc
a solution?

set spellfile=$HOME/.vim/spell/en.utf-8.add,/dir/to/project/en.utf-8.add

Then, to add a good word to your normal dictionary, you use zg,
to add a good word to your project dictionary, you use 2zg, and
and everything just works, right?

If you have many project that you'd like to do this for, though, I can
see how remembering to use a count might be tough.  In that case,
something like this ought to work:

--- SNIP ---

" Only waste our time for subdirectories of a directory matching our
" project's name
au BufNewFile,BufRead */projectname/* call SetupDictionary(expand("<afile>"))

function! SetupDictionary(file)
  let LANGS = [ "en.utf-8" ]

  " Get path to current file, expanding out "~" and "$HOME", etc
  let file = fnamemodify(expand(a:file), ':p:h')

  " Split it on /, keeping the separators
  let dirs = split(file, '/\zs')

  " Join it back together incrementally, so that we change
  " [ "/", "path/" , "to/"      , "myfile/"         ]  to
  " [ "/", "/path/", "/path/to/", "/path/to/myfile" ]
  for i in range(1, len(dirs)-1)
    let dirs[i] = dirs[i-1] . dirs[i]
  endfor

  " Then, for every directory up the path, plus ~/.vim/spell
  for dir in [ expand("~/.vim/spell/") ] + dirs
    " And for each possible dictionary language
    for lang in LANGS
      " If the directory contains a dictionary for that language
      if filereadable(dir . lang . ".add")
        " We remove that dictionary from its current position in
        " spellfile, if applicable, then add it at the beginning.
        exe "setlocal spellfile-=" . dir . lang . ".add"
        exe "setlocal spellfile^=" . dir . lang . ".add"
      endif
    endfor
  endfor

  " The end result is that for each buffer, the buffer-local
  " 'spellfile' contains every dictionary found in the walk up the
  " tree, plus the user one in ~/.vim/spell, so words found in any
  " will be recognized as good, and 'zg' will add words only to the
  " wordlist deepest in the tree, or the one in ~/.vim/spell/ if no
  " others are found.
endfunction

--- SNAP ---

Both only set the spellfile, so they're much less dangerous than
using :set exrc, and should take care of everything you need.
The more complicated solution might be a bit more user-friendly,
though.

~Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---