I am writing a macro, and I would like to determine if the current line where the cursor resides is a collapsed area or not. Can someone show me a way to do this?
Sure:
return false
Seriously though - the cursor can't reside in a collapsed region - you always see it. Put the cursor inside a method, then collapse the method, and the cursor jumps into the method definition. Uncollapse the method and the cursor stays in the definition.
Edit------------------
Reading your comment, it seems like there are some resourecs you can use, but nothing that fits exactly what you need. You could try using Edit.StopOutlining to turn off all collapsing, then run through the Macro. You could also take a look at the sample Macro "OutlineCode" which collapses code - and then try and change it to uncollapse code. There's also a MSDN article on that.
So a workable solution for me is to turn off outlining expansion, have the macro do its magic and then turn auto-outlining expansion back on. Thanks for the help!
Related
Is there a command/macro/keyboard shortcut that will expand the region where the cursor is and expand all collapsed regions inside it (recursively) ? if not can that be achieved ?
Short answer
As far as I know - No. There isn't a single shortcut that does that.
How to implement it by yourself
It's quite easy to create a plugin for Visual Studio that does exactly that:
Get the cursor location.
Store the 'start' and 'end' line numbers
For each line:
If it contains a region - expand it.
Few examples to begin with:
https://github.com/LeonalaDiantes/RegionsWasher
https://github.com/dnperfors/RegionExpander
https://github.com/fsdsabel/ExpandRegions
https://github.com/pauljmelia/regionsareevil
https://github.com/yasam100/CodeRegionsSnippets-VSExtension
Some of the projects are very close to the thing you have in mind, so you might even fork it and do your changes.
:-)
Another option
you might get the same result by using Macros for Visual Studio Editor/Recorder:
And then, write a macro like this one or maybe even record the steps you like to "run".
IMO, with recording and playing it will be a little harder to achieve.
but I'll be happy to be proved wrong.
I had the same problem, the following worked for me without having to make a macro or a plugin. Note, this is only a partial solution to the problem. I got it to expand recursively underneath a function, but I'm not sure how to reverse it (i.e. recursively collapse everything under the function again). To recursively collapse everything again, I could only figure to use (Ctrl+M, Ctrl+L), which collapses/expands everything in your file, but then you have to drill back down to the function you want.
Firstly, I got everything in a collapsed state by pressing (Ctrl+M, Ctrl+L). You may have to use that combination twice to get everything to collapse. Then I expanded a class and drilled down to the function I wanted to work on.
With the function in its collapsed state, I highlighted the single collapsed row it was on and pressed (Ctrl+M, Ctrl+M).
Doing so recursively expanded everything under the function.
I hope this partial solution helps someone who doesn't want to make a macro or plugin.
I believe ctrl + k followed by ctrl+] should unfold all subregions
replacing the ] with [ should fold all subregions.
When I'm working at someone else's code, sometimes it happens that I've found something useful that I likely will need to return later to.
Except the chances are that I forget where I've found that part and then I need to find it again. Nowadays I'm mostly using breakpoints to set these down, But I don't need these breakpoints for debugging, so I don't think that's the most efficient method. Something that could work for me is a sort of marker that functions marking down like a breakpoint, but does not affect debugging.
Will all these ways of breakpoints, search functions, finding references, and adding a Watches. I do have a feeling that such feature is present in Visual Studio already. But I havn't found it yet, I've already tried searching it up, but it looks like it hasn't asked before.
So, is there a feature in Visual Studio that let you mark down code like breakpoints, but just for the purpose of marking down?
There is more than one way to do so.
If I finde something interesting I mark it with a Bookmark.
Just STRG + K, STRK + K and it will be places on your current row.
With these Buttons you can switch to your bookmarks or delete them all. They are client based.
Visual Studio also gives you a "To Do List" Function. This one is triggered by comments in the code and seen for everyone with the right options used.
See here how it works in detail.
Yes, it's called a bookmark. This little toolbar is for bookmarks:
You can also use the Edit, Bookmarks... menu item and the View, Other Windows, Bookmark Window which among other things lets you see all of them and give them names.
One caveat: the bookmark binds to the line number, and doesn't move if you add or remove lines. So if you bookmark the first line of a function, then make changes above that, the bookmark won't be on the first line of a function any more.
I know about basic features of visual studio debugging. F10, F11, Shift+F11, Ctrl+F10.
If I am inside a for loop is there a way of stopping right after the loop is completed?
Right now the way I am doing it is to manually go to the location after the loop and press Ctrl+F10. Is there a better way of doing this?
There is no dedicated "Step Out of Loop" command in Visual Studio. "Step Out" (Shift+F11) works only for functions. There are only two options that I can think of:
Like Brian suggests, there is Run to Cursor, which has been there at least since VC++ 6. This is what you're already getting with the Ctrl+F10 keyboard shortcut. I use this literally all the time while debugging; it's an extremely useful tool. I don't really understand why you think this is a lousy way of doing it, or why you think there should be a "better" way.
You could set a simple breakpoint on the line of code immediately following the loop. This is relatively simple if you use the keyboard shortcut F9. But you still have to navigate to the appropriate line of code, so you might as well use Run to Cursor.
If you're working in a C-derived language, your loops probably conclude with a }. So you could use the Ctrl+] keyboard shortcut to move to the matching brace in the source file if your caret is at the loop's opening brace. That might make navigation easier. It certainly can help avoid moving your hands over to the mouse, killing precious seconds.
* Note that keyboard combinations are subject to change, depending on how you have configured your Visual Studio environment.
I just found out that if you hover with your cursor at beginning of the desired line, VS automatically blends in a little play symbol. When you click on it, debugger jumps to this point.
Perhaps you would like to use a breakpoint, which can be used to trigger the debugger once your program has reached a specific line. You can set one by clicking on the left side of the code line, where errors and arrows usually show up during debugging. Hope this helps!
Simple way is to put a break statement in the for loop and add a condition. This will allow you to test the loop while debugging.
When I extract a method in CodeRush, it has some default formatting. I'd like to change it. Specifically, when I choose the location of the extracted method, CodeRush smashes it in, directly above the method I put the location marker at.
So:
When I choose to drop the extracted method, like this:
It ends up looking like this:
What I want is for it to have some control over how the method looks, at the moment I want to add some blank lines between it and the next method. How can I do that?
Open the DevExpress -> Options dialog;
Go to the Editor | Code Formatting | Blank Lines option page;
Toggle the 'After multi-line members' option.
I requested this here: http://www.devexpress.com/Support/Center/p/S130722.aspx
It got implemented here: http://www.devexpress.com/Support/Center/p/S19229.aspx
There's now a massive formatting subsystem I spent 3 hours fighting that tries to outdo ReSharper's massive formatting subsystem which both need to be able to survive VS Autoformat (CtrlK D) and don't always.
Now you know it's there, I'd appreciate a quick summary from you as to whether you were able to make it do what you wanted!
Is it possible to view variable values in Eclipse when debugging? Right now when I "mouse over" a variable all I get is the definition.
e.g. for [int mLastView] I get [com.company.samples.MyClass.mLastView] instead of 1. The value that was assigned to it.
Also, is there anyway to improve debugging in Eclipse?
For starter: making the breakpoints visible as in VS (see below)?
Eclipse Break Point
Visual Studio Break Point
I posted this over at Stack Overflow and one of the suggestions was to go into Window -> Preferences -> Java -> Editor -> Hovers and select the Variable Values option and assign a modifier.
When I was first trying to resolve this issue, this was one of the options I looked at, but oddly enough, there was no Variable Values preference available, it was missing. Once my “fix” above was applied, it magically appeared:
Click to see the pictureBroken Link
Actually, since eclipse3.4, not only do you see the value of a variable when you pass the mouse over it, you can actually inspect it:
When debugging, hovers for variables have been enhanced to display an object inspector. The inspector will display logical structures according to the toggle setting in the visible Variables or Expressions view.
If you hit the breakpoint while you are debugging, you do see the value of the variable when you mouse over. You can also select an expression, and inspect the value of it's evaluation using the "Inspect" menu option. You can also use the "Variables" view to see the current value of all in-scope variables.
About breakpoint visibility:
Right-click on the right outline of the editor, you'll see some Preferences, and there in Annotations you can select Breakpoints. I personally added Text as Highlighted and some pinky colour. Shame that the highlighting is really buggy, sticks here and there, breaks between lines, etc. But it somehow works for most cases.
(Another shame is that breakpoint bullet is often hidden behind some suggestion icon or what - why they can't make the gutter wider like Idea does, I don't know.)
I got similar but a little different problem with the thread-starter. Sometimes during debugging, I mouse over a variable, I see it current value. Sometimes it's just the definition, like in coding mode. So what caused the first case, what the second?
PS: Of course I can always choose to view Variables (Alt+Shift+Q,V) but it's faster if you have mouse over value instantly.
Thanks