[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser-racket c9008a6 091/191: [WIP] Draw images inline in
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/geiser-racket c9008a6 091/191: [WIP] Draw images inline in the Racket REPL. |
Date: |
Sun, 1 Aug 2021 18:32:06 -0400 (EDT) |
branch: elpa/geiser-racket
commit c9008a6e0b7fddefbcd2a937b41e83773a71f46b
Author: Michael W <gcr@sneakygcr.net>
Commit: Michael W <gcr@sneakygcr.net>
[WIP] Draw images inline in the Racket REPL.
On the racket side, we use a custom print handler to print
images (convertible? values; see file/convertible) in a special format:
#<Image: filename>
On the geiser side, we add a comint post-output hook to search for
that filename and replace it with inline images.
---
geiser/user.rkt | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/geiser/user.rkt b/geiser/user.rkt
index c8cca24..38eefd8 100644
--- a/geiser/user.rkt
+++ b/geiser/user.rkt
@@ -14,7 +14,10 @@
(provide init-geiser-repl run-geiser-server start-geiser)
(require (for-syntax racket/base)
+ file/convertible
mzlib/thread
+ racket/file
+ racket/pretty
racket/tcp
geiser
geiser/enter
@@ -88,10 +91,30 @@
(define (geiser-prompt-read prompt)
(make-repl-reader (geiser-read prompt)))
+(define (geiser-save-tmpimage imgbytes)
+ ;; Save imgbytes to a new temporary file and return the filename
+ (define filename (make-temporary-file "geiser-img-~a.png"))
+ (with-output-to-file filename #:exists 'truncate
+ (lambda () (display imgbytes)))
+ filename)
+
+(define (geiser-maybe-print-image value)
+ (cond
+ [(and (convertible? value)
+ (convert value 'png-bytes))
+ => (lambda (pngbytes)
+ ;; (The above could be problematic if a future version of racket
+ ;; suddenly decides it can "convert" strings to picts)
+ (printf "#<Image: ~a>\n" (geiser-save-tmpimage pngbytes)))]
+ [else
+ (unless (void? value)
+ (pretty-print value))]))
+
(define (init-geiser-repl)
(compile-enforce-module-constants #f)
(current-load/use-compiled geiser-loader)
- (current-prompt-read (geiser-prompt-read geiser-prompt)))
+ (current-prompt-read (geiser-prompt-read geiser-prompt))
+ (current-print geiser-maybe-print-image))
(define (run-geiser-repl in out enforce-module-constants)
(parameterize [(compile-enforce-module-constants enforce-module-constants)
@@ -99,7 +122,8 @@
(current-output-port out)
(current-error-port out)
(current-load/use-compiled geiser-loader)
- (current-prompt-read (geiser-prompt-read geiser-prompt))]
+ (current-prompt-read (geiser-prompt-read geiser-prompt))
+ (current-print geiser-maybe-print-image)]
(read-eval-print-loop)))
(define server-channel (make-channel))
- [nongnu] elpa/geiser-racket 0c9d6c3 055/191: Guile reconnected (but not debuggable (yet)), (continued)
- [nongnu] elpa/geiser-racket 0c9d6c3 055/191: Guile reconnected (but not debuggable (yet)), Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket fbbd3ab 060/191: Superior schemes, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 58657b4 056/191: Better EOT token for more robust communication, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket fd14450 062/191: Support for implementation-specific font lock keywords, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 309ca6d 069/191: Racket: more information in symbol documentation, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket a787a26 071/191: Bug fix: don't intern symbols read by scheme reader, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket c4b8c1a 080/191: Racket: geiser-add-to-load-path implemented, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket a9405d0 095/191: Racket: reading into elisp-land the cache dir as needed, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 20cc118 083/191: Leftover code from the previous patch removed, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket ce1f555 085/191: Racket: capturing and displaying standard error during evaluation, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket c9008a6 091/191: [WIP] Draw images inline in the Racket REPL.,
Philip Kaludercic <=
- [nongnu] elpa/geiser-racket 62e2006 114/191: Indentation for Racket's struct, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 0be1797 122/191: A better solution to the funky filename problem, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket e17099e 166/191: Skip expression quote when getting a racket symbol, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 3079c3a 163/191: Racket: displaying graphics in structured objects, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket c0a617f 173/191: Begin the summary lines of all elisp libraries with three semicolons, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 99acb21 175/191: Fix indentation, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 6bc2bc2 176/191: Fix indentation, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 74a223e 008/191: Racket: autodoc for struct constructors, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 4c3903a 063/191: Better module help, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-racket 1f64738 066/191: Racket: showing submodules in module help, Philip Kaludercic, 2021/08/01