question: public void actionPerformed ( ActionEvent e ) { Caret c = textArea . getCaret ( ) ; if ( c . getDot ( ) != c . getMark ( ) ) { return ; } RSyntaxDocument doc = ( RSyntaxDocument ) textArea . getDocument ( ) ; doc . readLock ( ) ; try { removeHighlights ( ) ; int line = textArea . getCaretLineNumber ( ) ; Token tokenList = textArea . getTokenListForLine ( line ) ; int dot = c . getDot ( ) ; Token t = RSyntaxUtilities . getTokenAtOffset ( tokenList , dot ) ; if ( t == null || ! isValidType ( t ) || isNonWordChar ( t ) ) { dot -- ; try { if ( dot >= textArea . getLineStartOffset ( line ) ) { t = RSyntaxUtilities . getTokenAtOffset ( tokenList , dot ) ; } } catch ( BadLocationException ble ) { ble . printStackTrace ( ) ; } } if ( t != null && isValidType ( t ) && ! isNonWordChar ( t ) ) { RSyntaxTextAreaHighlighter h = ( RSyntaxTextAreaHighlighter ) textArea . getHighlighter ( ) ; String lexeme = t . getLexeme ( ) ; int type = t . type ; for ( int i = 0 ; i < textArea . getLineCount ( ) ; i ++ ) { Token temp = textArea . getTokenListForLine ( i ) ; while ( temp != null && temp . isPaintable ( ) ) { if ( temp . is ( type , lexeme ) ) { try { int end = temp . offset + temp . textCount ; Object tag = h . addMarkedOccurrenceHighlight ( temp . offset , end , p ) ; tags . add ( tag ) ; } catch ( BadLocationException ble ) { ble . printStackTrace ( ) ; } } temp = temp . getNextToken ( ) ; } } } } finally { doc . readUnlock ( ) ; } textArea . fireMarkedOccurrencesChanged ( ) ; }
target:  Called after the caret has been moved and a fixed time delay has elapsed. This locates and highlights all occurrences of the identifier at the caret position, if any.