Author Topic: Jump to last visited line?  (Read 5256 times)

ahodsdon

  • Community Member
  • Posts: 15
  • Hero Points: 0
Jump to last visited line?
« on: June 20, 2007, 06:24:24 pm »
Is there a way to jump to the last visited line that works recursively? Something akin to Ctrl-O in Vim? Or ctrl-Z, with the side-effect that it only undoes movement?

kenkahn

  • Community Member
  • Posts: 33
  • Hero Points: 1
Re: Jump to last visited line?
« Reply #1 on: June 20, 2007, 06:31:57 pm »
You can push the current line onto the bookmark stack via push-bookmark, then pop the lines in LIFO order, via pop-bookmark.  I've added ICONs for these, as well as toggle-bookmark, to my toolbar.

hs2

  • Senior Community Member
  • Posts: 2747
  • Hero Points: 288
Re: Jump to last visited line?
« Reply #2 on: June 20, 2007, 06:33:13 pm »
Ctrl-<COMMA> aka. pop-bookmark can be used.
Various code browsing / navigation functions leave (unnamed) bookmarks (see gutter) to go back by this command.
You can also call it directly (on cmdline) or by using a shortcut (if you defined one).

HS2

Edit: And the winner is ... kenkahn :) (I'm just too slow.)
« Last Edit: June 20, 2007, 06:35:06 pm by hs2 »

ahodsdon

  • Community Member
  • Posts: 15
  • Hero Points: 0
Re: Jump to last visited line?
« Reply #3 on: June 20, 2007, 07:47:10 pm »
Ah, but if I haven't pushed the bookmark on the stack ahead of time, it sounds like I'm out of luck, right?

Graeme

  • Senior Community Member
  • Posts: 2478
  • Hero Points: 325
Re: Jump to last visited line?
« Reply #4 on: June 20, 2007, 07:52:46 pm »
You can also use undo-cursor  - but it undoes all cursor movement so it takes you back to the place where you last made a change in the current source file.  I'm sure it wouldn't be hard for slick team to modify this a little to make an undo option that returned when the current line changed - i.e. a feature request would be worthwhile.

You could also try my goback facility in the GFileman toolbar package I posted in the macros forum.  It remembers where you've been but in "chunks" of 24 lines.  You could rebuild it with a different chunk size.  I have a newer version but due to being quite sick for a while I can't really post it at the moment, but I think the existing version doesn't have any major problems.  I think I've recently made a change so that when you "go back", it goes to the line in the chunk you were last on, rather than to the middle of the chunk.  I also went to the trouble of making the goback history persistent and it's remembered per project in a disk file if you enable a def_ option.

Graeme

ahodsdon

  • Community Member
  • Posts: 15
  • Hero Points: 0
Re: Jump to last visited line?
« Reply #5 on: June 20, 2007, 10:17:03 pm »
Thanks! Two good avenues to explore.

Graeme

  • Senior Community Member
  • Posts: 2478
  • Hero Points: 325
Re: Jump to last visited line?
« Reply #6 on: June 20, 2007, 10:34:45 pm »
Here's the latest revision of the goback source file in case it's useful.  I'm not sure what I changed.  It relies on a half second timer interrupt to sample the current line/file cursor location so if you move the cursor quickly it won't pick everything up, but then if you don't stay somewhere long enough to get it recorded, you probably don't want to go back there anyway.  It also works "across" different source files, unlike undo-cursor.

Graeme

ahodsdon

  • Community Member
  • Posts: 15
  • Hero Points: 0
Re: Jump to last visited line?
« Reply #7 on: June 20, 2007, 11:51:56 pm »
Great! I find the cross-buffer support in Vim very useful. Probably will in Slick, too.

Thanks again.

hs2

  • Senior Community Member
  • Posts: 2747
  • Hero Points: 288
Re: Jump to last visited line?
« Reply #8 on: June 21, 2007, 10:44:32 am »
@Graeme: Glad to see that you're alive and kicking again ! HS2

Graeme

  • Senior Community Member
  • Posts: 2478
  • Hero Points: 325
Re: Jump to last visited line?
« Reply #9 on: September 11, 2007, 02:10:26 am »

Dunno if anyone's using this code but just in case - I've found and fixed a couple of problems to do with the last_line thing I had recently added but not tested much.  Also, in step_thru_goback_history I've added an F7 key that toggles between goback through the "last_line" or "line" where "line" is the centre line of a "chunk" and last_line was the line the cursor was last on in that chunk.  If you've enabled def_goback_persistent_history then it's best to delete goback.dat from your config folder before loading the new file coz the previous version didn't include the "last_line" value in goback.dat but the new version expects it to be there  (don't really have time to handle this nicely at present).

The zip file includes the latest GFileman toolbar code which fixes a small number of things.  GFileman.e has the timer function GFileman_timer_callback() which calls GFH_maintain_line_buffer_goback_history(), so to use the goback mechanism you need to load both GFileman.e and GFilemanGoback.e or add you own timer code to GFilemanGoback.e.

Graeme

P.S. HS2, thanks, I'm alive but not kicking yet so dunno when I'll be back here regularly!