src/Pure/PIDE/document.scala
changeset 59319 677615cba30d
parent 59077 7e0d3da6e6d8
child 59372 503739360344
equal deleted inserted replaced
59318:3ef6b0b6232e 59319:677615cba30d
   111         that match {
   111         that match {
   112           case other: Name => node == other.node
   112           case other: Name => node == other.node
   113           case _ => false
   113           case _ => false
   114         }
   114         }
   115 
   115 
   116       def is_theory: Boolean = !theory.isEmpty
   116       def is_theory: Boolean = theory.nonEmpty
   117       override def toString: String = if (is_theory) theory else node
   117       override def toString: String = if (is_theory) theory else node
   118 
   118 
   119       def map(f: String => String): Name = copy(f(node), f(master_dir), theory)
   119       def map(f: String => String): Name = copy(f(node), f(master_dir), theory)
   120     }
   120     }
   121 
   121 
   206     }
   206     }
   207 
   207 
   208     final class Commands private(val commands: Linear_Set[Command])
   208     final class Commands private(val commands: Linear_Set[Command])
   209     {
   209     {
   210       lazy val load_commands: List[Command] =
   210       lazy val load_commands: List[Command] =
   211         commands.iterator.filter(cmd => !cmd.blobs.isEmpty).toList
   211         commands.iterator.filter(cmd => cmd.blobs.nonEmpty).toList
   212 
   212 
   213       private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) =
   213       private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) =
   214       {
   214       {
   215         val blocks = new mutable.ListBuffer[(Command, Text.Offset)]
   215         val blocks = new mutable.ListBuffer[(Command, Text.Offset)]
   216         var next_block = 0
   216         var next_block = 0
   227 
   227 
   228       private def full_range: Text.Range = full_index._2
   228       private def full_range: Text.Range = full_index._2
   229 
   229 
   230       def iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] =
   230       def iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] =
   231       {
   231       {
   232         if (!commands.isEmpty && full_range.contains(i)) {
   232         if (commands.nonEmpty && full_range.contains(i)) {
   233           val (cmd0, start0) = full_index._1(i / Commands.block_size)
   233           val (cmd0, start0) = full_index._1(i / Commands.block_size)
   234           Node.Commands.starts(commands.iterator(cmd0), start0) dropWhile {
   234           Node.Commands.starts(commands.iterator(cmd0), start0) dropWhile {
   235             case (cmd, start) => start + cmd.length <= i }
   235             case (cmd, start) => start + cmd.length <= i }
   236         }
   236         }
   237         else Iterator.empty
   237         else Iterator.empty
   626     def remove_versions(retain: Int = 0): (List[Version], State) =
   626     def remove_versions(retain: Int = 0): (List[Version], State) =
   627     {
   627     {
   628       history.prune(is_stable, retain) match {
   628       history.prune(is_stable, retain) match {
   629         case Some((dropped, history1)) =>
   629         case Some((dropped, history1)) =>
   630           val old_versions = dropped.map(change => change.version.get_finished)
   630           val old_versions = dropped.map(change => change.version.get_finished)
   631           val removing = !old_versions.isEmpty
   631           val removing = old_versions.nonEmpty
   632           val state1 = copy(history = history1, removing_versions = removing)
   632           val state1 = copy(history = history1, removing_versions = removing)
   633           (old_versions, state1)
   633           (old_versions, state1)
   634         case None => fail
   634         case None => fail
   635       }
   635       }
   636     }
   636     }
   748       {
   748       {
   749         /* global information */
   749         /* global information */
   750 
   750 
   751         val state = State.this
   751         val state = State.this
   752         val version = stable.version.get_finished
   752         val version = stable.version.get_finished
   753         val is_outdated = !(pending_edits.isEmpty && latest == stable)
   753         val is_outdated = pending_edits.nonEmpty || latest != stable
   754 
   754 
   755 
   755 
   756         /* local node content */
   756         /* local node content */
   757 
   757 
   758         def convert(offset: Text.Offset) =
   758         def convert(offset: Text.Offset) =
   768 
   768 
   769         val load_commands: List[Command] =
   769         val load_commands: List[Command] =
   770           if (node_name.is_theory) Nil
   770           if (node_name.is_theory) Nil
   771           else version.nodes.load_commands(node_name)
   771           else version.nodes.load_commands(node_name)
   772 
   772 
   773         val is_loaded: Boolean = node_name.is_theory || !load_commands.isEmpty
   773         val is_loaded: Boolean = node_name.is_theory || load_commands.nonEmpty
   774 
   774 
   775         def eq_content(other: Snapshot): Boolean =
   775         def eq_content(other: Snapshot): Boolean =
   776         {
   776         {
   777           def eq_commands(commands: (Command, Command)): Boolean =
   777           def eq_commands(commands: (Command, Command)): Boolean =
   778           {
   778           {