drupal-sublimetext icon indicating copy to clipboard operation
drupal-sublimetext copied to clipboard

hook snippets should only grab up to the first '.'

Open ryanarmstrong opened this issue 12 years ago • 7 comments

When the hook code snippets grab the filename, they grab everything up to the last '.'

This works fine for any .module, .install etc but doesn't work anytime you have a file like modulename.views.inc etc as it creates:

function modulename.views($vars) {}

Here's a regular expression that changes that behavior: ^[^.]+(?=.)

I tried editing hook.sublime-snippet but it didn't seem to make a difference.

ryanarmstrong avatar Mar 22 '13 01:03 ryanarmstrong

Ok, so editing that file did end up working but my regular expression is a bit off. Regex isn't my strong suit.

ryanarmstrong avatar Mar 22 '13 01:03 ryanarmstrong

If you get a a fix for this, I'd definitely roll it in!

robballou avatar Mar 22 '13 14:03 robballou

I'll poke around. I should also note that I am on Sublime 3, so it's certainly possible that that is causing issues as well, being a beta and all :)

ryanarmstrong avatar Mar 22 '13 17:03 ryanarmstrong

I just pushed some changes to all the hooks that should fix this. I had forgotten that this was fixed in the generic "hook" snippet. Give it a try and let me know if it works for you.

Thanks,

Rob

robballou avatar Mar 27 '13 14:03 robballou

Howdy.. nice project :)

I actually had a suggestion related to this topic. I looks like the snippets currently use the active filename (minus suffix) to determine the proper function prefixes. On large projects things are often broken out into lots of files, so I was thinking it might be nice to take the top level module or theme directory name, like:

..../sites//themes/mytheme/overrides.php -> mytheme .../sites//modules/mymodule/preprocessors.php -> mymodule

I've been playing around with this, and the following expression seems to work:

${TM_FILEPATH/.+(?:\/|\\)(?:themes|modules)(?:\/|\\)(.+)(?:\/|\\).*/$1/}

I'm working on OS X/Linux, but I tried to put backslashes in for Windows also.

Just something to consider... :) Thanks...

Codelica avatar Mar 28 '13 19:03 Codelica

That's a really good idea. Hopefully I can play around with that soon and try it out!

robballou avatar Mar 29 '13 14:03 robballou

Actually that first attempt didn't take into account further directory nesting... Ooops.. but you can give this one a try. I imagine it could be optimized, regex is not my day job. :)

${1:${TM_FILEPATH/.+(?:\/|\\)(?:themes|modules)(?:\/|\\)([a-zA-Z0-9_]+)(?:\/|\\).*/$1/}}

Codelica avatar Mar 29 '13 16:03 Codelica