From 47fbfdf1f0f93fd8ba9131d33ba7758eab111fb8 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 28 Mar 2013 16:43:22 -0700 Subject: [PATCH] xmode.highlight: enable highlighting of words. --- basis/xmode/highlight/highlight-docs.factor | 9 ++++----- basis/xmode/highlight/highlight.factor | 16 +++++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/basis/xmode/highlight/highlight-docs.factor b/basis/xmode/highlight/highlight-docs.factor index 06d6da45b0..b6e3170501 100644 --- a/basis/xmode/highlight/highlight-docs.factor +++ b/basis/xmode/highlight/highlight-docs.factor @@ -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)." } ; diff --git a/basis/xmode/highlight/highlight.factor b/basis/xmode/highlight/highlight.factor index 208abdefcb..1a40867ed3 100644 --- a/basis/xmode/highlight/highlight.factor +++ b/basis/xmode/highlight/highlight.factor @@ -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 ;