midrange.com code scratchpad
Name:
Fix the D-specs
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
06/30/2008 10:27:00 pm
IP:
Logged
Description:
Sample Eclispe Monkey script by Joe Pluta
Code:
  1. --- Came wiffling through the eclipsey wood ---
  2. /*
  3.  * Menu: RPG > Fix D Specs
  4.  * Kudos: Joe Pluta
  5.  * License: EPL 1.0
  6.  * DOM: http://download.eclipse.org/technology/das\
  7. h/update/org.eclipse.eclipsemonkey.lang.javascript
  8.  */ 
  9.  
  10.  function main() {
  11.     var editor = editors.activeEditor;
  12.     
  13.      // get range of lines in the selection (or at th\
  14. e cursor position)
  15.     var range = editor.selectionRange;
  16.     var startLine = editor.getLineAtOffset(range.star\
  17. tingOffset);
  18.     var endLine = editor.getLineAtOffset(range.ending\
  19. Offset); 
  20.     
  21.     editor.beginCompoundChange();
  22.     
  23.     for (var i = startLine; i <= endLine; i++) {
  24.         var offset = editor.getOffsetAtLine(i);
  25.         var offset2 = editor.getOffsetAtLine(i + 1);
  26.         var length = (offset2 - offset) - 1;
  27.         var line = editor.source.substring(offset, offse\
  28. t2); 
  29.         // Substring starting at zero based offset posit\
  30. ion 17 
  31.         // the second number is the character position a\
  32. fter the 
  33.         // ending character I want.
  34.         if ( (line.substring(17,18) == "D") && (line.sub\
  35. string(18,19) != "*") &&
  36.                  (line.substring(51,52) == "B")) {
  37.                 editor.applyEdit(offset + 51, 1, "I");
  38.         }
  39.     }
  40.     editor.endCompoundChange();
  41. }   
  42. --- And burbled as it ran! ---
© 2004-2019 by midrange.com generated in 0.005s valid xhtml & css