]> gitweb.factorcode.org Git - factor.git/commitdiff
xmode.highlight: enable highlighting of words.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 28 Mar 2013 23:43:22 +0000 (16:43 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 28 Mar 2013 23:43:22 +0000 (16:43 -0700)
basis/xmode/highlight/highlight-docs.factor
basis/xmode/highlight/highlight.factor

index 06d6da45b02cb50a55ef1c6a1ec774bbffb11333..b6e3170501037ba985335888e9249251b58d16db 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2011 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: help.markup help.syntax sequences strings xmode.catalog
-xmode.highlight xmode.tokens ;
+USING: help.markup help.syntax sequences strings words
+xmode.catalog xmode.highlight xmode.tokens ;
 
 IN: xmode.highlight
 
@@ -20,8 +20,7 @@ HELP: highlight-lines
 } ;
 
 HELP: highlight.
-{ $values { "path" string } }
+{ $values { "obj" string } }
 { $description
-    "Highlight and print code from the specified file (represented by "
-    { $snippet "path" } ").  The mode is determined using the file extension."
+    "Highlight and print code from the specified " { $link word } " or path (with a mode determined using the file extension)."
 } ;
index 208abdefcb7a591221cf1ae20f7d421696f2653e..1a40867ed3d5be9ce16cef386c983b2f23c1a315 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2011 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: accessors assocs colors.hex io io.encodings.utf8 io.files
-io.styles kernel locals math math.parser namespaces sequences
-xmode.catalog xmode.marker ;
+USING: accessors assocs colors.hex io io.encodings.utf8
+io.files io.streams.string io.styles kernel locals see
+sequences splitting strings words xmode.catalog xmode.marker ;
 
 IN: xmode.highlight
 
@@ -46,7 +46,7 @@ PRIVATE>
 : highlight-tokens ( tokens -- )
     [
         [ str>> ] [ id>> ] bi
-        [ name>> STYLES at ] [ f ] if* BASE assoc-union
+        [ name>> STYLES at BASE assoc-union ] [ BASE ] if*
         format
     ] each nl ;
 
@@ -55,7 +55,13 @@ PRIVATE>
         tokenize-line highlight-tokens
     ] curry each drop ;
 
-:: highlight. ( path -- )
+GENERIC: highlight. ( obj -- )
+
+M:: string highlight. ( path -- )
     path utf8 file-lines [
         path over first find-mode highlight-lines
     ] unless-empty ;
+
+M: word highlight.
+    [ see ] with-string-writer string-lines
+    "factor" highlight-lines ;