home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / wp / ewdin2.zip / AUTOINS2.PAS < prev   
Pascal/Delphi Source File  |  1993-06-03  |  3KB  |  96 lines

  1. {************************************************}
  2. {                                                }
  3. { E! for Windows                                 }
  4. { (c) - Patrick Philippot - 1992-1993            }
  5. {                                                }
  6. { AutoIns2 Extension DLL - version 1.0           }
  7. {                                                }
  8. { This DLL modifies the basic behavior of the    }
  9. { AutoInsert function. Currently, when auto-     }
  10. { inserting a right brace, EW doesn't move       }
  11. { the cursor where you would expect, that is,    }
  12. { just before the right brace. Some users prefer }
  13. { the original behavior. If you don't, install   }
  14. { this DLL.                                      }
  15. {                                                }
  16. {************************************************}
  17.  
  18. (*
  19. To use this DLL simply load it from the user menu or add its name to the
  20. list of autoloaded Extension DLLs by using the Autoload dialog box from
  21. the User Menu of EW. That's all. This extension cannot be executed because
  22. it only adds a hook responding to E! notifications. AutoIns exports no
  23. EWExecute function.
  24.  
  25. After installation and if AutoInsert has been checked in the Local Default
  26. dialog box from the Control Center, the AutoInsert function behavior will
  27. be modified. After execution, the cursor will be moved backwards one
  28. position and will be located between the left and right braces.
  29.  
  30. Please refer to the documentation for details about the AutoInsert feature.
  31.  
  32. This DLL is a less intrusive, smarter variant of AUTOINS.EWD. The cursor
  33. will not be moved if the character preceding the right brace is not the
  34. corresponding left brace.
  35.  
  36. This small piece of code also shows you how easy it is to modify basic
  37. functions of E!.
  38. *)
  39.  
  40. {$IFDEF DEBUG}
  41. {$A+,G+,B-,D+,E-,F+,I-,N-,R+,S+,V-,L+,Q+,Y+,K+,X+}
  42. {$ELSE}
  43. {$A+,G+,B-,D-,E-,F+,I-,N-,R-,S-,V-,L-,Q-,Y-,K+,X+}
  44. {$ENDIF}
  45.  
  46. {$C MOVEABLE PRELOAD DISCARDABLE}
  47.  
  48. library AutoIns;
  49.  
  50. uses WinTypes, WinProcs, EWApiImp, Strings;
  51.  
  52. {$I ewuser.inc}
  53.  
  54. var
  55.   SaveExit : Pointer;
  56.   P        : PChar;
  57.   CaretPos : longint;
  58.   XPos     : word;
  59.  
  60. function NotifyHook(eventcode : word; wParam : word; lParam : longint) : integer; export;
  61.  
  62. const
  63.  
  64.   RightBraces : string[3] = ')]}';
  65.   LeftBraces  : string[3] = '([{';
  66.  
  67. begin
  68.   NotifyHook := 0; {-A non-zero value would break the hook chain}
  69.   if  (eventcode = ewNotify_CharExit)
  70.   and (Char(Lo(wParam)) in [')', ']', '}'])
  71.   and (EWGetLocalFlag(EWLclbAutoInsert) <> 0)
  72.   and (EWGetInsertState <> 0) then begin
  73.     CaretPos := EwGetCaretPos;
  74.     XPos := LoWord(CaretPos);
  75.     P := EWGetLineAt(HiWord(CaretPos));
  76.     if  (XPos >= 2)
  77.     and ((P + XPos - 2)^ = LeftBraces[Pos(Char(Lo(wParam)), RightBraces)]) then
  78.       EWPrevCol;
  79.   end;
  80. end;
  81.  
  82. procedure LibExit; far;
  83. begin
  84.   EWRemoveHook(EWHook_Notify, @NotifyHook);
  85.   ExitProc := SaveExit;
  86. end;
  87.  
  88. exports
  89.   NotifyHook index 1;
  90.  
  91. begin
  92.   EWSetHook(EWHook_Notify, @NotifyHook);
  93.   SaveExit := ExitProc;
  94.   ExitProc := @LibExit;
  95. end.
  96.