home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmkmap1.zip / HERBERT.E < prev    next >
Text File  |  1996-12-26  |  5KB  |  194 lines

  1. /*
  2.  * Constant HOLD_INDENT_IN_STREAM_MODE to modify the behaviour of the
  3.  * enter key in stream mode. Only applies to henter_common().
  4.  */
  5.  
  6. const
  7. compile if not defined(HOLD_INDENT_IN_STREAM_MODE)
  8.    HOLD_INDENT_IN_STREAM_MODE = 0
  9. compile endif
  10.  
  11. /*
  12.  * 01/96 by herbert
  13.  * makes the keyset with the name at cursor position the current
  14.  * keyset
  15.  */
  16. defproc new_keyset()
  17. getline newkeys
  18. newkeys=substr( newkeys, .col)
  19. parse value newkeys with newkeys rest
  20. sayerror 'changed keyset to 'newkeys
  21. .keyset = newkeys
  22.  
  23. /*
  24.  * 03/1995 by herbert
  25.  * Snappy enter-behaviour, stays at current column, even shifts
  26.  * text to it when splitting a line
  27.  */
  28. defproc hinsert_line()
  29. if .line then
  30.       split
  31.    else
  32.       insert
  33.       up
  34.    endif
  35.    getline line
  36.    parse value pmargins() with leftcol . paracol .
  37.    if line='' or not .line then
  38.       .col=paracol
  39.    else
  40.       call pfirst_nonblank()
  41.       if .col=paracol then .col=leftcol; endif
  42.    endif
  43.    down
  44.    getline line
  45.    if line<>'' then
  46.       old_insert = insertstate()
  47.       if old_insert <> 1 then insert_toggle endif
  48.       newcol = .col
  49.       .col = 1
  50.       do urx=1 to newcol-1
  51.          keyin ' '
  52.       enddo
  53.       .col = newcol
  54.       if old_insert <> 1 then insert_toggle endif
  55.    endif
  56.  
  57. /*
  58.  * Slightly enhanced enter_common()
  59.  *  If Constant HOLD_INDENT_IN_STREAM_MODE is set to 1
  60.  *  hinsert_line is called.
  61.  */
  62. compile if ENHANCED_ENTER_KEYS
  63. defproc henter_common(action)
  64.  compile if WANT_CUA_MARKING = 'SWITCH'
  65.    universal CUA_marking_switch
  66.  compile endif
  67.  compile if WANT_STREAM_MODE = 'SWITCH'
  68.    universal stream_mode
  69.    if stream_mode then
  70.  compile endif
  71.  compile if WANT_STREAM_MODE
  72.     compile if HOLD_INDENT_IN_STREAM_MODE = 1
  73.       call hinsert_line()
  74.     compile else
  75.       if .line then
  76.   compile if WANT_CUA_MARKING
  77.    compile if WANT_CUA_MARKING = 'SWITCH'
  78.          if CUA_marking_switch then
  79.    compile endif
  80.             if not process_mark_like_cua() and   -- There was no mark
  81.                not insert_state() then           -- & we're in replace mode
  82.                delete_char    -- Delete the character, to emulate replacing the
  83.             endif             -- marked character with a newline.
  84.    compile if WANT_CUA_MARKING = 'SWITCH'
  85.          endif
  86.    compile endif
  87.   compile endif  -- WANT_CUA_MARKING
  88.          split
  89.          .col=1
  90.          down
  91.       else
  92.          insert
  93.          .col=1
  94.       endif
  95.    compile endif --- HOLD_INDENT_IN_STREAM_MODE = 1
  96.       return
  97.  compile endif  -- WANT_STREAM_MODE
  98.  compile if WANT_STREAM_MODE = 'SWITCH'
  99.    endif
  100.  compile endif
  101.  compile if WANT_STREAM_MODE <> 1
  102.    if .line = .last  & (action=3 | action=5) then  -- 'ADDATEND' | 'DEPENDS+'
  103.       call einsert_line()
  104.       down                       -- This keeps the === Bottom === line visible.
  105.       return
  106.    endif
  107. ;     'NEXTLINE' 'ADDATEND'                        'DEPENDS'  'DEPENDS+'
  108.    if action=2 | action=3 | (not insert_state() & (action=4 | action=5)) then
  109.       down                          -- go to next line
  110.       begin_line
  111.       return
  112.    endif
  113.    if action=6 then
  114.       call splitlines()
  115.       call pfirst_nonblank()
  116.       down
  117. ;;    refresh
  118.       return
  119.    endif
  120.    call einsert_line()           -- insert a line
  121.  compile endif  -- WANT_STREAM_MODE <> 1
  122. compile endif
  123.  
  124. /*
  125.  * 03/1995 by Herbert :
  126.  * - Added a defproc smart_backspace() for programming modes. It detects
  127.  *   the indent level of the current paragraph and of those above and
  128.  *   then backspaces to the next lower indent level.
  129.  */
  130.  
  131. defproc smart_backspace()
  132.    getline line
  133.    this_col = .col
  134.    if line = '' then
  135.       left_col = this_col
  136.    else
  137.       call pfirst_nonblank()
  138.       left_col = .col
  139.       .col = this_col
  140.    endif
  141.    if this_col = 1 | this_col > left_col
  142.    then
  143.       call do_backspace()
  144.    else
  145.       this_line = .line
  146.       lc = 0
  147.       do while .line & .col >= this_col
  148.          up
  149.          lc = lc + 1
  150.          call pfirst_nonblank()
  151.       enddo
  152.       if .col <> left_col then left_col = this_col - .col endif
  153.       do i = 1 to lc
  154.           down
  155.       enddo
  156.       .col = this_col
  157.       do i = 1 to left_col
  158.          call do_backspace()
  159.       enddo
  160.    endif
  161.  
  162. /*
  163.  * Snappy Semicolon like known from Emacs :-)
  164.  * If a ';' is entered at the end of a line
  165.  * a newline will be performed
  166.  * For Expansion purposes the ';' has to be
  167.  * entered before!
  168.  */
  169. defproc Emacs_Semicolon()
  170.    getline line
  171.    if length( line) < .col then
  172.       call hinsert_line()
  173.    endif
  174.  
  175. /*
  176.  * Smart closing '}' for Cmode: performs a smart_backspace() if
  177.  *    there's no nonblank char left from cursor
  178.  */
  179. defproc cmode_closing_brace()
  180.    this_col = .col
  181.    call pfirst_nonblank()
  182.    left_col = .col
  183.    .col = this_col
  184.    if this_col <>1 & (left_col = 1 | left_col >= this_col)
  185.    then call smart_backspace()
  186.    endif
  187.    keyin '}'
  188.    this_col = .col
  189.    .col = .col - 1
  190.    call passist()
  191.    call passist()
  192.    .col = this_col
  193.  
  194.