home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / MYMODE.PEL < prev    next >
Text File  |  1995-03-01  |  4KB  |  136 lines

  1. #  
  2. #  This file is meant to serve as a guide when creating your own emulation mode
  3. #  from scratch.  For further assistance please refer to the emulation specific
  4. #  PEL files such as emacs.pel and brief.pel.
  5. #  
  6.  
  7.  
  8. #  Variables declared local in a file can be referenced anywhere within that
  9. #  file but not from any other file.
  10.  
  11. local my_keymap = -1;      #  variable that holds the key assignments for my_mode
  12. local old_search_flags;    #  variable holding the old state of the search flags
  13.  
  14. function my_mode()
  15. {
  16.  
  17.    local prevPauseOnError
  18.  
  19.    # check to see if we are already in "my" emulation mode, so we
  20.    # don't make all the assignments again.
  21.  
  22.    if( emulation_mode == "my_mode" )
  23.       return;
  24.  
  25.    # set the global variable pause_on_error to pause if an error or warning
  26.    # occurs during initialization of your mode
  27.  
  28.    prevPauseOnError = pause_on_error
  29.    pause_on_error   = 1
  30.  
  31.    # emulation_mode is a PEL global variable indicating the current
  32.    # emulation mode
  33.  
  34.    emulation_mode = "my_mode"  
  35.  
  36.    #  add my_mode to the emulations array so it shows up in the settings notebook
  37.    emulations["my_mode"] = "My mode"
  38.  
  39.    # Set the global variable search_flags to search the way you want.
  40.    # This example forces the search to be forward and have regular
  41.    # expressions on.  You may set many global variables here such as
  42.    # linenumber format, scroll variables, window_flags and many more.  For
  43.    # a more complete list see the online help "Variable" section.  Remember
  44.    # that PEL functions and variables are case sensitive.
  45.  
  46.    old_search_flags = search_flags
  47.    search_flags     = SEARCH_FORWARD + SEARCH_REGEX
  48.  
  49.    # execute this event so that you call the cleanup function of a previous
  50.    # emulation or any other functions attached to the changed emulation event.
  51.  
  52.    execute_event_handler( EVENT_EMULATION_CHANGED )
  53.  
  54.    # attach your own cleanup functions so you can restore the editor after
  55.    # you change emulation modes again
  56.  
  57.    attach_event_handler( EVENT_EMULATION_CHANGED, function_id("mymode_exit") )
  58.  
  59.    create_my_keymap()
  60.  
  61.    # This command updates the keystrokes for the pulldown menus, if you map
  62.    # any keystrokes to the same functions that the menu item calls.
  63.  
  64.    fix_menu_text()
  65.  
  66.    pause_on_error = prevPauseOnError                     
  67.  
  68. }
  69.  
  70. global function create_my_keymap()
  71. {
  72.  
  73.    # Here you define "my_keymap".  After creating a new keymap that has the
  74.    # factory default mappings to begin with, you map any other keys you want
  75.    # using the assign_key function (See documentaion for a full description of
  76.    # this function.)  If the keymap already exists, you can skip the creation
  77.    # and assignment of keys.
  78.  
  79.    if( my_keymap >= 0 )
  80.    {
  81.       current_keymap = my_keymap
  82.    }
  83.    else
  84.    {
  85.       current_kemap = my_keymap = create_keymap( factory_keymap )
  86.  
  87.       # Here you may add any keybindings you wish
  88.  
  89.       assign_key( "<Ctrl-Z>",           "gui_find" ) # gui_find is provided in gui_srch.pel
  90.       assign_key( "<Backspace>",        "delete_left" )
  91.       assign_key( "<Ctrl-Alt-Shift-N>", "nimble_fingers" )
  92.    }
  93. }
  94.  
  95. function delete_left()
  96. {
  97.  
  98.    local ch, answer, p_string
  99.  
  100.    prev_char()
  101.  
  102.    ch = read_buffer(1)
  103.    p_string = sprintf("Are you sure you want to delete this '%s' (y/n)? ", ch)
  104.  
  105.    answer = prompt(p_string, "n")
  106.  
  107.    if(tolower(substr(answer, 1, 1)) == "y")
  108.       delete_chars()
  109.    else
  110.       next_char()
  111. }
  112.  
  113. function nimble_fingers()
  114. {
  115.    
  116.    goto_buffer_top()
  117.    drop_anchor()
  118.    goto_buffer_bottom()
  119.    delete_to_scrap()
  120.    raise_anchor()
  121.  
  122.    message("Buffer deleted to scrap")
  123. }
  124.  
  125. global function mymode_exit()
  126. {
  127.    
  128.    # You may reset any variables you changed when the emulation mode was
  129.    # initialized.
  130.  
  131.    search_flags = old_search_flags
  132.  
  133.    message("Thank you for using my emulation mode.");
  134.  
  135. }
  136.