/* * This is simple jEdit beanshell macro for numbering lines. * Custom starting numbers, custom step and separator. * * charset: UTF-8 * * (c) TAAT Digital Technologies 2006 * Tomasz Pęszor * info at taat dot pl * http://taat.pl/jedit/ */ void numbering() { if (textArea.getSelectedText()==null) { mcp=textArea.getCaretPosition(); textArea.selectAll(); sn=true; } line = textArea.getCaretLine(); len = textArea.getLineLength(line) + 1; while(true) { start = Macros.input(view, "Start number:","1"); if(start == null) return; step = Macros.input(view, "Step:","1"); if(step == null) return; separator = Macros.input(view, "Separator:",". "); if(separator == null) return; try { buffer.beginCompoundEdit(); selectedLines = textArea.getSelectedLines(); start = Integer.parseInt(start); //end = start+selectedLines.length; step = Integer.parseInt(step); for(int i=0; i < selectedLines.length; ++i) { offsetBOL = textArea.getLineStartOffset(selectedLines[i]); textArea.setCaretPosition(offsetBOL); textArea.goToStartOfWhiteSpace(false); textArea.goToEndOfWhiteSpace(true); text = textArea.getSelectedText(); if(text == null) text = ""; j = i*step+start; textArea.setSelectedText(j + separator + text); } if (sn==true) { textArea.selectNone(); len=buffer.getLength(); if (mcp>len) mcp=len; textArea.setCaretPosition(mcp); } buffer.endCompoundEdit(); textArea.requestFocus(); return; } catch(NumberFormatException e){ } } } // main if(buffer.isReadOnly()) Macros.error(view, "Buffer is read-only."); else numbering(); /* Macro index entry (in DocBook XML) Lines_to_numbered.bsh Custom starting numbers, custom step and separator. (c) TAAT Digital Technologies 2006 */