Can I Append Custom Highlights to an Existing Syntax Without Forking It? - sublimetext3

I'm looking to add a few custom syntax highlights to an existing one, but I don't want to maintain a copy of the base one I'm using in its entirety. Is there a way to extend an existing syntax (and continue to do so through updating, if possible) and just append a few new rules to it?
I've tried using extends: Packages/HTML/HTML.sublime-syntax in my own .sublime-syntax file, but I get a console error for "syntax inheritance does not allow for mixed versions" and I have no idea what that means. I don't see it mentioned in the documentation either. Help?

The Documentation on Syntax Definitions has a section on inheritance and how you do it; there a section on Limitations:
A syntax may extend a syntax that itself extends another syntax. There are no enforced limits on extending, other than that all syntaxes must share the same version.
version is a new concept in recent versions of Syntaxes; it's listed under compatibility. The general gist is that there are various things about syntaxes which are either bugs or unexpected/undesirable behaviour, but since there are so many syntaxes already available that would be broken if that behaviour was changed, the concept of version was added so that newer syntaxes can avail themselves of fixes.
As a result, as mentioned above all syntaxes must be the same version, ostensibly so that their behaviour is consistent. Syntaxes that are newly rewritten/revamped in Sublime Text 4 use the new version, and the HTML syntax is one of them.
Hence, you need to include version: 2 in your syntax to be able to extend the HTML syntax.

Related

Sublime 3 - Highlight variable in Perl/PHP string

I am turning to use Sublime3 instead of Notepad++. I have some concern when working with Perl/PHP or any kind of languages that use dollar sign for declare variable.
Here is an example, in Notepad ++:
As can be seen, "HELO $name" was displayed with different colors.
By that way, we can easily recognize there is a variable in the string.
In Sublime 3 , it looked like this:
So you can see there are no different between text and variable. It would caused confusion in some case.
May I know is there are any solution for this ?
Thank you and best regards.
Alex
This is self-promoting, but it will actually solve the problem
You may want to check out my Neon Color Scheme, available via Package Control. Its goal is to make as many languages as possible look as good as possible, and has hundreds of selectors that are specific for many different syntaxes, including Perl and PHP. Specifically, both languages support highlighting for string interpolation. Here is your code using Sublime's Perl syntax from dev build 3118, which should be very similar to the latest public build, which you should be using if you're not registered yet:
And here is the equivalent code in PHP:
Please note that these images were taken using a work-in-progress version of Neon, which I'm planning on releasing in the next day or so. The current version should look the same, as I don't think I've edited any of these scopes, but if not just let me know and I'll point you to the dev version.

Defining a vim syntax file that selectively applies other syntax files in different regions

Is there a way to define a syntax file in Vim that is essentially a "meta" layer on top of other syntax files? By this I mean that the file defines syntax highlighting regions, but all it does for each region is specify a different syntax file to be applied to that region. This is useful for PHP embedded in HTML, or any other sort of file mixing languages. I am aware that there are scripts that handle PHP and HTML together, but I don't think they do it in the manner I described. I'm interested in the general solution to this problem.
That's what :syntax include is for. With it, you can mark certain regions in the buffer, and apply the subordinate syntax in there. As long as the regions are clearly delimited and do not mix, this works pretty well. This is used for example in the HTML syntax to include JavaScript inside <script> tags, and Vimscript uses that for Perl, Python, and other integration languages. You'll find these scripts at $VIMRUNTIME/syntax/.
Alternative
My SyntaxRange plugin provides a different approach, where you can highlight certain regions with another syntax, without defining a separate new syntax. This is used for more adhoc markup, e.g. to highlight a Python snippet inside an HTML blog post, or to automatically highlight inline patches inside an email body.
Composite filetypes
Finally, there are add-on syntaxes that go "on top" of a main syntax. An example is cpp.doxygen. You cannot do that with arbitrary syntaxes, though; the script has to be specially written to support that.

How to change a variable name automatically across the project in VIM?

In eclipse, if you change a variable name, eclipse will automatically change this variable's name in whole project.
Can vim do that too?
Vim is a text editor, not an IDE. Though it has some notion of a filetype's syntax, it does not fully parse nor understand the language's full syntax. Refactorings, even simple ones like Rename identifier, do require such full understanding (to be 100% correct).
There are attempts at refactoring support in Vim, most language-specific, some also generic. But I'd advise to keep using a real IDE for this (for its comfort, safety, and correctness), and instead use Vim only for simple, text-based replacements, using :bufdo substitute/... or macros, as described here.
Sort of.
Because it is not an IDE and thus doesn't understand anything about your code, Vim only sees text where you see a variable name. It can't infer anything from the scope or whatever. Without the use of some external program, renaming a variable in Vim is usually done with a buffer-wide or project-wide search/replace.
Since you didn't tell us what language you are working with we can't tell you if there is a language-specific solution for your needs.
try this plugin -> Clighter, for c-family rename-refactoring. It's based on clang, but there are limitations. Still in development

VIM: hack ctags or tweak tagbar for better PHP support

Recently, i gave up Taglist for Tagbar. Tagbar works as expected for all languages except PHP.
It lists class, methods and variables into their respective categories instead of displaying methods and variables into their respective scope.
I came to know that ctags has poor support for PHP.
Is there any way to improve ctags and Tagbar's support for PHP? I am hopping for some kind of hack or tweak, or any other way around.
I have just using PHP_Parser as syntax parsing backend written a tool called phpctags to generate ctags compatiable index file and an addon plugin for tagbar called tagbar-phpctags to enhance the PHP suport for tagbar.
Methods and properties even local variables assigned in functions could be listed in their own scope now as well as their access information.
Maybe these could help.
Unfortunately there is no easy answer to this. The ctags PHP parser just uses regular expressions, and the result -- as you noticed -- is that support for scopes is missing.
There would be two ways to get proper scope support working: someone has to write either an actual recursive parser module for ctags, or some other program that can output tags in a ctags compatible format. That could theoretically even be written in PHP, which might make it easier -- maybe there already is some functionality available that allows access to the AST, which would then just need to be printed out in the correct format. But until someone does that I'm afraid there's no real way to properly display PHP scopes in Tagbar, since it has to rely on the information that ctags hands to it.

Is it possible to define custom naming conventions for resharper?

I'm using Resharper (with the StyleCop plugin, although I don't think that's relevant to the question/answer) to enforce naming conventions amongst other things in our code base. Pretty much everywhere this works brilliantly, with one exception.
For test method names I prefer the following convention:
ThingOrBehaviourUnderTest_Action_ExpectedOutcome
Currently this results in an inconsistent naming warning and to-date I've just ignored it (I know I can disable the warning in that file, but then it disables the warning for all any other naming inconsistencies). In the list of styles I can assign Resharper offers camel case, which would result in:
ThingOrBehaviourUnderTestActionExpectedOutcome
or underscore separated words:
Thing_or_behaviour_under_test_action_expected_outcome
Both are close to what I want, but not quite there. I guess I'm after a way of allowing underscores as valid characters in camel cased test method names, or a way of supporting a custom naming convention. Is this possible?
I know this question is pretty old, but ReSharper 7 now finally supports the definition of extended naming rules. Those make it possible to have separate name styles for test methods.
The AgentSmith plugin for ReSharper should meet your needs through its regex rule support.

Resources