Eclipse-RCP: Hide lines of text permanently, keep correct line numbers - eclipse-rcp

I have text files which contain code inside an Editor. The user can run an analysis on a certain part of his code, which will result in a set of lines which should be hidden. Next I want to present the user with only the remaining lines, but with correct linenumbers, as from the original document. Possible solutions I thought of:
Open a new Editor which does not contain the hidden lines, but *somehow* still has correct line numbers
Hide the lines in the original editor, and offer a button for the user to 'unhide'. Probably a similar solution required as in 1.
I don't really know how to go about this. Folds would be a weird solution, because they can be unfolded individually, and seem to be more semantically tied to things like methods or classes. Also, simply creating a new document without the hidden lines results in wrong linenumbers.

Use a ProjectionViewer and reflection to invoke the private method ProjectionViewer.collapse(int offset int length). This method is only used internally to hide a certain portion of the text, by manipulating the ProjectionDocument (see http://eclipse.org/articles/Article-Folding-in-Eclipse-Text-Editors/folding.html).
After this, folding text in the editor using the annotations(the little +/- icons) WILL break everything, so this solution and regular folding are mutually exclusive.

Related

Adding line counter to a text field

I want to add a line counter to a textfield for a sort of text editor. Looking around, I've seen that a lot of questions on this topic are either unanswered, or do not answer in a satisfactory manner. Something like this How to add prefix widget on every new line in textfield in flutter? asks fundamentally the same question I am, however the only answer there is to create a new widget for each line.
This is one method that could be used, where I add new textfields in a list and build them in a row with their respective line number. However, this means I cannot have those textfields function on more than one line, and I will need to add more textfields each time a user wants to add enough text to make it overflow. The biggest flaw I see with this, though, is that it makes it harder (if not impossible?) to easily select and edit text as you would expect from a text editor, such as using the built in systems for a textfield.
Now, for my solution I am using https://pub.dev/packages/extended_text_field as a way to gain some functionality that I don't really want to take the time to figure out how to do on my own (embedded onClick callbacks for text), so it would be ideal if I could continue to use that without having to fork or even have to figure out how to write my own version.
The primary issue I'm running into is not necessarily getting the number of lines, which can be found using some solutions from How can I add line numbers to TextField on Flutter?, but rather how and where to show those line numbers.
As above, it's not really ideal to pair some number alongside a textfield and create a new textfield for each expected line. What would be ideal, however, is something like , where each line number is prefixed to the line built by the text field. For example, like this: . Something like the solution proposed in Add a prefix to every line in a multiline Text Input in Flutter? would not work especially well, because the solution there is to literally add string values to the textfield, which would require systems to clean the text, in addition to causing an unexpected ability to actually change the numbers (or other line prefix) by the user.
So -- is there any way to implement a line prefix for each line in a textfield? Would it be possible to override an InputDecoration (which allows creating the individual line prefix, but nothing more) to create a line prefix for each line drawn by the textfield? If not, exactly what would be needed to create this? I am familiar with flutter, but I am not quite as familiar with the lower level API's.

VS Code Refactoring: Change all occurences - but only in block scope

When using "change all occurences" in VS Code, it will just search the whole file for matches and change them. Is there a similar feature doing the same thing, but limiting it to function or block scope?
Let's take an example where I would need that: I'm having a React file with several components and want to refactor a class component to a functional component, so I'm changing all occurences of this.props to props. However, I obviously don't want to change all the other class components as well that are supposed to stay class components. :-)
This seems like such a standard use case, but I'm not able to find it anywhere in VS Code. If it's not possible (yet, or for some good reasons) is there another way to achieve what I'm trying to do?
Check out the 'Add Selection To Next Find Match' functionality. It allows you to highlight the first occurrence you'd like to change, then using a keyboard shortcut, highlight the next occurrence and so on until you've selected all the instances you want to change. When all to-be-changed occurrences are selected, you can edit the selected text normally. Just remember to hit the escape key a couple times after editing to return to a single cursor!
Here are the keybindings for the command, it's Cmd+d on Mac:
https://code.visualstudio.com/docs/getstarted/keybindings
I find it very useful when renaming variables, there's also a shortcut to skip occurrences (Cmd+k Cmd+d) in case there is text you don't want to change in between.

How to move selected code segment to the left in VS Code?

The question is, how do I move the selected block of code by one or several tabs, but not to the right (which is done by selecting a code and pressing Tab key), but to the left? Without selection each line one by one and deleting whitespace?
Moving parts of code from one place to another with differences in indent levels is a bit hard without knowing the shortcut.
What I mean (Imgur)
Thanks!
For what you want,
Shift+Tab
should do the trick. However, I would like to recommend this extension which I find easier to use when formatting blocks of text: Indent One space
Note however this extension only indents selections by exactly one space, forward or backwards.

comment out an interval in matlab through command line

I have a very long script in MATLAB (1500 lines) and want to test two different settings. To do so, I need to comment out some codes in a specific interval (e.g. form line 234 to line 255).
Is there a function in MATLAB that takes the intervals and comments/uncomments them automatically?
You can just highlight your code and click on the comment button. Highlight and click on uncomment to remove comment.In windows you may also use shortcut keys cntrl+r and cntrl+t. But yeah, the if else is a better idea but takes more time in the beginning to code in the if else.
I would agree with others that putting your code into a block surrounded by if-else would probably be a better solution than what you originally asked for.
But if you want to do it, you can use the following function:
function commentout(fromline, toline)
currentDoc = matlab.desktop.editor.getActive;
currentDoc.insertTextAtPositionInLine(sprintf('%%{\n'), fromline, 0)
currentDoc.insertTextAtPositionInLine(sprintf('%%}\n'), toline+1, 0)
This will work in most recent versions of MATLAB.
To uncomment, I think you'll need to do something a bit more complex, like getting the entire text from the active document, removing the specified comment lines, then setting the entire text back again (get, modify and set the Text property of the document).

ignore differences in syntax in beyondcompare

In a branch of code I have changed all of the code from obj.varname to obj("varname") and when I compare the code I would like to ignore these differences since varname is the same.
I have a regular expression that I think I need but unfortunately can't get the comparison to be ignored using Beyond Compare from Scooter
^obj\("\w*"\)|obj\.\w*$
I am following this tutorial http://www.scootersoftware.com/support.php?zz=kb_unimportantv3
So my question: is this even possible with beyond compare? If yes, please share a solution including either instructions or post your screenshots.
Beyond Compare 3's Professional edition supports this through its Text Replacements feature. If you've already purchased a Standard edition license you need to revert to trial mode to test it: http://www.scootersoftware.com/suppo...?zz=kb_evalpro
Load your two files in the Text Compare.
Open the Session Settings dialog from the the Session menu, and on the Replacements tab click New to create a new replacement.
In the Text to find edit, use (\w+)\.(\w+)
In the Replace with edit, use $1("$2")
Check the Regular expression checkbox.
The alternative would be to mark any instance of obj.varname and obj("varname") as unimportant. The basic steps would be this:
Load your two files in the Text Compare.
Open the Session Settings dialog from the Session menu, and on the Importance tab click the Edit Grammar... button.
In the next dialog click the New... button below the top listbox.
Change the Element name field to something useful (say, "PropertyAccess").
Change the Category* to List.
In the Text in list* edit, add these two lines:
obj.varname
obj("varname")
Click OK to close the Grammar Item dialog and then click OK again to close the Text Format* grammar item.
Uncheck "PropertyAccess" (or whatever you named it) in the Grammar elements listbox in the Session Settings dialog, then click OK to close it.
This approach isn't as flexible or clean. In the steps above you're matching specific, hardcoded object and variable names, so obj.varname is unimportant but obj.othervar isn't, even if it's aligned against obj("othervar"). If text on both sides is unimportant the difference will be unimportant; if one side is important it will be an important difference. So, with the above steps, obj.varname and obj("varname") will be unimportant everywhere, but it will work correctly since they'll either be matched to other cases that also match those definitions (and thus unimportant) or will be matched to something else that doesn't match that definition, which will be important and will make the difference important.
You can use regular expressions to match more general text categories, but you probably don't want to. For example, if you wanted to match all text that followed that pattern you could use these two lines instead:
\w+\.\w+
\w+\("\w+"\)
And then check the Regular expressions checkbox in the Grammar Item dialog so they're matched that way.
The upside/downside to that is that any text that matches those patterns is then unimportant. abc.newvar vs. def.varname would be considered an unimportant difference because both sides match the unimportant definition. That's good for things like comments or whitespace changes, but probably isn't what you want to do here.