public void findPreviousOccurrence(Editor editor) {
   Line line;
   for (line = editor.getDotLine().previous(); line != null; line = line.previous()) {
     if (line instanceof OccurrenceLine) break;
   }
   if (line instanceof OccurrenceLine) findOccurrence(editor, line);
 }
 public Position getInitialDotPos() {
   final boolean listEachOccurrence;
   if (search instanceof FindInFiles)
     listEachOccurrence = ((FindInFiles) search).getListEachOccurrence();
   else listEachOccurrence = true;
   for (Line line = getFirstLine(); line != null; line = line.next()) {
     if (line instanceof OccurrenceLine) return new Position(line, 0);
     if (!listEachOccurrence && line instanceof FileLine) return new Position(line, 0);
   }
   return new Position(getFirstLine(), 0);
 }
 public void findOccurrenceAtDot(Editor editor, boolean killList) {
   Position pos = editor.getDotCopy();
   if (pos == null) return;
   Line sourceLine = null;
   int sourceLineNumber = 0;
   Buffer buf = null;
   String canonicalPath = null;
   setLastDotPos(pos);
   final Line line = pos.getLine();
   if ((line instanceof OccurrenceLine)) {
     sourceLine = ((OccurrenceLine) line).getSourceLine();
     Line ln = line;
     if (!ln.getText().startsWith("File: "))
       sourceLineNumber = Utilities.parseInt(ln.getText()) - 1;
     while (ln != null) {
       if (ln.getText().startsWith("File: ")) {
         canonicalPath = ln.getText().substring(6);
         break;
       }
       ln = ln.previous();
     }
   } else if (line instanceof FileLine) canonicalPath = ((FileLine) line).getCanonicalPath();
   if (buf == null && canonicalPath != null)
     buf = Editor.getBuffer(File.getInstance(canonicalPath));
   if (buf != null) {
     if (!buf.isLoaded()) {
       if (!buf.initialized()) buf.initialize();
       buf.load();
       if (!buf.isLoaded()) {
         editor.status("Unable to load buffer");
         return;
       }
     }
     if (line instanceof FileLine) {
       // Mark file visited.
       ((FileLine) line).markVisited();
       // Advance dot to next line.
       Position dot = editor.getDot();
       if (dot.equals(pos) && dot.getNextLine() != null) {
         dot.moveTo(dot.getNextLine(), 0);
         editor.moveCaretToDotCol();
       }
     }
     Line target;
     if (sourceLine != null) {
       if (buf.contains(sourceLine)) target = sourceLine;
       else target = buf.getLine(sourceLine.lineNumber());
     } else target = buf.getLine(sourceLineNumber);
     gotoSource(editor, buf, target, killList);
   }
 }
 private Line findLineForOccurrence(File sourceFile, Line sourceLine) {
   if (sourceFile == null) return null;
   if (sourceLine == null) return null;
   final String cp = sourceFile.canonicalPath();
   Line line;
   for (line = getFirstLine(); line != null; line = line.next()) {
     if (line instanceof FileLine) {
       if (((FileLine) line).getCanonicalPath().equals(cp)) break;
     }
   }
   if (line == null) return null;
   Debug.assertTrue(line instanceof FileLine);
   Debug.assertTrue(((FileLine) line).getCanonicalPath().equals(cp));
   int target = sourceLine.lineNumber() + 1;
   Line best = null;
   for (line = line.next(); line instanceof OccurrenceLine; line = line.next()) {
     int candidate = ((OccurrenceLine) line).getSourceLineNumber();
     if (candidate == target) return line;
     if (best != null && candidate > target) return best;
     best = line;
   }
   return best;
 }