xmode.highlight: enable highlighting of words.

db4
John Benediktsson 2013-03-28 16:43:22 -07:00
parent b38f42f73c
commit 47fbfdf1f0
2 changed files with 15 additions and 10 deletions

View File

@ -1,8 +1,8 @@
! Copyright (C) 2011 John Benediktsson ! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license ! See http://factorcode.org/license.txt for BSD license
USING: help.markup help.syntax sequences strings xmode.catalog USING: help.markup help.syntax sequences strings words
xmode.highlight xmode.tokens ; xmode.catalog xmode.highlight xmode.tokens ;
IN: xmode.highlight IN: xmode.highlight
@ -20,8 +20,7 @@ HELP: highlight-lines
} ; } ;
HELP: highlight. HELP: highlight.
{ $values { "path" string } } { $values { "obj" string } }
{ $description { $description
"Highlight and print code from the specified file (represented by " "Highlight and print code from the specified " { $link word } " or path (with a mode determined using the file extension)."
{ $snippet "path" } "). The mode is determined using the file extension."
} ; } ;

View File

@ -1,9 +1,9 @@
! Copyright (C) 2011 John Benediktsson ! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license ! See http://factorcode.org/license.txt for BSD license
USING: accessors assocs colors.hex io io.encodings.utf8 io.files USING: accessors assocs colors.hex io io.encodings.utf8
io.styles kernel locals math math.parser namespaces sequences io.files io.streams.string io.styles kernel locals see
xmode.catalog xmode.marker ; sequences splitting strings words xmode.catalog xmode.marker ;
IN: xmode.highlight IN: xmode.highlight
@ -46,7 +46,7 @@ PRIVATE>
: highlight-tokens ( tokens -- ) : highlight-tokens ( tokens -- )
[ [
[ str>> ] [ id>> ] bi [ str>> ] [ id>> ] bi
[ name>> STYLES at ] [ f ] if* BASE assoc-union [ name>> STYLES at BASE assoc-union ] [ BASE ] if*
format format
] each nl ; ] each nl ;
@ -55,7 +55,13 @@ PRIVATE>
tokenize-line highlight-tokens tokenize-line highlight-tokens
] curry each drop ; ] curry each drop ;
:: highlight. ( path -- ) GENERIC: highlight. ( obj -- )
M:: string highlight. ( path -- )
path utf8 file-lines [ path utf8 file-lines [
path over first find-mode highlight-lines path over first find-mode highlight-lines
] unless-empty ; ] unless-empty ;
M: word highlight.
[ see ] with-string-writer string-lines
"factor" highlight-lines ;