tpope / vim-rails

rails.vim: Ruby on Rails power tools
http://www.vim.org/scripts/script.php?script_id=1567
4.11k stars 384 forks source link

"Not allowed in sandbox" while defining navcommands in config/rails.vim #195

Closed jumski closed 11 years ago

jumski commented 11 years ago

Hi!

I want to have project-specific navcommands (3 of last backbone-js projects i was working on have different convention for storing models/views/collections).

I have created config/rails.vim file and put some navcommand definitions there:

autocmd User Rails Rnavcommand jcollection app/assets/javascripts/backbone/collections/ -glob=**/* -suffix=.js.coffee                                                         
autocmd User Rails Rnavcommand jmodel app/assets/javascripts/backbone/models/ -glob=**/* -suffix=.js.coffee                                                                   
autocmd User Rails Rnavcommand jview app/assets/javascripts/backbone/views/ -glob=**/* -suffix=.js.coffee                                                                     
autocmd User Rails Rnavcommand jrouter app/assets/javascripts/backbone/routers/ -glob=**/* -suffix=.js.coffee                                                                 
autocmd User Rails Rnavcommand template app/assets/javascripts/backbone/templates/ -glob=**/* -suffix=.hbs

I've got this error while starting vim:

Error detected while processing /home/jumski/work/ebookmakr/config/rails.vim:                                                                                                 
line    3:                                                                                                                                                                    
E48: Not allowed in sandbox: autocmd User Rails Rnavcommand admin app/admin/ -suffix=.rb

Do you know if it is possible at all? Where to look for solution?

Thanks in advance

tpope commented 11 years ago

This problem is near and dear to me. First, a workaround:

autocmd User Rails exe 'source ' .
      \ fnameescape(rails#app().path('config/myunsafecommands.vim'))

Basically, :sandbox source config/rails.vim is a crude hammer to swing at the problem of allowing a safe way to provide per-project configuration. I don't think it's a good idea to drop the :sandbox and allow arbitrary code to be executed.

I think probably the best solution is a new config file, config/vim.json or some such (JSON because it's relatively easy to parse in Vim):

{
  "navcommands": {
    "jcollection": {
      "path": "app/assets/javascripts/backbone/collections",
      "glob": "**/*",
      "suffix": ".js.coffee",
    }
  }
}

The navigation code is pretty old (it's still written with Vim 6 compatibility in mind, ugh), so I've been reticent to tackle this. But I want it just as bad as you do.

tpope commented 11 years ago

Okay, I made a first pass at this. Went with a dumb data structure inside of config/rails.vim. Details are subject to change. Give it a spin!

jumski commented 11 years ago

Great!

Wanted to test it immediately, so I updated my rails-vim and put following into config/rails.vim:


let b:rails_file_types = {
      \ 'jmodel': {
      \   'prefix': ['app/assets/javascripts/backbone/models'],
      \   'suffix': '.js.coffee',
      \   'affinity': 'model'}}

It looks like it is not sourced, :Rjmodel is not working and i cannot inspect this variable with let b:rails_file_types

First i thought maybe neo-bundle fucked something up and i do not have recent commits for vim-rails, but looking into :help rails I have confirmed that i have recent version, so I assume problem is somewhere else.

Do you have any ideas? Thanks! Wojtek

tpope commented 11 years ago

Try with a fresh Vim instance.

On Sat, Jan 5, 2013 at 2:22 PM, Wojtek Majewski notifications@github.comwrote:

Great!

Wanted to test it immediately, so I updated my rails-vim and put following into config/rails.vim:

let b:rails_file_types = { \ 'jmodel': { \ 'prefix': ['app/assets/javascripts/backbone/models'], \ 'suffix': '.js.coffee', \ 'affinity': 'model'}}

It looks like it is not sourced, :Rjmodel is not working and i cannot inspect this variable with let b:rails_file_types

First i thought maybe neo-bundle fucked something up and i do not have recent commits for vim-rails, but looking into :help rails I have confirmed that i have recent version, so I assume problem is somewhere else.

Do you have any ideas? Thanks! Wojtek

— Reply to this email directly or view it on GitHubhttps://github.com/tpope/vim-rails/issues/195#issuecomment-11918366.

tpope commented 11 years ago

Oh, far more likely explanation. You need modelines enabled now. What does :verbose set modeline? report.

jumski commented 11 years ago

That was a modeline thing.

Now everything works like a charm.

Thanks :)

tpope commented 11 years ago

Decided on a different approach: https://github.com/tpope/vim-rails/commit/8d10657107f56f19c9010cfb12c8705d101452e0

The config/rails.vim way still works for now, but I'm probably going to yank it.

tpope commented 11 years ago

Aaaand renaming classifications to projections. I never liked classifications: It makes me think of OO classes.

jumski commented 11 years ago

im creating config/environment.rb and config/editor.json like crazy ;] using it for non-rails projects too

thanks:)

tpope commented 11 years ago

Yep, there's definitely another plugin hiding in all this, which is why I've started a very slow transition from :Rmodel to :Emodel, :RSmodel to :Smodel, and so on. No reason to use R in a non-Rails app.

tpope commented 11 years ago

Annnd I've completely changed the format and file name. I'd appreciate it if you'd try migrating and let me know if you have any issues. You'll be a good test for if the docs are clear. It should be straightforward, if a bit tedious.

It's backwards compatible, so you don't have to switch all your projects at once.

jumski commented 11 years ago

Just migrated my main project's editor.json. It was not working when i renamed editor.json to projections.json (commands were not defined), but it works with old name (i've pull-rebased vim-rails of course:)).

One thing worth adding to docs is that all the projections-related stuff should go under root projections key in the json, because now it is not clear enough for a newcomer and it must be guessed. I've found no other issues tho.

Migration seems to be pretty straightforward. This thing rocks and saves hundreds of keystrokes, What more can i say - I really enjoy it, thank you:)

tpope commented 11 years ago

It doesn't go under the projections key when you use projections.json. Which is probably why it didn't work for you. :)

jumski commented 11 years ago

Haha. Confirmed :)

paulodelgado commented 11 years ago

Hmpf, I'm having a similar problem whilst migrating from config/editor.json to config/projections.json

https://gist.github.com/74a1c50f75c34b27364a

Projections are just not loading - :cry: (I have a fresh install of vim via Homebrew and vim-rails@master)

jumski commented 11 years ago

Hey!

Syntax you have used is a vim lang - you can place it in your vimrc. If you want to use config/projections.json, use pure json object, not a vim variable