home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / REPEAT.PEL < prev    next >
Text File  |  1994-04-01  |  3KB  |  113 lines

  1. # $Header:   P:\source\wmacros\wrepeat.pev   1.2   01 Apr 1994 14:55:46   WALKER  $
  2.  
  3. ##############################################################################
  4. #
  5. #       Compuware Corporation
  6. #         31440 Northwestern Highway
  7. #           Farmington Hills, Michigan 48334-2564
  8. #
  9. #   This source code listing contains information that is
  10. #   proprietary to Compuware Corporation and may not be copied
  11. #   duplicated, translated, transmitted, stored, retrieved
  12. #   or in any manner or by any method conveyed or disclosed
  13. #   to a third party or parties without express written
  14. #   permission from Compuware Corporation.
  15. #
  16. #  
  17. ##############################################################################
  18.  
  19. #### $Workfile:   wrepeat.pel  $: repeat count support
  20.  
  21. global function repeat_key_action()
  22. {
  23.         
  24.    local repeatCount = 0
  25.    local msg = "Enter repeat count followed by the key to repeat. ["
  26.    local digit = "zip"
  27.    local keyToExecute
  28.    local keyUsedToGetHere = current_key
  29.    local binding
  30.    local c
  31.    local functionId
  32.  
  33.    ###
  34.    ### build the repeat count
  35.    ###
  36.  
  37. #  begin_dialog()
  38.    notify( msg 1 "]" )
  39.  
  40.    while (1)
  41.    {
  42.       while ( chr(c = getchar()) ~ /[0-9]/ )
  43.       {
  44.          digit = c - ord("0")
  45.          repeatCount = repeatCount * 10 + digit
  46.          notify( msg repeatCount "]" )
  47.       }
  48.  
  49.       # Esc key to exit
  50.       if ( current_key == KEYCODE_ESC )
  51.       {
  52.          notify( "Command canceled" )
  53.          digit = ""
  54.          repeatCount = 0
  55.          break
  56.       }
  57.  
  58.       # repeat key multiplies by four ala Emacs
  59.       if ( current_key == keyUsedToGetHere )
  60.       {
  61.          digit = ""
  62.          repeatCount = (repeatCount ? repeatCount : 1) * 4
  63.          notify( msg repeatCount "]" )
  64.       }
  65.       else
  66.          break
  67.    }
  68.  
  69.    message( "" )
  70. #  end_dialog()
  71.  
  72.    if ( digit == "zip" )
  73.       repeatCount = 1
  74.    else if ( repeatCount < 1 )
  75.       return
  76.  
  77.    ###
  78.    ### build the string representation of the key then repeat its action
  79.    ###
  80.  
  81.    keyToExecute = "#" current_key
  82.  
  83.    # eat the character remaining after a DOS two-character sequence
  84.    # (must be done after accessing "current_key")
  85.    if (c == 0)
  86.       getchar()
  87.  
  88.    binding = keymap_binding( keyToExecute )
  89.    if ( binding !~ /repeat_key_action/ )
  90.    {
  91.       if ((functionId = function_id( binding )))
  92.       {
  93.          while (repeatCount--)
  94.          {
  95.             execute_function( functionId )
  96.          }
  97.       }
  98.    }
  99. }
  100.  
  101.  
  102. ##
  103. ## execute the function bound to a given key
  104. ##
  105.  
  106. global function execute_key_action( keystring )    #PUBLIC
  107. {
  108.    local binding = keymap_binding( keystring )
  109.  
  110.    if ( binding && ( binding !~ /execute_key_action/ ))
  111.       return execute_function( binding )
  112. }
  113.