home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / FREDV19A.LHA / FrexxEd / fpl / BookMark.FPL < prev    next >
Encoding:
Text File  |  1995-07-27  |  5.6 KB  |  181 lines

  1. // $Id: BookMark.FPL 1.2 1995/07/27 16:32:27 jskov Exp $
  2.  
  3. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» GotoBookMark() ««
  4. export int GotoBookMark(int num)
  5. {
  6.   string book;
  7.   int x, y;
  8.  
  9.   book=joinstr("BookMark_y", ltostr(num));
  10.   y=ReadInfo(book);
  11.   if (y) {
  12.     book=joinstr("BookMark_x", ltostr(num));
  13.     x=ReadInfo(book);
  14.     GotoLine(y, x);
  15.     CenterView();
  16.   } else
  17.     ReturnStatus("No book mark stored!");
  18.  
  19. }
  20.  
  21. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» SetBookMark() ««
  22. export int SetBookMark(int num)
  23. {
  24.   string book;
  25.  
  26.   book=joinstr("BookMark_y", ltostr(num));
  27.   SetInfo(-1, book, ReadInfo("line"));
  28.   book=joinstr("BookMark_x", ltostr(num));
  29.   SetInfo(-1, book, ReadInfo("byte_position"));
  30.  
  31. }
  32.  
  33.  
  34. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» loadBookMarks() ««
  35. // Mark storage format:  "m1Line:m1BytePos:m2Line:m2....m10BytePos:"
  36.  
  37. export int loadBookMarks()
  38. {
  39.   string s;
  40.  
  41.   if (strlen(s=ReadInfo("mark_storage"))){
  42.     if (-1<strstr(s,":"))                    // absolute?
  43.       s = LoadString(s+ReadInfo("file_name")+".Mrk");
  44.     else
  45.       s = LoadString(ReadInfo("file_path")+"marks/"+ReadInfo("file_name")+".Mrk");
  46.   } else
  47.     s = LoadString(ReadInfo("full_file_name")+".Mrk");
  48.  
  49.   if (strlen(s)){
  50.     int counter;
  51.     int i=0;
  52.     int pos;
  53.     string book;
  54.  
  55.     for (counter=1; counter<=10; counter++) {
  56.       book=joinstr("BookMark_y", ltostr(counter)); // Fix line
  57.       pos = atoi(substr(s,i,i-(i=strstr(s,":",i)+1)));
  58.       SetInfo(-1,book, pos);
  59.       book=joinstr("BookMark_x", ltostr(counter)); // Fix byteposition
  60.       pos = atoi(substr(s,i,i-(i=strstr(s,":",i)+1)));
  61.       SetInfo(-1,book, pos);
  62.     }
  63.     ReturnStatus("Marks successfully loaded!");
  64.   } else
  65.     ReturnStatus("No marks loaded!");
  66.   return 0;
  67. }
  68.  
  69. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» saveBookMarks() ««
  70. export int saveBookMarks()
  71. {
  72.   string s;                                    // Contain marks in string form
  73.   string book;
  74.   int counter;
  75.  
  76.   int sum;                                    // Simple check; all marks unused
  77.  
  78.  
  79.   for (counter=1; counter<=10; counter++) {
  80.     book=joinstr("BookMark_y", ltostr(counter)); // Fix line
  81.     s += itoa(ReadInfo(book)) + ":";
  82.     sum += ReadInfo(book);
  83.     book=joinstr("BookMark_x", ltostr(counter)); // Fix byteposition
  84.     s += itoa(ReadInfo(book)) + ":";
  85.     sum += ReadInfo(book);
  86.   }
  87.  
  88.   if (sum){                                    // Only save if any active bookmarks!
  89.  
  90.     if (strlen(book=ReadInfo("mark_storage"))){
  91.       if (-1<strstr(book,":"))                // absolute?
  92.         book = book+ReadInfo("file_name")+".Mrk";
  93.       else {
  94.         if (!Check(ReadInfo("file_path")+"marks")) // Always make directory!
  95.           System("makedir "+ReadInfo("file_path")+"marks");
  96.         book = ReadInfo("file_path")+"marks/"+ReadInfo("file_name")+".Mrk";
  97.       }
  98.     } else
  99.       book = ReadInfo("full_file_name")+".Mrk";
  100.  
  101.     SaveString(book,s);
  102.   }
  103.   return 0;
  104. }
  105. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» updateMarks ««
  106.  
  107. int preLine;
  108.  
  109. export int markHook()                        // Let's remember current line
  110. {
  111.   preLine = ReadInfo("line");
  112.   return 0;
  113. }
  114.  
  115. export int markHookPast()
  116. {                                            // Compare the now current line
  117.   if (preLine!=ReadInfo("line")){            // with the previously recorded!
  118.     int diff = preLine-ReadInfo("line");
  119.     int counter;
  120.     string book;
  121.  
  122.     for (counter=1; counter<=10; counter++) {
  123.       book=joinstr("BookMark_y", ltostr(counter)); // Construct mark name
  124.       if (ReadInfo(book)>preLine)            // If mark below affected area
  125.         SetInfo(-1,book,ReadInfo(book)-diff); // adjust its position (line wise)
  126.     }
  127.   }
  128.   return 0;
  129. }
  130.  
  131. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Init ««
  132. { // Hook functions which may affect mark positions
  133.   Hook("BlockPaste","markHook();","mark_adjust_marks");
  134.   Hook("BlockCut","markHook();","mark_adjust_marks");
  135.   Hook("Delete","markHook();","mark_adjust_marks");
  136.   Hook("DeleteLine","markHook();","mark_adjust_marks");
  137.   Hook("DeleteWord","markHook();","mark_adjust_marks");
  138.   Hook("Backspace","markHook();","mark_adjust_marks");
  139.   Hook("BackspaceWord","markHook();","mark_adjust_marks");
  140.   Hook("Output","markHook();","mark_adjust_marks");
  141.   Hook("Yank","markHook();","mark_adjust_marks");
  142.   Hook("InsertFile","markHook();","mark_adjust_marks");
  143.  
  144.   HookPast("BlockPaste","markHookPast();","mark_adjust_marks");
  145.   HookPast("BlockCut","markHookPast();","mark_adjust_marks");
  146.   HookPast("Delete","markHookPast();","mark_adjust_marks");
  147.   HookPast("DeleteLine","markHookPast();","mark_adjust_marks");
  148.   HookPast("DeleteWord","markHookPast();","mark_adjust_marks");
  149.   HookPast("Backspace","markHookPast();","mark_adjust_marks");
  150.   HookPast("BackspaceWord","markHookPast();","mark_adjust_marks");
  151.   HookPast("Output","markHookPast();","mark_adjust_marks");
  152.   HookPast("Yank","markHookPast();","mark_adjust_marks");
  153.   HookPast("InsertFile","markHookPast();","mark_adjust_marks");
  154.  
  155.  
  156.   HookPast("Save","saveBookMarks();","mark_save_marks");
  157.   HookPast("Load","loadBookMarks();","mark_save_marks");
  158. }
  159.  
  160. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Create Mark info vars ««
  161. {
  162.   int counter;
  163.   string book, key;
  164.   for (counter=1; counter<=10; counter++) {
  165.     book=joinstr("BookMark_y", ltostr(counter));
  166.     ConstructInfo(book, "", "", "ILH", "", 0, 0);
  167.     book=joinstr("BookMark_x", ltostr(counter));
  168.     ConstructInfo(book, "", "", "ILH", "", 0, 0);
  169.  
  170.     key=joinstr("'F", ltostr(counter), "'");
  171.     AssignKey(joinstr("GotoBookMark(", ltostr(counter), ");"), key);
  172.     key=joinstr("'F", ltostr(counter+10), "'");
  173.     AssignKey(joinstr("SetBookMark(", ltostr(counter), ");"), key);
  174.   }
  175. }
  176.  
  177. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Info ««
  178. ConstructInfo("mark_adjust_marks","","","WBL","",0,1,0);
  179. ConstructInfo("mark_save_marks","","","WBL","",0,1,0);
  180. ConstructInfo("mark_storage","","","WSG(io)","",0,0,"local");
  181.