asok / projectile-rails

Emacs Rails mode based on projectile
258 stars 59 forks source link

Only expand rails snippets in rails projects #139

Closed imtayadeway closed 5 years ago

imtayadeway commented 5 years ago

While most of these do not apply, I'm finding the require "rails_helper" in the spec skeleton a bit jarring when I'm creating spec files in non-Rails Ruby projects. Granted, this snippet allows me to specify which helper gets require'd, but I think I'd rather have a hook that gave me good defaults for non-Rails projects when I'm not in one, and this feels like the wrong place to introduce nuances like that.

asok commented 5 years ago

Apparently I only use my mode in the rails applications, that's why I've never experienced this issue.

Thank you for raising it.

But looking at your change I'm not sure if it's correct. Firstly projectile-rails-root is a function not a variable so it should raise an error. And to be honest, the most straightforward way for accomplish that should be:

@@ -1627,8 +1627,7 @@ If file does not exist and ASK in not nil it will ask user to proceed."
     (projectile-rails-set-assets-dirs)
     (projectile-rails-set-fixture-dirs)))

-(dolist (mode '(ruby-mode-hook enh-ruby-mode-hook))
-  (add-hook mode #'projectile-rails-expand-snippet-maybe))
+(add-hook 'projectile-rails-mode #'projectile-rails-expand-snippet-maybe)

I can't recall why I haven't do it that way. I have re-test this change and see if it works.

imtayadeway commented 5 years ago

@asok thanks for looking that over. Apparently I don't write much lisp these days, so thanks for spotting that. I updated with your suggestion - LMK if you need any other changes

asok commented 5 years ago

Now my elisp is rusty. It should be (add-hook 'projectile-rails-mode-hook #'projectile-rails-expand-snippet-maybe). That is 'projectile-rails-mode-hook instead of 'projectile-rails-mode.

imtayadeway commented 5 years ago

@asok ah thanks for checking! Amended and force-pushed

asok commented 5 years ago

Thanks!