I would like to extend the CDT plugin for eclipse, to show/hide lines of code which are matching some regex. I don't want to "fold" via foldingStructureProviders, I really want them to be not visible while preserving line numbers. I need line numbers for later work.
Does anybody know a good extension point of the cdt c editor for that?
Example:
1: int main(){
2: call_regex();
3: return 1;
4: }
After activated "Hide Button":
1: int main(){
3: return 1;
4: }
Deactivate "Hide Button":
Example:
1: int main(){
2: call_regex();
3: return 1;
4: }
Look up Segmented and Projected modes in Eclipse Editors.
For example, the ProjectionViewer which is extended by CDT's CSourceViewer.
Related
I would like to be able to create/write a command to fold all code in all open editors within visual studio code.
I believe I am very close.
I am using the "script commands" extension written by Marcel J. Kloubert
When I use the following script with 7 or so open editors in a single group. I achieve the following:
The open editor (at the time of execution) has its code folded
VSC will loop over the open editors
No other editor has its code folded
The script I am using:
// Fold all code in all open editors.
function execute(args) {
// Obtain access to vscode
var vscode = args.require('vscode');
// Set number of open editors... (future: query vscode for number of open editors)
var numOpenEditor = 20;
// Loop for numOpenEditor times
for (var i = 0; i <= numOpenEditor; i++){
// Fold the current open editor
vscode.commands.executeCommand('editor.foldAll');
// Move to the next editor to the right
vscode.commands.executeCommand('workbench.action.nextEditor');
// Loop message
var statusString = 'Loop ->' + i
// print message
vscode.window.showErrorMessage(statusString);
}
}
// Script Commands must have a public execute() function to work.
exports.execute = execute;
I have made an interesting observation, when I use the above script with 7 or so open editors with two groups or more. Something about switching to a new group will allow the command editor.foldAll to work. Note, that if a group has multiple editors, the only editor to fold its code is the open editor in the group. Thus, all other editors will not fold.
I also thought that maybe... the script needed to slow down, so I added a function to pause on every iteration. This did not turn out to work either.
Any help would be great!
You just need to make this function async and wait for the executeCommand calls to complete before moving on:
// Fold all code in all open editors.
async function execute(args) {
// Obtain access to vscode
var vscode = args.require('vscode');
// Set number of open editors... (future: query vscode for number of open editors)
var numOpenEditor = 5;
// Loop for numOpenEditor times
for (var i = 0; i <= numOpenEditor; i++) {
// Fold the current open editor
await vscode.commands.executeCommand('editor.foldAll');
// Move to the next editor to the right
await vscode.commands.executeCommand('workbench.action.nextEditor');
// Loop message
var statusString = 'Loop ->' + i
// print message
vscode.window.showErrorMessage(statusString);
}
}
// Script Commands must have a public execute() function to work.
exports.execute = execute;
I want IDA to automatically color lines in both the graph and text view for important instructions, for example wherever there is a call or xor instruction change the background color of each of those references to a certain color.
Here is what I am looking to achieve:
fig.1 graph view
fig.2 text view
I noticed you can go to Edit > Other > color instruction... from the main menu and this will allow you to change the background color of the selected instruction, but this does not change all of them and seems to only affect the current database.
How can I make IDA automatically color certain instructions such as call and xoras shown from the example images?
I want it to automatically work for any database I open.
You need to write an IDA plug in using IDAPython (python for IDA) or IDC (IDA scripting language which is very similar to C), the following code is in IDC:
#include <idc.idc>
static main(void)
{
auto currentEA;
auto currentMnem;
auto prevMnem;
auto currentOp;
prevMnem = "";
currentOp;
currentEA = FirstSeg();
currentEA = NextHead(currentEA, 0xFFFFFFFF);
while (currentEA != BADADDR)
{
currentMnem = GetMnem(currentEA);
//Highlight call functions
if (currentMnem == "call")
{
SetColor(currentEA, CIC_ITEM, 0xc7c7ff);
}
}
}
You can also refer to the opcodes' operands:
//Non-zeroing XORs are often signs of data encoding
if (currentMnem == "xor")
{
if (GetOpnd(currentEA, 0) != GetOpnd(currentEA, 1))
{
SetColor(currentEA, CIC_ITEM, 0xFFFF00);
}
}
Here is a guide from Hex Blog for using IDC plug-ins.
And here is a sample for similar script in IDA Python instead of IDC.
Is there any auto-complete shortcut or code-generation command in Android Studio that creates a stub
switch (myEnum){
}
statement containing all of the possible case statements for a defined enum as in Eclipse?
Put the caret on "switch", press Alt-Enter, select "Create missing 'switch' branches".
Enum.class
public enum
myEnum{
Item1,
Item2,
Item3,
Item4
}
EnumSwitchImplement.class
private Enum.myEnum mMyEnum;
switch(mMyEnum){
//put cursor here and press Alt + Enter
/*a box will come with option "create missing 'switch' branches"
select.*/
}
//your switch will convert to
switch(mMyEnum){
case Item1:
break;
case Item2:
break;
case Item3:
break;
case Item4:
break;
}
This works on Android Studio.
Haven't check on Eclipse. :)
Just place the mouse pointer over switch and then wait for some time. An yellow bulb will be shown as below. Click on that yellow bulb (or press ALT+Enter) and click on the option Create missing 'switch' branches option.
This will auto create the switch case-break statements as below.
Hope this helps someone.
I want to get line number from Visual Studio. Is it possible ? Thanks
You can use CallerLineNumberAttribute
public void DoProcessing()
{
TraceMessage("Something happened.");
}
public void TraceMessage(string message,
[CallerLineNumber] int sourceLineNumber = 0)
{
Trace.WriteLine("message: " + message);
Trace.WriteLine("source line number: " + sourceLineNumber);
}
// Sample Output:
// message: Something happened.
// source line number: 31
If you just want to display line numbers in the IDE (as in your screenshot), follow these steps (tested in VS2012):
On the menu bar, choose Tools / Options. Expand the Text Editor node, then select either All Languages or, if you want it for just a specific language, open the node for the language you're using. Then check the Line Numbers checkbox in the Display section.
More info here on MSDN.
I am using Vim to edit a Java file, but I find the way Vim formats Java files is very different from Eclipse.
If I select the following code and press =, Vim does not format the code the way I would like. Can anyone help me?
Before Format:
case RINGTONE_PICKED: {
Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
handleRingtonePicked(pickedUri);
break;
}
case PHOTO_PICKED_WITH_DATA: {
if (mPhotoEditorView != null) {
final Bitmap photo = data.getParcelableExtra("data");
mPhotoEditorView.setPhotoBitmap(photo);
} else {
// The contact that requested the photo is no longer present.
// TODO: Show error message
}
break;
}
After Format:
case RINGTONE_PICKED: {
Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
handleRingtonePicked(pickedUri);
break;
}
case PHOTO_PICKED_WITH_DATA: {
if (mPhotoEditorView != null) {
final Bitmap photo = data.getParcelableExtra("data");
mPhotoEditorView.setPhotoBitmap(photo);
} else {
// The contact that requested the photo is no longer present.
// TODO: Show error message
}
break;
}
This is what I want:
case RINGTONE_PICKED: {
Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
handleRingtonePicked(pickedUri);
break;
}
case PHOTO_PICKED_WITH_DATA: {
if (mPhotoEditorView != null) {
final Bitmap photo = data.getParcelableExtra("data");
mPhotoEditorView.setPhotoBitmap(photo);
} else {
// The contact that requested the photo is no longer present.
// TODO: Show error message
}
break;
}
Indentation in VIM (and in any other editor or IDE) is carried on by indentation rules coded by someone. There is no guarantee that any two system will follow same indentation practice, since there are different indentation practices around.
I also use VIM for minor editing Java files, and I'm not aware of any common alternative indentation script for Java, other than the one included in the official distribution. I you're familiar with VIM scripting you can try to edit the indentation script to your needs. It resides at $VIMRUNTIME/indent/java.vim.
By the way your example is a little uncommon. Using curly braces for cases of a switch statement is unnecessary. I guess VIM indentation scripts indent blocks by considering the block type and gets confused with this kind of uncommon blocks. Netbeans also get a little confused with this example, it aligns the case blocks in a reasonable way, but the closing curly brace of switch statement is completely out of alignment. That kind of odd behavior will not be so common with default VIM indentation. Actually if you remove the curly braces of the case statements VIM indentation aligns the statements quite well.