-
-
Save Muon/2561013 to your computer and use it in GitHub Desktop.
<snippet> | |
<content><![CDATA[ | |
#ifndef ${TM_FILEPATH/(([A-Za-z]+)\/src\/)|./\U(?1:$2_)\E/g}${TM_FILENAME/(([A-Z])([A-Z][a-z]))|(([a-z])([A-Z]))|([a-z])|(\.)/\U(?1:$2_$3)(?4:$5_$6)$7(?8:_)\E/g} | |
#define ${TM_FILEPATH/(([A-Za-z]+)\/src\/)|./\U(?1:$2_)\E/g}${TM_FILENAME/(([A-Z])([A-Z][a-z]))|(([a-z])([A-Z]))|([a-z])|(\.)/\U(?1:$2_$3)(?4:$5_$6)$7(?8:_)\E/g} | |
$0 | |
#endif | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<tabTrigger>guard</tabTrigger> | |
<!-- Optional: Set a scope to limit where the snippet will trigger --> | |
<scope>source.c++</scope> | |
<scope>source.c</scope> | |
</snippet> |
This is really handy, thanks!
It's not a major nuisance, but it seems the snippet doesn't handle names containing digits. In my Project called "HDF5Test", for a file named "MyClass.hpp the snippet generated TEST_MY_CLASS_HPP. Fixing this was easy by just adding 0-9
to the regular expression for TM_FILEPATH
.
For the filenames themselves it's harder. Currently If the name contains digits, no additional underscores will be created around them. I guess it's not clear at all how to decide to which part of a word a digit belongs. Most of the time it will belong to the part left of it, but in cases like MD2HtmlConverter.cpp
it's a word of its own, and in Split3Way.h
it might be seen as belonging to "Way". Perhaps the easiest way would be to isolate all numbers into their own "block". I experimented a bit but couldn't come to a working solution. Since you created the code, perhaps it's easier for you to figure something out. I'd really appreciate it.
Woah, blast from the past. Sorry, I didn't notice your comment at all. (Are there notifications for this? @_@) I unfortunately can't remember how this works any more. I might be compelled to reexamine this in the near future. I suggest trying to hijack the part which matches multiple capitals to match non-leading digits as well. That would probably solve your problem. Good luck!
Tested with camelCase, UpperCamelCase and under_score filenames. Also works properly with multiple capital letters:
ABCFoo.hpp
turns intoABC_FOO_HPP
. Tries to guess the project name by looking for the name of the first directory below a directorysrc
, outputs nothing if not found; this may need adjustment.