MIMETypes.st
changeset 2298 2d09f75ee005
parent 2142 d9537c2a5c64
child 2375 723e3325bad1
--- a/MIMETypes.st	Sat Apr 07 23:52:29 2007 +0200
+++ b/MIMETypes.st	Tue Apr 10 16:35:37 2007 +0200
@@ -8,10 +8,7 @@
  be provided or otherwise made available to, or used by, any
  other person.  No title to or ownership of the software is
  hereby transferred.
-
-
 "
-
 "{ Package: 'stx:libview2' }"
 
 Object subclass:#MIMETypes
@@ -21,7 +18,8 @@
 		SuffixToCommentStringMapping FileSuffixToTypeMapping
 		FilenameToTypeMapping FileSuffixToImageReaderClassMapping
 		CharSetToFontMapping LastSuffix LastType
-		DefaultCommandPerMIMEPerOS DefaultPrintCommandPerMIMEPerOS'
+		DefaultCommandPerMIMEPerOS DefaultPrintCommandPerMIMEPerOS
+		TypeToParentesisSpecMapping SuffixToParentesisSpecMapping'
 	poolDictionaries:''
 	category:'Net-Communication-Support'
 !
@@ -95,12 +93,13 @@
     self initializeFileNameToMimeTypeMapping.
     self initializeImageReaderMappings.
     self initializeCommentStringMappings.
+    self initializeParentesisSpecMappings.
 
     "
      self initialize
     "
 
-    "Modified: / 12-05-2004 / 11:07:20 / cg"
+    "Modified: / 10-04-2007 / 15:16:44 / cg"
 !
 
 initializeCommentStringMappings
@@ -169,6 +168,10 @@
         put:#('//' ('/*' '*/')).          
 
     TypeToCommentStringMapping 
+        at:'application/x-lisp-source'
+        put:#(';' (nil nil)).           "/ '#' for EOL comments only
+
+    TypeToCommentStringMapping 
         at:'application/x-asn1-source'
         put:#('--' ('--' '--')).          
 
@@ -180,7 +183,9 @@
 
     SuffixToCommentStringMapping 
         at:'rs'
-        put:#(';' (nil nil)).          
+        put:#(';' (nil nil)).
+
+    "Modified: / 07-04-2007 / 16:12:05 / cg"
 !
 
 initializeDefaultCommands
@@ -310,6 +315,73 @@
     FileSuffixToImageReaderClassMapping at:'jpg'  put:JPEGReader.
     FileSuffixToImageReaderClassMapping at:'gif'  put:GIFReader.
     FileSuffixToImageReaderClassMapping at:'tif'  put:TIFFReader.
+!
+
+initializeParentesisSpecMappings
+    |spec|
+
+    TypeToParentesisSpecMapping := Dictionary new.
+    SuffixToParentesisSpecMapping := Dictionary new.
+
+    "/ ST/X spec
+    spec := IdentityDictionary new.       
+    spec at:#open        put:#( $( $[ ${ "$> $<") .
+    spec at:#close       put:#( $) $] $} "$> $<").
+    spec at:#ignore      put:#( $' $" '$[' '$]' '${' '$)' ).
+    spec at:#eolComment  put:'"/'.   
+
+    TypeToParentesisSpecMapping
+        at:'application/x-smalltalk-source'
+        put:spec.           
+
+    "/ ST/X spec
+    spec := IdentityDictionary new.       
+    spec at:#open        put:#( $< ) .
+    spec at:#close       put:#( $< ).
+    spec at:#ignore      put:#( $' $" '$[' '$]' '${' '$)' ).
+
+    #('text/html' 'text/xml' 'application/xml')
+    do:[:eachXMLType |
+        TypeToParentesisSpecMapping
+            at:eachXMLType
+            put:spec
+    ].
+
+    "/ ANSI-c
+    spec := IdentityDictionary new.       
+    spec at:#open        put:#( $( $[ ${ ) .
+    spec at:#close       put:#( $) $] $} ).
+    spec at:#ignore      put:#( $' $" ).
+    spec at:#eolComment  put:'//'.   
+
+    TypeToParentesisSpecMapping
+        at:'application/x-c-source'
+        put:spec.           
+
+    TypeToParentesisSpecMapping
+        at:'application/x-cpp-source'
+        put:spec.          
+
+    TypeToParentesisSpecMapping
+        at:'application/x-java-source'
+        put:spec.          
+
+    TypeToParentesisSpecMapping
+        at:'application/x-javascript'
+        put:spec.          
+
+    "/ Lisp
+    spec := IdentityDictionary new.       
+    spec at:#open        put:#( $(  ) .
+    spec at:#close       put:#( $)  ).
+    spec at:#ignore      put:#( $" ).
+    spec at:#eolComment  put:';'.   
+
+    TypeToParentesisSpecMapping
+        at:'application/x-lisp-source'
+        put:spec.
+
+    "Created: / 10-04-2007 / 15:16:37 / cg"
 ! !
 
 !MIMETypes class methodsFor:'initialization-lists'!
@@ -366,7 +438,10 @@
         'mak'                        'application/x-make'
         'bat'                        'application/x-batch-script'
         ('asn1' 'x409' 'gdmo' 'gdm') 'application/x-asn1-source'
+        ('lisp' 'lsp' 'scm' 'ss')    'application/x-lisp-source'
     )
+
+    "Modified: / 09-04-2007 / 09:46:04 / cg"
 !
 
 applicationTextTypeList
@@ -965,6 +1040,60 @@
      mime := MIMETypes mimeTypeForFilename:'Object.st'.
      MIMETypes commentStringsForMimeType:mime suffix:nil.    
     "
+!
+
+parentesisSpecForFilename:aFilename
+    "return a useful parentesis spec; heuristics for now.
+     The returned value is a dictionary to be used as parentesis spec in an editor"
+
+     |mime|
+
+     mime := MIMETypes mimeTypeForFilename:aFilename.
+     ^ self parentesisSpecForMimeType:mime suffix:(aFilename asFilename suffix)
+
+    "
+     MIMETypes parentesisSpecForFilename:'Object.st'. 
+     MIMETypes parentesisSpecForFilename:'Foo.java'. 
+     MIMETypes parentesisSpecForFilename:'Foo.html'. 
+     MIMETypes parentesisSpecForFilename:'Foo.lsp'. 
+    "
+
+    "Created: / 10-04-2007 / 15:18:41 / cg"
+!
+
+parentesisSpecForFilename:aFilename ifUnknown:alternative
+     |mime|
+
+     mime := MIMETypes mimeTypeForFilename:aFilename.
+     ^ self parentesisSpecForMimeType:mime suffix:(aFilename asFilename suffix) ifUnknown:alternative
+
+    "Created: / 10-04-2007 / 15:26:20 / cg"
+!
+
+parentesisSpecForMimeType:mime suffix:suff
+    ^ self
+        parentesisSpecForMimeType:mime suffix:suff 
+        ifUnknown: nil
+
+    "Created: / 10-04-2007 / 15:19:39 / cg"
+!
+
+parentesisSpecForMimeType:mime suffix:suff ifUnknown:alternativeValue
+    |spec|
+
+    spec := TypeToParentesisSpecMapping at:mime ifAbsent:nil.
+    spec notNil ifTrue:[
+        ^ spec
+    ].
+
+    spec := SuffixToParentesisSpecMapping at:suff ifAbsent:nil.
+    spec notNil ifTrue:[
+        ^ spec
+    ].
+
+    ^ alternativeValue value
+
+    "Created: / 10-04-2007 / 15:20:38 / cg"
 ! !
 
 !MIMETypes::MIMEType class methodsFor:'documentation'!
@@ -1062,7 +1191,7 @@
 !MIMETypes class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.87 2006-07-28 12:49:40 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.88 2007-04-10 14:35:37 cg Exp $'
 ! !
 
 MIMETypes initialize!