diff --git a/quad/quadwriter/lang-helper.rkt b/quad/quadwriter/lang-helper.rkt index 01636b9e..e5638f24 100644 --- a/quad/quadwriter/lang-helper.rkt +++ b/quad/quadwriter/lang-helper.rkt @@ -1,6 +1,8 @@ #lang debug racket/base (require (for-syntax racket/base) racket/match + racket/system + racket/class syntax/strip-context scribble/reader quadwriter/core @@ -22,13 +24,17 @@ (define-syntax (new-module-begin stx) (syntax-case stx () [(_ PATH-STRING . EXPRS) - (with-syntax ([DOC (datum->syntax #'PATH-STRING 'doc)]) + (with-syntax ([DOC (datum->syntax #'PATH-STRING 'doc)] + [VIEW-RESULT (datum->syntax #'PATH-STRING 'view-result)]) #'(#%module-begin - ;; stick an nbsp in the strings so we have one printing char + (provide DOC VIEW-RESULT) (define DOC (DOC-PROC (list . EXPRS))) - (provide DOC) + (define pdf-path (path-string->pdf-path 'PATH-STRING)) + (define (VIEW-RESULT) + (when (file-exists? pdf-path) + (void (system (format "open ~a" pdf-path))))) (module+ main - (render-pdf DOC (path-string->pdf-path 'PATH-STRING)))))])))) + (render-pdf DOC pdf-path))))])))) (define (path-string->pdf-path path-string) (match (format "~a" path-string) @@ -52,3 +58,31 @@ [(txexpr tag attrs elems) (list* tag (cons 'attr-list attrs) (map loop elems))] [(? list? xs) (map loop xs)] [_ x]))) + +(define (get-info in mod line col pos) + ;; DrRacket caches source file information per session, + ;; so we can do the same to avoid multiple searches for the command char. + (define command-char-cache (make-hash)) + (define my-command-char #\◊) + (λ (key default) + (case key + [(color-lexer) + (match (dynamic-require 'syntax-color/scribble-lexer 'make-scribble-inside-lexer (λ () #false)) + [(? procedure? make-lexer) (make-lexer #:command-char my-command-char)] + [_ default])] + [(drracket:toolbar-buttons) + (match (dynamic-require 'pollen/private/drracket-buttons 'make-drracket-buttons (λ () #false)) + [(? procedure? make-buttons) (make-buttons my-command-char)])] + [(drracket:indentation) + (λ (text pos) + (define line-idx (send text position-line pos)) + (define line-start-pos (send text line-start-position line-idx)) + (define line-end-pos (send text line-end-position line-idx)) + (define first-vis-pos + (or + (for/first ([pos (in-range line-start-pos line-end-pos)] + #:unless (char-blank? (send text get-character pos))) + pos) + line-start-pos)) + (- first-vis-pos line-start-pos))] + [else default]))) diff --git a/quad/quadwriter/main.rkt b/quad/quadwriter/main.rkt index 4550de4c..18eed02a 100644 --- a/quad/quadwriter/main.rkt +++ b/quad/quadwriter/main.rkt @@ -8,5 +8,5 @@ (module reader racket/base (require "lang-helper.rkt") - (provide read-syntax) + (provide read-syntax get-info) (define read-syntax (make-read-syntax 'quadwriter quad-at-reader))) \ No newline at end of file diff --git a/quad/quadwriter/markdown.rkt b/quad/quadwriter/markdown.rkt index 890ef0b1..d73574d4 100644 --- a/quad/quadwriter/markdown.rkt +++ b/quad/quadwriter/markdown.rkt @@ -29,6 +29,6 @@ (module reader racket/base (require racket/port markdown "lang-helper.rkt") - (provide read-syntax) + (provide read-syntax get-info) (define read-syntax (make-read-syntax 'quadwriter/markdown (λ (path-string p) (xexpr->parse-tree (parse-markdown (port->string p))))))) \ No newline at end of file diff --git a/quad/quadwriter/markup.rkt b/quad/quadwriter/markup.rkt index 8d5fa93f..6adbc686 100644 --- a/quad/quadwriter/markup.rkt +++ b/quad/quadwriter/markup.rkt @@ -1,5 +1,6 @@ #lang debug racket/base (require "lang-helper.rkt" + "tags.rkt" (only-in "markdown.rkt" doc-proc)) (provide #%top #%datum #%app #%top-interaction (all-from-out "tags.rkt")) @@ -8,7 +9,7 @@ (module reader racket/base (require "lang-helper.rkt" pollen/decode) - (provide read-syntax) + (provide read-syntax get-info) (define read-syntax (make-read-syntax 'quadwriter/markup (λ (path-string ip) diff --git a/quad/quadwriter/tags.rkt b/quad/quadwriter/tags.rkt index 854da004..9761712b 100644 --- a/quad/quadwriter/tags.rkt +++ b/quad/quadwriter/tags.rkt @@ -5,6 +5,7 @@ racket/string racket/list racket/dict + racket/match txexpr/base "font.rkt") (provide (all-defined-out)) @@ -90,7 +91,8 @@ (define bullet-indent (* bullet-space-factor em)) (qexpr (list* `(inset-left ,(number->string bullet-indent)) attrs) (add-between - (for/list ([(expr idx) (in-indexed exprs)]) + (for/list ([(expr idx) (in-indexed exprs)] + #:when (txexpr? expr)) (list* (get-tag expr) (cons (list 'list-index (or bullet-val (format "~a" (add1 idx)))) (get-attrs expr)) (get-elements expr))) pbr)))