Variable substitution in Pydev code templates - pydev

Pydev offers code templates when you create a new Python module. They include variable substitution such as ${my_variable}. How are these variables supposed to be given values?

Those "variables" are not user's variables.
Their whole list is available via button "Edit Variables...". This button appears when you edit a PyDev editor template (either creating a new one of modifying an old one). Their definitions are prefixed within PyDev. You should neither expect to define your own template variables nor expect to modify the definition of the already provided ones.

Related

Can one VS Code syntax scope reference another for theme purposes?

In VS Code, I'd like to have one textmate scope (e.g. punctuation.definition.variable) reference another one (e.g. variable.other.readwrite.global) so that the first element always uses the second element's color. Is that possible?
I am not interested in creating my own theme because I want these changes to be dynamic, to stay in effect regardless of what theme is in use. Specifically, the Perl syntax definition for $foo separates the sigil (e.g. $) and the variable name (e.g. foo) into two separate elements, and I would like to treat them as one.
In settings.json you can customize the editor workspace syntax highlighting with editor.tokenColorCustomizations and that will apply to every theme unless you specify it for some themes only.
Docs: https://code.visualstudio.com/docs/getstarted/themes#_editor-syntax-highlighting
Here you can find Docs for creating you own rule for syntax highlighting: https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide

Sublime Text 3: Auto-Complete uses incorrect syntax for for loop

With sublime text 3, the autocomplete when typing "for" and hitting tab gives you:
for x in xrange(1,10):
pass
However, this is not a valid statement for python 3. I've tried creating a new build system using the following:
{
"cmd": ["c:/Python37/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
the auto-complete for for still gives the wrong syntax. any advice?
The short version is that the sublime-build and sublime-snippet files that ship with Sublime in support of Python target Python version 2 and not Python version 3. I don't know if that's just due to that being what was used initially or if it's being done on purpose, though.
In Sublime, resources are generally related to a particular language based on the scope provided by the syntax definition. So for example snippets for Python are associated with source.python, your example build file uses that scope to know that it applies to Python files, and so on. As such, no matter what build you happen to be using, that has no effect on the snippets that are being offered.
By way of example, if you use the View Package File command from the command palette and enter the text python for snippet, the list of package resources will filter to Python/Snippets/for.sublime-snippet; pressing Enter to view that resource shows this:
<snippet>
<tabTrigger>for</tabTrigger>
<scope>source.python</scope>
<description>For Loop</description>
<content><![CDATA[
for ${1:x} in ${2:xrange(1,10)}:
${0:pass}
]]></content>
</snippet>
Here the tabTrigger specifies how the snippet inserts, scope controls where it inserts and content controls what it is inserts. Thus, in order to change it to support Python 3, you need to either create your own snippet or modify the existing one.
An issue with creating your own snippet is that it will be added to the list of snippets including the offending one, which allows it to possibly still trigger when you don't expect it to. There is also no general purposes "easy" way to disable individual snippets.
As such, generally the best course of action would be to use the PackageResourceViewer package. Install it, select PackageResourceViewer: Open Resource from the command palette, then select the same file as outlined above and modify the content of the snippet (e.g. replace xrange with range) and save the file.
That will get Sublime to replace the existing snippet with your edited version, so that it takes the place of the existing one and works the way you want.

Add parentheses around C-expression in Eclipse

Is there a way to select a C/C++ expression in Eclipse and put a bracket around it with a single keyboard shortcut? IDEs usually have this but I couldn't find a way in Eclipse.
For Java Code, there is a more or less good workaround described in Parentheses over selected words in Eclipse, but this does not work for C-Code - after bringing up the template list for the selection, the suggested templates are empty.
As far as I know, exactly that is not possible. You might report it to Eclipse CDT as a feature request.
But as workaround a template like the following can be used:
(${line_selection})${cursor}
If you hit Shift+Alt+Z the Surround With Quick Menu shows all templates containing ${line_selection} and with a number key a templated can be selected.
The key Shift+Alt+Z can be changed, but unfortunately no key can be defined to select the template directly. Also unfortunately, this does not work for multi-line selections because everything in the template in the line before ${line_selection} will be applied to each selected line.

How do I modify the EL opening template in Eclipse?

Whenever I am working in a JSP file and I type ${ to start an el (Expression Language) tag, Eclipse will automatically add } (with a space before the closing brace) after the cursor so that I get ${ } instead of ${}.
Is there a code template in Preferences that I can modify to change this behavior, or is it beyond user preference control?
I have checked in Preferences: Web: JSP Files: Editor: Templates, but none of those templates match. I've also looked in several other sections in Preferences but haven't found anything promising.
What #Mero provided (see comments on answer above) might not be an exact answer, but creating a JSP Template probably the closest thing that I've found.
A few notes for anyone that wants to go that route:
Create a new template through menu Window->Preferences, then in the drill down menu navigate to Web->JSP Files->Editor->Templates. Click New.
Name is a shortcut you can type (the same way typing sysout ctrl+space in Java is a shortcut for System.out.println()). I suggest something simple like el. This allows you to type e l ctrl-space instead of $ { ctrl-space to pull it up.
Context tells it when it should appear in intellisense. I suggest creating two of this template where one has a context of JSP Attribute value and the other has a context of All JSP.
Description is just informative. Put whatever you want. I put 'EL Script' myself.
Pattern is where you put what will be inserted. Put $${${cursor}} or $${${script}}, depending on preference. See below for explanation on the differences.
In Eclipse Templates ${} is how you put variables in the template, so to make it actually print ${} you have to escape the $ with a $$ leading to $${}.
The predefined variable ${cursor} defines where the cursor is after intellisense replaces the el, so to have the cursor appear in between the curly braces you want to do this: $${${cursor}}.
Using any variable that is not predefined (in this case, ${script}) will simply put in that variable with a box around it and allow you to type over it and press enter when you're done, allowing you to move to the end of the closing curly brace.
Note: I understand that this is not an actual answer, but rather is a workaround. I'm putting it here simply so that those who are fine with a workaround can know how to go about doing it.
Edit
For those that don't like having to type ctrl-space, a workaround could be to have the template name start with< since on JSP pages, the < opens the intellisense, so for instance, you could have the name be <el or <$.
A workaround but not an answer:
Disable auto-close of EL tags. You type ${expression} and get ${expression}|, rather than typing ${expression and getting ${expression| }. (| denotes the cursor location)
See this answer, from when this same question was asked of Eclipse Kepler: https://stackoverflow.com/a/20258401/1021426

Eclipse CDT variable colors in editor

I hope this is an OK question to ask here. It's programming related so I thought it would be better here than superuser. So I'm using the CDT C++ eclipse plugin. I know how to change the colors the editor uses for certain things. But is there a way to make it so all variables are DIFFERENT colors? For example in KDevelop, it sets local variables and class variables different colors and bolds class variables. Can I replicate that in CDT?
The Eclipse text editor offers some level of color customizations for syntax.
You can check it on: Window > Preferences > C/C++ > Editor > Syntax Coloring
There are several elements that can be changed, including Code, Assembly, Comments, Preprocessor and Doxygen.
Under Code, its possible to change the color of certain variable types, like global variables, local variable declarations, local variable references, and parameter variables.
But I don't think its able to change the color of every single variable you declared in the code. Maybe you can search for an Eclipse plugin to do that.