TIP: Click on subject to list as thread! ANSI
echo: semware
to: All
from: Michael Graham
date: 2003-01-24 13:52:24
subject: [TSEPro] Re: Retracing the cursor position locations

From: Michael Graham 
@Date: Thu, 23 Jan 2003 22:22:24 -0500
@Sender: semware-owner{at}sawasdi.apana.org.au




> I'm thinking I might play around with undojump to see if it can be made
> to use bookmarks internally for its position stack.  Since I practically
> never use bookmarks myself, the loss of them for other purposes wouldn't
> affect me.

Here's a first stab at UndoJump_bk, a variation on Carlo Hogeveen's
UndoJump macro.  This version uses a slightly different approach -
it implements the history stack in terms of bookmarks.  Mostly just a
proof of concept, and not widely tested yet.  Differences from
UndoJump are:

    * positions in the history are immune to text editing changes

    * you can have a few more positions in the stack (up to 26 if you
      don't normally use bookmarks)

Carlo, you are welcome to include this version in your UndoJump package,
if you think that would be a good idea.  Or it could be spun off into
its own project.  Note that in addition to the bookmark code, I also
messed with the idle sensitivity mechanism, which may improve (or
degrade) timing on other people's systems :)


    /*
       Macro   :  UndoJump_Bk

       Based on:  UndoJump
       Author  :  carlo.hogeveen{at}xs4all.nl
       Date    :  22 May 2001

       UndoJump_Bk is a modification of UndoJump which uses bookmarks
       internally to maintain positions in the undo history.  This means:
           * positions in the history are immune to text editing changes
           * you can have more positions in the stack (up to 26 if you
             don't normally use bookmarks)

       modifications by:  Michael Graham 
       modification date: 23 Jan, 2003

    */

    // Here's where you change the range of bookmarks used by this macro. TSE
    // provides 26 bookmarks from a-z.  You can use all of them here, or
    // reserve some for your own use. By default this macro uses
    // bookmarks K to Z, i.e. the last 16 bookmarks,  leaving you with the
    // first 10.

    string bookmark_start[1] = 'k'
    string bookmark_end[1]   = 'z'

    // Check each N/18 seconds of no activity.
    integer macro_reaction_speed  = 18

    // Check if the cursor moved N lines.
    // If N == 0, then N is set to be just larger than a PageDown/PageUp.
    integer lines_moved_criterium = 0

    // Here starts the program.
    // Touch at your own risk, except for the key definitions at the bottom.

    integer old_bufferid       = 0
    integer old_line           = 0
    integer lines_moved        = 0
    integer last_ticks         = 0

    constant ASC_A = 97
    constant ASC_Z = 122

    #define DEBUG_JUMPS FALSE
    #define DEBUG_TICKS FALSE

    //----------------------------------------

    integer stack_pos    = 0
    integer stack_base   = 0
    integer stack_size   = 0
    integer stack_end    = 0
    integer stack_first  = 0
    integer stack_last   = 0


    #if DEBUG_JUMPS
    proc dump_stack (string msg)
        UpdateDisplay()
        Message(
        msg
        + "; [pos: " + Str(stack_pos) + "
("+Chr(stack_pos)+"); "
        + " first: " + Str(stack_first) + "
("+Chr(stack_first)+")"
        + " last: " + Str(stack_last) + "
("+Chr(stack_last)+")"
        + " base: " + Str(stack_base) + "
("+Chr(stack_base)+")"
        + " end: " + Str(stack_end) + "
("+Chr(stack_end)+"); "
        + " size: " + Str(stack_size) + "; "
        + " ] " + Str(last_ticks)
        )
    end
    #endif

    proc Push_Position()
        // Push something on the stack
        if stack_pos >= stack_end
            stack_pos   = stack_base
            stack_first = stack_pos + 1
        else
            stack_pos   = stack_pos + 1
            if stack_pos == stack_first
                if stack_first == stack_end
                    stack_first = stack_base
                else
                    stack_first = stack_pos + 1
                endif
            endif
        endif

        stack_last = stack_pos

        #if DEBUG_JUMPS
            dump_stack("pushing position")
        #endif

        PlaceMark(Chr(stack_pos))

        old_bufferid = GetBufferId()
        old_line     = CurrLine()

    end

    proc Pop_Position()
        // Pop from the stack, not going beyond the "first" one
        if stack_pos == stack_first
            UpdateDisplay()
            Message("No (more) jumps to undo")
        else
            if stack_pos <= stack_base
                stack_pos = stack_end
            else
                stack_pos = stack_pos - 1
            endif
            #if DEBUG_JUMPS
                dump_stack("popping position")
            #endif
            GotoMark(Chr(stack_pos))
            old_bufferid = GetBufferId()
            old_line     = CurrLine()
        endif
    end

    proc undo_jump()
        Pop_Position()
    end

    proc redo_jump()
        if stack_pos == stack_last
            UpdateDisplay()
            Message("No (more) jumps to redo")
        else
            if stack_pos >= stack_end
                stack_pos   = stack_base
            else
                stack_pos   = stack_pos + 1
            endif
            #if DEBUG_JUMPS
                dump_stack("redo jump")
            #endif
            GotoMark(Chr(stack_pos))
            old_bufferid = GetBufferId()
            old_line     = CurrLine()
        endif
    end

    proc idle()

       integer ticks = GetClockTicks()
       if ticks - last_ticks > macro_reaction_speed or ticks < last_ticks

          last_ticks  = ticks
          lines_moved = CurrLine() - old_line

          if lines_moved > lines_moved_criterium
          or lines_moved < lines_moved_criterium * -1
          or GetBufferId()  old_bufferid
             Push_Position()
          endif

          old_bufferid = GetBufferId()
          old_line     = CurrLine()
       endif

       #if DEBUG_TICKS
           Message(">>ticks: " + Str(ticks) + "/"
+ str(last_ticks))
       #endif
    end

    proc WhenLoaded()
        if lines_moved_criterium == 0
            lines_moved_criterium = Query(ScreenRows)
        endif

        stack_base  = Asc(Lower(bookmark_start))
        stack_end   = Asc(Lower(bookmark_end))
        stack_size  = stack_end - stack_base
        stack_pos   = stack_base
        stack_first = stack_pos
        stack_last  = stack_pos

        if (stack_end > stack_pos) and (stack_size > 1)
          and stack_base >= ASC_A
          and stack_end  <= ASC_Z
            Hook(_IDLE_, idle)
        else
            Warn("Can't use bookmarks " + bookmark_start + "
through " + bookmark_end)
        endif

        Push_Position()
    end

    proc Main()
        string cmd[2] = SubStr(Trim(Query(MacroCmdLine)), 1, 2)

        case cmd
            when '-s'  // Push Position (SAVE)
                Push_Position()

            when '-b'  // Previous position (BACK)
                undo_jump()

            when '-n'  // Forward in History (NEXT)
                redo_jump()

            otherwise
                if Length(cmd)
                    Warn("Unknown command " + cmd)
                endif
        endcase
    end

    #ifdef WIN32
              undo_jump()
          redo_jump()
    #else
              undo_jump()
               redo_jump()
    #endif



--
Michael Graham
magog{at}the-wire.com


--
TSEPro mailing list



---
[sawasdi.apana.org.au] (3:800/846.13)
* Origin: apana>>>>>fidonet
SEEN-BY: 633/267 270
@PATH: 800/846 1 640/954 774/605 123/500 106/1 379/1 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.