home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / FREDV19A.LHA / FrexxEd / fpl / ZMacs.FPL < prev   
Encoding:
Text File  |  1995-07-21  |  9.2 KB  |  294 lines

  1. // $Id: ZMacs.FPL 1.16 1995/07/21 10:45:54 jskov Exp jskov $
  2. // $VER: ZMacs.FPL 1.8 (21.07.95) © Jesper Skov
  3.  
  4.  
  5. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Ideas ««
  6. // M-y scroll through old yanks (kill ring).
  7. // M-t transpose words
  8.  
  9. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Support routines ««
  10. export int __yankID = GetBufferID("DefaultBlock");  // ID of the block buffer
  11.  
  12. int __killCounter; 
  13. void export emacsBsWord()
  14. {
  15.   int thisBuffer;
  16.   int end_line = ReadInfo("line");
  17.   int end_byte = ReadInfo("byte_position");
  18.   int tempBlock = BlockCreate("__bsTempBlock");
  19.  
  20.   if (ReadInfo("counter")!=(__killCounter+1)){
  21.     Clean("Clear(__yankID);");}
  22.   __killCounter = ReadInfo("counter");
  23.  
  24.   CursorLeftWord();
  25.   BlockCut(tempBlock, GetCursor(end_byte, end_line), end_line, GetCursor(end_byte=ReadInfo("byte_position")), end_line=ReadInfo("line"));
  26.  
  27.   thisBuffer = CurrentBuffer(__yankID);
  28.   GotoLine(1);
  29.   BlockPaste(tempBlock);
  30.   CurrentBuffer(thisBuffer);
  31.  
  32.   GotoLine(end_line, end_byte);
  33.  
  34.   Kill(tempBlock);
  35. }
  36.  
  37. void export emacsDelWord()
  38. {
  39.   int beg_line = ReadInfo("line");
  40.   int beg_byte = ReadInfo("byte_position");
  41.  
  42.   if (ReadInfo("counter")!=(__killCounter+1)){
  43.     Clean("Clear(__yankID);");}
  44.   __killCounter = ReadInfo("counter");
  45.  
  46.   CursorRightWord();
  47.   BlockCutAppend(__yankID, GetCursor(ReadInfo("byte_position")), ReadInfo("line"), GetCursor(beg_byte, beg_line), beg_line);
  48.  
  49.   GotoLine(beg_line, beg_byte);
  50. }   
  51.  
  52. /*
  53.  * Emacs kill-line embryo.
  54.  * Killed lines will get copied into the block buffer before deleted. Note that
  55.  * the first killed line will first clear the block buffer, and kills following
  56.  * that one will append them to the current one.
  57.  *
  58.  * Paste the buffer with BlockPaste() or BlockPasteRect() just as usual blocks.
  59.  *
  60.  * Coded by Daniel Stenberg
  61.  */
  62.  
  63. void export kill_line()
  64. {
  65.   int this_count = ReadInfo("counter");
  66.   if ((this_count != __killCounter)&&(this_count != __killCounter+1)) {
  67.     // We were not invoked this/last action, clear the buffer
  68.     Clean("Clear(__yankID);");                // Clear the block without any hooks
  69.   }
  70.   __killCounter = ReadInfo("counter");
  71.   if(Isnewline(GetChar())) {                // standing on a newline character
  72.     int oldID = GetEntryID();                // get current entry
  73.     Delete();                                // delete the newline character
  74.     CurrentBuffer(__yankID);                // switch to the block buffer
  75.     GotoLine(-1);                            // jump to the bottom
  76.     GotoLine(ReadInfo("line"),ReadInfo("line_length")); // jump to end of line
  77.     Output("\n");                            // add a newline to the buffer
  78.     CurrentBuffer(oldID);                    // switch back to previous buffer
  79.   } else {                                    // delete to end of line
  80.     int curr_col = ReadInfo("column");        // get current column
  81.     int end_col = GetCursor(ReadInfo("line_length")); // get column of the end of line
  82.     int curr_line = ReadInfo("line");        // get line number
  83.  
  84.     BlockCopyAppend(__yankID, end_col, curr_line, curr_col, curr_line);  // append the line to the block
  85.  
  86.     DeleteEol();                            // delete to the end of line
  87.   }
  88. }
  89.  
  90. int export __yankCounter; 
  91.  
  92. /*
  93. string __killRing[16];
  94.  
  95. int nextEntry=0;                            // Where to fill kill data next time
  96. int prevEntry;                                // Last exchanged at prev yankPop call
  97. int wrapped;
  98. int __yankPopCounter; 
  99. int __yankCounter; 
  100. void export yankPop()
  101. {
  102.   if (ReadInfo("counter")+1!=__yankCounter){
  103.     DisplayBeep();
  104.     ReturnStatus("Last command was not a yank!");
  105.   } else {
  106.     if (ReadInfo("counter")+1==__yankPopCounter){
  107.       if ((!wrapped && !prevEntry) || (wrapped && ((prevEntry-1) % 15)==firstEntry)){
  108.         DisplayBeep();
  109.         ReturnStatus("No more entries in kill ring!")
  110.         exit();
  111.       } else {
  112.         prevEntry--;
  113.  
  114.  
  115.       }
  116.     }
  117.   }
  118. }
  119. */
  120.  
  121. void export emacsOpenFile(int viewControl)
  122. {
  123.   int old_popup = ReadInfo("popup_view");
  124.   SetInfo(0,"popup_view",viewControl);
  125.   Open("");
  126.   SetInfo(0,"popup_view",old_popup);
  127. }
  128.  
  129.  
  130. void export emacsIncludeFile()
  131. {
  132.   int old_popup = ReadInfo("popup_view");
  133.   SetInfo(0,"popup_view",0);
  134.   InsertFile("");
  135.   SetInfo(0,"popup_view",old_popup);
  136. }
  137.  
  138.  
  139.  
  140. void export emacsGotoBuffer(int viewControl)
  141. {
  142.   int id=PromptBuffer("",1);
  143.   if (id){
  144.     Activate(id,viewControl);
  145.     CurrentBuffer(id);
  146.   }
  147. }
  148.  
  149.  
  150. void export emacsTranspose()
  151. {
  152.   int letter=GetChar();
  153.  
  154.   if (Isnewline(letter)){
  155.     CursorLeft();
  156.     letter=GetChar();
  157.     Delete();
  158.     CursorLeft();
  159.     Output(itoc(letter));
  160.     CursorRight();
  161.   } else {
  162.     Delete();
  163.     CursorLeft();
  164.     Output(itoc(letter));
  165.     if (Isnewline(GetChar())){                // Fix if moved to prev line
  166.       CursorRight();
  167.     }
  168.   }
  169. }
  170.  
  171. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Configuration ««
  172.  
  173. string metaKey = "amiga";                            // Default/0
  174.  
  175. ConstructInfo("emacs_meta","","","GCW(system)","Amiga|Escape|Alt",0,0);
  176.  
  177. if (ReadInfo("emacs_meta")==1){
  178.   metaKey = "'esc'";                                // 1=Esc
  179. } else if (ReadInfo("emacs_meta")==2){
  180.   metaKey = "alt";                                    // 2=alt
  181. }
  182.  
  183. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Cursor movement ««
  184. AssignKey("CursorLeft();",    "control b");
  185. AssignKey("CursorRight();",    "control f");
  186. AssignKey("CursorLeftWord();", joinstr(metaKey," b"));
  187. AssignKey("CursorRightWord();",    "'esc' f");
  188.  
  189. AssignKey("CursorDown();",    "control n");
  190. AssignKey("CursorUp();",    "control p");
  191.  
  192. AssignKey("PageUp();",        "control V");
  193. AssignKey("PageUp();",        joinstr(metaKey," v"));
  194. AssignKey("PageDown();",    "control v");
  195. AssignKey("GotoLine(ReadInfo(\"line\"));","control a");
  196. AssignKey("GotoLine(ReadInfo(\"line\"),ReadInfo(\"line_length\"));","control e");
  197. AssignKey("                                // Next view
  198. {
  199.   int id=PrevView();
  200.  
  201.   Activate(id, 0);CurrentBuffer(id);
  202. }",                            "control x o");
  203. AssignKey("                                // Previous view
  204. {
  205.   int id=NextView();
  206.  
  207.   Activate(id, 0);CurrentBuffer(id);
  208. }",                            "control x O");
  209. AssignKey("GotoLine();",    "control c g");
  210. AssignKey("GotoLine(1,0);",    joinstr(metaKey," <"));
  211. AssignKey("Bottom();End();",joinstr(metaKey," >"));
  212.  
  213. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Editing ««
  214. AssignKey("kill_line();",    "control k");
  215. AssignKey("DeleteEol();",    "shift 'Del'");
  216. AssignKey("Backspace(ReadInfo(\"byte_position\"));","shift 'backspace'");
  217. AssignKey("
  218. {
  219.   if (ReadInfo(\"line_length\")==1){
  220.     kill_line();                         // Don't overdo it if the line is
  221.   } else {                                 // is empty
  222.     GotoLine(ReadInfo(\"line\"));kill_line();kill_line();
  223.   }
  224. }",                            "control K");
  225.  
  226. AssignKey("Delete();",        "control d");
  227. AssignKey("emacsDelWord();",    joinstr(metaKey," d"));
  228. AssignKey("emacsBsWord();",joinstr(metaKey," 'backspace'"));
  229.  
  230. AssignKey("Undo();",        "control x u");
  231.  
  232. AssignKey("CenterLine(0);", joinstr(metaKey," s"), "!block_exist");
  233. AssignKey("CenterBlock();", joinstr(metaKey," s"), "block_exist");
  234.  
  235. AssignKey("emacsTranspose();","control t");
  236.  
  237. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Block control ««
  238. AssignKey("BlockMark();",    "control 'space'");
  239. AssignKey("BlockCopy();",    "control W");
  240. AssignKey("BlockCopy();",    joinstr(metaKey," w"));
  241. AssignKey("BlockCut();",    "control w");
  242. AssignKey("__yankCounter=ReadInfo(\"counter\");BlockPaste();",    "control y");
  243.  
  244. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Macro control ««
  245. AssignKey("if (!ReadInfo(\"macro_on\"))
  246.              {MacroRecord(1);};","control x (");
  247. AssignKey("if (ReadInfo(\"macro_on\")){MacroRecord(1,\"\",\"control x e\");};","control x )");
  248.  
  249.  
  250. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Buffer control ««
  251. AssignKey("SaveChanges();",    "control x control s");
  252. AssignKey("SaveAs();",        "control x control w");
  253. AssignKey("emacsOpenFile(0);","control x control f");
  254. AssignKey("emacsOpenFile(1);","control x 4 f");
  255. AssignKey("emacsIncludeFile();","control x i");
  256. AssignKey("Kill(GetBufferID());","control x k");
  257. AssignKey("QuitAll();",        "control x control c");
  258. AssignKey("emacsGotoBuffer(0);","control x b");
  259. AssignKey("emacsGotoBuffer(1);","control x 4 b");
  260.  
  261. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» View control ««
  262. AssignKey("MaximizeView();","control x 1");
  263. AssignKey("RemoveView();",    "control x 0");
  264. AssignKey("CurrentBuffer(Activate(DuplicateEntry(),1));","control x 2");
  265. AssignKey("CenterView();",    "control l");
  266.  
  267. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Folder control ««
  268. AssignKey("FoldShow();", "control c control s");     // SHOW
  269. AssignKey("FoldShow(0);", "control c control S e");  // (e)xclusive
  270. AssignKey("FoldShow(-1);", "control c control S a"); // (a)ll
  271. AssignKey("FoldDelete();", "control c control S d"); // (d)elete
  272. AssignKey("FoldHide();", "control c control h");     // HIDE
  273. AssignKey("FoldHide(0);", "control c control H e");  // (e)xclusive
  274. AssignKey("FoldHide(-1);", "control c control H a"); // (a)ll
  275. AssignKey("Fold();", "control c control H n");       // (n)ew
  276.  
  277. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Search & Replace ««
  278. AssignKey("{ int ret; if ((ret=ReplaceSet())>=0)
  279.     { if (Replace()<0) DisplayBeep(); }
  280.          else ReturnStatus(GetReturnMsg(ret)); };", joinstr(metaKey, " shift 5"));
  281.  
  282. AssignKey("MySearch(0);", "control S");        // Repeat search forwards
  283. AssignKey("MySearch(1);", "control R");        // do backwards
  284.  
  285. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Miscellaneous ««
  286. AssignKey("SetInfo(-1,\"wall_right\",ReadInfo(\"column\"));","control x f");
  287.                                                 // Set wall_right
  288.  
  289. AssignKey("checkWord();", joinstr(metaKey, " shift 4")); // ISpell
  290.  
  291. AssignKey("Prompt();",        joinstr(metaKey," x"));
  292.  
  293. AssignKey("Iconify();",        "control z");
  294.