asok / projectile-rails

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

feat(projectile-rails-choices): use all matches #126

Open danielma opened 6 years ago

danielma commented 6 years ago

Allow regular expressions with more than one match group, and concatenate them to create the final string.

This is useful for me for finding nested resources with similar paths, and building short selectors based only on the unique elements.

The best example is finding JS components inside the app/javascripts directory.

The application I work on has two main interfaces, one for admins, and one for regular consumers. So we have components both inside the app/javascripts/admin/components and app/javascripts/consumer/components directories.

With this change, I can do something like

(projectile-rails-find-resource
  "component: "
  '(("app/javascripts/" "/javascripts/\\(.+/\\)components/\\(.+\\).js$")))

and this will generate a list like

admin/money_input
consumer/money_input
shared/error_container
asok commented 6 years ago

Hi @danielma first of all I'm sorry for responding so late. Do you think that some of the built-in projectile-rails-find-.*-resource commands would improve from this change? If not I'm afraid I would not merge it. It's a smart solution but it would just make the code a bit more complex without any benefit.

@Silex what do you think?

danielma commented 6 years ago

@asok 🤔 honestly, no I don't think any of the built-ins would be improved by this change. I feel like my use case is common but not standard.

This is definitely a projectile-rails power user feature. I have a bunch of extra projectile-rails-find-* commands that I've defined for myself.

If it doesn't seem like it will benefit the project and you decide not to merge, no hard feelings. Thanks for taking a look