Author Topic: Cursor retrace macro  (Read 10543 times)

Graeme

  • Senior Community Member
  • Posts: 2136
  • Hero Points: 263
Cursor retrace macro
« on: February 08, 2009, 10:22:47 am »

Hi

Attached is some macro code that provides a cursor retrace and modified lines retrace facility.  Don't know if it's any use to anyone else but I use it a lot.  It's kind of beta/ use at your own risk software but even if it gives you a slick C stack error, you should still be able to save your files and restart slick.  By default, it doesn't start running when slick starts so if it gives you problems, restarting slick is one easy way to stop it running and the best way to recover.  If you find it reliable, you can configure it to start automatically when slick starts.  It's tested only on Windows XP and with slick 13.0.2/ 14.0.0.

Line markers with associated bitmaps are used to keep track of the cursor.  These bitmaps can be made "invisible" but sometimes, strange unwanted bitmaps turn up in the margin instead of the "blank/ invisible" bitmap.  I don't know the cause of this.  The visible bitmaps are mainly useful for debugging.

To load it, unzip all the files into a folder e.g. create a "macros" folder in your configuration folder, then load the following three files in this order
  DLinkList.e
  xretrace_popup.e
  xretrace.e

Use the "load module" command on the macro menu to load the files and the unload module command to remove them.  I recommend unloading these modules before upgrading to a new version of SlickEdit, since it's possible an error could occur if you let SlickEdit load them automatically.

At the start of xretrace.e there is some documentation on what it's all about and how to use it.

The main commands it provides are

 1. xretrace_modified_line    - go to the most recently modified line/region
 2. xretrace_cursor           - go to the most recent cursor location/region
 3. xretrace_modified_line_steps  - step through modified regions using an event loop
 4. xretrace_cursor_steps         - step through visited regions using an event loop

The keys that I bind to these are Ctrl-Alt-Right, C-A-Left, Alt-Shift-Up, C-A-Up respectively  - I don't have a use for the s-expression thing that these keys default to.

xretrace_cursor can be used to alternate between the last two places you've visited.

xretrace_modified_line goes to the last place where you modified code, except if you're already on the last line you modified, it goes to the second to last region you modified, so it also alternates between two places when you use it repeatedly.

It doesn't treat inserted lines as "modified" and it also doesn't register deleted lines as "modified regions".

The event loop versions produce a popup window reminding you of the "key bindings" in the event loop.

If you have "color modified lines" enabled, you might not want to use xretrace because it interferes with this  - read the documentation about it at the start of xretrace.e.  I endeavoured to compensate for this but since I personally don't normally have "color modified lines" enabled I'm not sure how big an issue this is.

DLinkList.e provides a doubly linked list "container" slightly similar to C++ STL list container.  It has some documentation at the start on how to use it.

xretrace_control_panel.e provides a configuration dialog for xretrace.  If you make changes to the code/dialog you might encounter a spurious Slick C stack problem from which the only way I know of to recover is to delete vslick.sta and reload the code.  I don't know the cause of this either but I've reported it to slick support.

The name xretrace was chosen to hopefully avoid any name clash with shipped Slick C code.

Graeme

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: Cursor retrace macro
« Reply #1 on: February 08, 2009, 10:30:26 pm »
sometimes, strange unwanted bitmaps turn up in the margin

That's not unique to your macro.  I have about ten 3rd party macros, but none of them do anything with margin bitmaps, and I see the same kind of problem just doing stock actions in the editor.  If I leave SE running for long enough and do enough stock editor actions that set/clear/etc margin bitmaps then eventually the margin bitmaps suddenly go awry.  The editor draws margin bitmaps at the right spots, but it just draws the wrong images at the right spots.

I'm just guessing here, but it smells like an index is getting thrown off somehow.  Maybe there's a niggly little bug tucked in a corner (maybe an edge condition is mishandled or something) in the part of the SE code that manages/draws the margin bitmaps.

I've seen it with 13.0.0, 13.0.1, and 13.0.2.  I'm pretty sure I also saw it with 12.0.3.  I can't say anything about earlier versions, because 12.0.3 is the first version I used.

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 285
Re: Cursor retrace macro
« Reply #2 on: February 09, 2009, 12:02:49 am »
Yep - this used to happen in v12.0.3 as well. But extremely rarely. - HS2

frank_lv

  • Community Member
  • Posts: 30
  • Hero Points: 0
Re: Cursor retrace macro
« Reply #3 on: April 09, 2009, 01:07:55 pm »
It is very powerful.
But I think it is too complex, May be a simple version is good, like source insight ,ue, vc .

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4405
  • Hero Points: 331
Re: Cursor retrace macro
« Reply #4 on: April 09, 2009, 02:54:31 pm »

...
Line markers with associated bitmaps are used to keep track of the cursor.  These bitmaps can be made "invisible" but sometimes, strange unwanted bitmaps turn up in the margin instead of the "blank/ invisible" bitmap.  I don't know the cause of this.  The visible bitmaps are mainly useful for debugging.
...

Graeme

We very recently found a bug in the display code having to do with bitmaps which likely explains why you are seeing some strange bitmap problems in the margin.  Yep, it's been around for a while. We just needed the right test case to reproduce it. The fix will be in 14.0.1

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: Cursor retrace macro
« Reply #5 on: April 09, 2009, 05:24:53 pm »
Awesome, thanks Clark!

Graeme

  • Senior Community Member
  • Posts: 2136
  • Hero Points: 263
Re: Cursor retrace macro
« Reply #6 on: April 09, 2009, 10:48:19 pm »
It is very powerful.
But I think it is too complex, May be a simple version is good, like source insight ,ue, vc .

Hmm, interesting comment.  I never thought about that.

Can you describe how a simple version would work?  What do VC and source insight do?

I'm guessing you want something that doesn't have 3 pages of obscure help information, no esoteric configuration options and maybe no popup menu.  (I've just noticed the F1,F2 help options in the popup menu are still giving problems in the last version I posted here http://community.slickedit.com/index.php?topic=4693.0).

Part of the problem is that the whole thing is a bit of a "kludge", tacked on to SE, and could be done a lot more easily in the SE core.  I had to describe the modified lines issue, the timer callback performance thing and the bitmaps problem because they might affect people.  Of the configuration options, the pause time and granularity options are the main things needed  - and most people probably wouldn't even want these.

Anyway, if you can describe how VC and source insight work that would be helpful.

Graeme

frank_lv

  • Community Member
  • Posts: 30
  • Hero Points: 0
Re: Cursor retrace macro
« Reply #7 on: April 10, 2009, 01:33:41 pm »
visual studio and source insight both have back and forward function.
back: Back to previous position
forward: forward to next position
do not need any menu.


Graeme

  • Senior Community Member
  • Posts: 2136
  • Hero Points: 263
Re: Cursor retrace macro
« Reply #8 on: April 10, 2009, 11:56:22 pm »
visual studio and source insight both have back and forward function.
back: Back to previous position
forward: forward to next position
do not need any menu.



Can you define "previous position".

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: Cursor retrace macro
« Reply #9 on: April 11, 2009, 12:15:10 am »
Graeme is being subtle.  The whole challenge in implementing this feature, is to define the positions.

SlickEdit has multiple ways to go to prev/next positions.
But the ways don't fit with what some people are looking for.
So the challenge is to accurately define precisely what is desired.

Saying "previous position = where the cursor was before" won't be detailed enough.
How long does the cursor need to be in a spot to count as having been there?
Should it track position on a per-file basis, or globally?
If you go to previous positions and then press Up, does that clear the list of next positions?  Or does the list of next positions not get cleared until you make a change to the file?
What signals that there is a "new position" to record?
Etc, etc.

Computers are pedantic, they need to be told exactly what to do.  So we have to figure out exactly what we want them to do, and then teach it to them in a flood of tiny words.  ;)

Graeme

  • Senior Community Member
  • Posts: 2136
  • Hero Points: 263
Re: Cursor retrace macro
« Reply #10 on: April 11, 2009, 02:25:57 am »

Quote
The whole challenge in implementing this feature, is to define the positions.

Yep.

From visual studio help

Quote
Use the Navigate Backward button to navigate to previously visited locations in the document, then use the Navigate Forward button to return afterwards. (You can also press CTRL + - to navigate backward and CTRL + SHIFT + - to navigate forward.) These buttons are particularly useful when using commands that take you far away from where you are currently working and you want to return to that location quickly. Examples of such commands are Incremental Search, Goto Line, Beginning of Document, End of Document, Pasting text or inserting file contents, and Go To Definition commands. The editor remembers locations when you move in a single command more than several lines away from where you are currently working, or if you edit in a particular location that is not adjacent to the last place you edited. The goal is to remember interesting locations so that you can recall where you have been working without remembering so many locations the feature is not useful (such as every character typed, or every line entering several new lines of code one right after the other).

It's hard to figure out exactly what VS strategy is but if I open a new file and put the cursor at the top, then hold the page down key down until I get to the end of the file, Ctrl + - takes me back up the screen one page at a time, even though I never stopped to look at anything.  Yet if I start at the top of the screen and use cursor down for a while, Ctrl + - takes me back to the very top, no matter how long I paused anywhere during the cursor down sequence.

It's hard to decide "what is an interesting cursor position that you might want to go back to."  So I made pause times and chunk sizes programmable and added a menu to allow staying within the same buffer or stepping from buffer to buffer and selecting one of two viewing granularities etc.

My strategy for stepping back and forwards along the list is different to VS.  With VS, if your history is 1 2 3 4 5 and you're now at position 5 and do Ctrl + - twice, you're now at position 3 but the list is still 12345.  Now if you go to some new position in the same file, say 6, then 7 then 8, - positions 6,7,8 seem to get inserted between 3 and 4.  The list is no longer in the order that you visited the code.

Whereas for me, I have one command (xretrace_cursor) that takes you back to the last cursor position (always at the top of the list).  Using xretrace_cursor repeatedly, alternates between the same two positions because if you're now at position A and you go to B, xretrace_cursor takes you back to position A because that's where you last were.   If you want to actually step along the list, you use xretrace_cursor_steps, which runs an event loop and makes no changes to the list until you exit.  The place where you exit is moved to the top of the list.  When the event loop is active, the popup menu is useful as a reminder that special key-bindings are in effect.

If I want to step back several places in the list it's because I'm looking for something and I don't mind having to hit a special key (ESC or ENTER) to indicate when I've got to where I want to go.

Possibly I could add commands that allowed you to step along the list without an event loop and with no list re-ordering - not sure exactly how it would work though.

Graeme

frank_lv

  • Community Member
  • Posts: 30
  • Hero Points: 0
Re: Cursor retrace macro
« Reply #11 on: April 11, 2009, 06:46:54 am »
I think there was a misunderstanding.
I think your macro functions same with visual studio.
'The simple version' means do not need show form and so on.
for example:
have two command: cursor_forward, cursor_back,
cursor_forward: same as visual studio navigate forward, bind key to 'Ctrl + Shift + -'
cursor_back: same as visual studio navigate back, bind key to 'Ctrl + -'

I think this is good, because the two functions been executed very frequently.
Do not need show Form. I think so.
Thanks your attention.

Graeme

  • Senior Community Member
  • Posts: 2136
  • Hero Points: 263
Re: Cursor retrace macro
« Reply #12 on: May 10, 2009, 10:13:59 am »
I think there was a misunderstanding.
I think your macro functions same with visual studio.
'The simple version' means do not need show form and so on.
for example:
have two command: cursor_forward, cursor_back,
cursor_forward: same as visual studio navigate forward, bind key to 'Ctrl + Shift + -'
cursor_back: same as visual studio navigate back, bind key to 'Ctrl + -'

I think this is good, because the two functions been executed very frequently.
Do not need show Form. I think so.
Thanks your attention.

Hi frank_lv

I don't think there was a misunderstanding - your comments were helpful.

I've added two new commands, xretrace_cursor_back and xretrace_cursor_fwd that might be more like what you're looking for.  http://community.slickedit.com/index.php?topic=4693.msg19933#msg19933

Graeme