 
 ; Internal links (to element ids) are nice to have. These imports will be used
 ; to create a modified LinkRenderer.
-
      LinkRenderer LinkRenderer$Rendering]
     [org.pegdown.ast WikiLinkNode])
 
 ; To run from the commandline this namespace must be compiled with a `-main`
 ; method. When run from the REPL or from Leiningen `gen-class` does nothing.
-  
   (:gen-class))
 
-(def ^:dynamic *verbose?*
-  "Whether to log messages to std-err or not."
-  false)
-
-; ## Utilities
-;
-; A few utility functions to make it easier to print messages to the console,
-; iterate side-effects through a collection, access resources, encode a string
-; for use as an id or fragment identifier, and bind an output stream to `*out*`
-; over a lexical scope.
-
-(defn message [& s]
-  (when *verbose?*
-    (binding [*out* (io/writer System/err)]
-      (println (apply str s)))))
-
-(defn each
-  "Apply f to each item of coll in order for side effects only.
-  Returns nil."
-  [f coll]
-  (doseq [c coll]
-    (f c)))
-
-(defn slurp-resource
-  "Get the complete contents of a Java resource."
-  [resource-name & continue-on-failure?]
-  (try
-    (-> (.getContextClassLoader (Thread/currentThread))
-      (.getResourceAsStream resource-name)
-      (java.io.InputStreamReader.)
-      (slurp))
-    (catch Exception e
-      (message "Failed to read resource " resource-name)
-      (if continue-on-failure?
-        (message "    continuing anyway...")
-        (do (message "    aborting...")
-          (throw e))))))
-
-(defn slurp-file|resource
-  "Get the contents of the file at path, or failing that, the contents of a
-  Java resource."
-  [path & continue-on-failure?]
-  (try (slurp path)
-    (catch java.io.FileNotFoundException _
-      (message "Using internal " path)
-      (slurp-resource path continue-on-failure?))))
-
-(defn encode-anchor [s]
-  (java.net.URLEncoder/encode (.replace s " " "-") "UTF-8"))
-
-(defmacro with-out-stream [out & body]
-  `(with-open [w# (io/writer ~out)]
-     (binding [*out* w#]
-       ~@body)))
 
 ;@top-level-vars
 ; ## Top level variables
 ;
 ; A few objects need to be accessed by a number of functions: regular
 ; expressions that match the beginning of commented lines, SyntaxHighlighter
-; options, a PegDownProcessor, and a modified LinkRenderer. The dynamic
-; variables are bound once for each file that is processed and are not mutated
-; at any other time, except `*brushes*` which is bound once per invocation of
-; `render-files`.
-;
-; ### Parsing variables
+; options, a PegDownProcessor, and a modified LinkRenderer.
+;
+;
+; ### Settings
+;
+; This dynamic variable is bound once in the commandline `-main` method and is
+; never subsequently altered by the code in this namespace. The variable is
+; bound to a map containing the following settings: which SyntaxHighlighter
+; theme to use; which SyntaxHighlighter brushes to include to start with (other
+; brushes may be added automatically by the program); what CSS file to include
+; if any; and whether to log messages to std-err or not.
+(def ^:dynamic *settings*
+  {:theme "shThemeEclipse.css"
+   :static-brushes []
+   :stylesheet nil
+   :verbose? false})
+
+
+; ### Per file
+;
+; These variables are rebound for every input file.
 
 (def ^:dynamic *single-comment*
   "A string containing a single comment token."
   ";")
 
-(defn comment
-  "A regular expression matching the beginning of a commented line."
-  []
-  (re-pattern (str "^" (Pattern/quote *single-comment*) " ?")))
-
-(defn anchor
-  "A regular expression matching the beginning of an anchor line."
-  []
-  (re-pattern (str (comment) "@ *")))
-
-(defn include
-  "A regular expression matching the beginning of an include line."
-  []
-  (re-pattern (str (comment) "%include +")))
-
-; ### Style variables
+(def ^:dynamic *language*
+  "A language string for use with SyntaxHighlighter."
+  "clojure")
+
+; Brushes can be added by the program whenever a new file is processed. They
+; must be path strings. This variable is given a binding only in the
+; `[[render-files]]` function.
+(def ^:dynamic *brushes* nil)
+
 
 ;@language map
+; ### Language map
 ;
 ; Including SyntaxHighlighter brush files automatically based on file suffix or
 ; the language argument to an include directive is preferrable to explicitly


; [h50](http://code.google.com/p/h5o/), the HTML5 outliner is used to create
; a table of contents.

(defn outliner-setup []
  (println "<div id=outline></div>")
  (inline-js

   ;"html" "shBrushXml.js"
   })


; ### Pegdown instances
;
; The same [pegdown processor][pp] and [link renderer][lr] are used for each
; program execution.
;
