author | wenzelm |
Wed, 22 Aug 2012 15:53:17 +0200 | |
changeset 48882 | 61dc7d5d150a |
parent 48870 | 4accee106f0f |
child 48883 | 04cd2fddb4d9 |
permissions | -rw-r--r-- |
45007 | 1 |
/* Title: Tools/jEdit/src/jedit_thy_load.scala |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
3 |
|
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
4 |
Primitives for loading theory files, based on jEdit buffer content. |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
6 |
|
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
8 |
|
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
9 |
|
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
10 |
import isabelle._ |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
11 |
|
48409 | 12 |
import java.io.{File => JFile, IOException} |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
13 |
import javax.swing.text.Segment |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
14 |
|
44963
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
15 |
import org.gjt.sp.jedit.io.{VFS, FileVFS, VFSFile, VFSManager} |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
16 |
import org.gjt.sp.jedit.MiscUtilities |
44963
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
17 |
import org.gjt.sp.jedit.View |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
18 |
|
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
19 |
|
48870
4accee106f0f
clarified initialization of Thy_Load, Thy_Info, Session;
wenzelm
parents:
48422
diff
changeset
|
20 |
class JEdit_Thy_Load(loaded_theories: Set[String] = Set.empty, base_syntax: Outer_Syntax) |
4accee106f0f
clarified initialization of Thy_Load, Thy_Info, Session;
wenzelm
parents:
48422
diff
changeset
|
21 |
extends Thy_Load(loaded_theories, base_syntax) |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
22 |
{ |
44615 | 23 |
override def append(dir: String, source_path: Path): String = |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
24 |
{ |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
25 |
val path = source_path.expand |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
26 |
if (path.is_absolute) Isabelle_System.platform_path(path) |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
27 |
else { |
44615 | 28 |
val vfs = VFSManager.getVFSForPath(dir) |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
29 |
if (vfs.isInstanceOf[FileVFS]) |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
30 |
MiscUtilities.resolveSymlinks( |
44615 | 31 |
vfs.constructPath(dir, Isabelle_System.platform_path(path))) |
32 |
else vfs.constructPath(dir, Isabelle_System.standard_path(path)) |
|
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
33 |
} |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
34 |
} |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
35 |
|
44963
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
36 |
def check_file(view: View, path: String): Boolean = |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
37 |
{ |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
38 |
val vfs = VFSManager.getVFSForPath(path) |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
39 |
val session = vfs.createVFSSession(path, view) |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
40 |
|
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
41 |
try { |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
42 |
session != null && { |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
43 |
try { |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
44 |
val file = vfs._getFile(session, path, view) |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
45 |
file != null && file.isReadable && file.getType == VFSFile.FILE |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
46 |
} |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
47 |
catch { case _: IOException => false } |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
48 |
} |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
49 |
} |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
50 |
finally { |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
51 |
try { vfs._endVFSSession(session, view) } |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
52 |
catch { case _: IOException => } |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
53 |
} |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
54 |
} |
4662dddc2fd8
explicit check_file wrt. jEdit VFS, to avoid slightly confusing empty buffer after IO error;
wenzelm
parents:
44953
diff
changeset
|
55 |
|
48882
61dc7d5d150a
use Thy_Header.read on explicit text only -- potentially via File.read, not Scan.byte_reader;
wenzelm
parents:
48870
diff
changeset
|
56 |
override def check_thy(name: Document.Node.Name): Document.Node.Header = |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
57 |
{ |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
58 |
Swing_Thread.now { |
44615 | 59 |
Isabelle.jedit_buffer(name.node) match { |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
60 |
case Some(buffer) => |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
61 |
Isabelle.buffer_lock(buffer) { |
48882
61dc7d5d150a
use Thy_Header.read on explicit text only -- potentially via File.read, not Scan.byte_reader;
wenzelm
parents:
48870
diff
changeset
|
62 |
Some(check_thy_text(name, buffer.getSegment(0, buffer.getLength))) |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
63 |
} |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
64 |
case None => None |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
65 |
} |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
66 |
} getOrElse { |
48409 | 67 |
val file = new JFile(name.node) // FIXME load URL via jEdit VFS (!?) |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
68 |
if (!file.exists || !file.isFile) error("No such file: " + quote(file.toString)) |
48882
61dc7d5d150a
use Thy_Header.read on explicit text only -- potentially via File.read, not Scan.byte_reader;
wenzelm
parents:
48870
diff
changeset
|
69 |
check_thy_text(name, File.read(file)) |
44577
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
70 |
} |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
71 |
} |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
72 |
} |
96b6388d06c4
separate module for jEdit primitives for loading theory files;
wenzelm
parents:
diff
changeset
|
73 |