Closed dstrunk closed 6 years ago
I'm somewhat confused. You seem to be referencing multiple things. Can you give a code example and surround the bit you want to highlight differently in <<<
and >>>
, e.g.,:
<?php
namespace App;
<<<final>>> class MyClass
{
}
sure (I admit the name phpUseFinalClass
needs some tweaking):
<?php
namespace <<<App>>>;
use App\<<<User>>>;
use Illuminate\Database\Eloquent\<<<Model>>>;
use Some\Other\<<<Class>>> as Alias;
use Some\<<<Class>>>, Another\Random\<<<Class>>>;
use One\More\{
<<<TestClass>>>,
<<<ForGoodMeasure>>>
};
Edit:
Here's a preliminary PR that will hopefully give a better explanation of what I'm shooting for: https://github.com/dstrunk/php.vim/commit/a4d1ab67d333a966f5e6d97e1dd6a7d589dd52f6
Okay, second try, GitHub just lost my original, long, comment. Try this:
syn keyword phpInclude namespace contained nextgroup=phpNamespaceName skipwhite skipempty
syn match phpNamespaceName /\(\\\|\h\w*\)*\h\w*/ contained contains=phpUseNamespaceSeparator skipwhite skipempty
syn match phpNamespaceOrUseClassName /\h\w*\(\_s*;\)\@=/ contained containedin=phpUseClass,phpNamespaceName,phpUseAlias
hi phpUseClassName guifg=#00c400
should get you this:
Awesome, thanks so much! Looks like I was overthinking regex per usual. This should get me pointed in the right direction for some of the other use-cases.
Would you be interested in a PR for this? You can close if not
This is the kind of thing that can live in the Snippets section of the README
. Let me know if you run into any edge cases.
I'm attempting to target the class name in a fully qualified class in a use statement for use in a colorscheme (https://github.com/tomasiser/vim-code-dark, for those interested). One key part of the colorscheme is the highlighting of the classname within a namespaced "use" statement, e.g.:
In the above, the targets are
App
,User
,Entry
, andModel
.I think I've got the regex required to target this bit of the use statement, but can't figure out how to implement:
/\(function\_s)+\)\@!\(\(\\\)\@<=\)\(\h\w*\)\(\(;\|\_s\)\@=\)/
could somebody point me in the right direction for implementing this? I've tried the following underneath the
" use statement
comment, as well as addedphpUseFinalClass
to the nextgroup underphpUseClass
:FWIW, I'm aware this regex isn't exhaustive for
{}
use statements, just trying to get a proof of concept done for a potential PR.