JSyntaxHighlighter/AutoTab.java
public String addTab(Document doc, int offset) throws BadLocationException{
		StringBuilder tab = new StringBuilder("\n");
		Element root = doc.getDefaultRootElement();
		
		int l = root.getElementIndex(offset);
		int i = root.getElement(l).getStartOffset();
		
		while (true){
			
			String temp = doc.getText(i, 1);
			
			if (temp.equals(" ") || temp.equals("\t")){
				tab.append(temp);
				i++;
			}else{
				break;
			}
			
		}
		
		return tab.toString();
	}
/**
	 * Adds tab to document where user presses enter if tab space already exists
	 * @param doc
	 * @param offset
	 * @return
	 * @throws BadLocationException
	 */
Adds tab to document where user presses enter if tab space already exists
@param doc
@param offset
@return
@throws BadLocationException
Adds tab to document where user presses enter if tab space already exists @param doc @param offset @return @throws BadLocationException
public String addTab(Document doc, int offset) throws BadLocationException{
		StringBuilder tab = new StringBuilder("\n");
		Element root = doc.getDefaultRootElement();
		int l = root.getElementIndex(offset);
		int i = root.getElement(l).getStartOffset();
		while (true){
			String temp = doc.getText(i, 1);
			if (temp.equals(" ") || temp.equals("\t")){
				tab.append(temp);
				i++;
			}else{
				break;
			}
		}
		return tab.toString();
	}
public String addTab ( Document doc , int offset ) throws BadLocationException { StringBuilder tab = new StringBuilder ( "\n" ) ; Element root = doc . getDefaultRootElement ( ) ; int l = root . getElementIndex ( offset ) ; int i = root . getElement ( l ) . getStartOffset ( ) ; while ( true ) { String temp = doc . getText ( i , 1 ) ; if ( temp . equals ( " " ) || temp . equals ( "\t" ) ) { tab . append ( temp ) ; i ++ ; } else { break ; } } return tab . toString ( ) ; }
Adds tab to document where user presses enter if tab space already exists
 @param doc
 @param offset
 @return
 @throws BadLocationException
Adds tab to document where user presses enter if tab space already exists @param doc @param offset @return @throws BadLocationException