add "insert command char" button to DrRacket (closes #104)

pull/105/head
Matthew Butterick 9 years ago
parent 2ac1bf0ad3
commit ae161ceda8

@ -0,0 +1,32 @@
#lang racket/base
(require racket/runtime-path
racket/gui/base
racket/class)
(provide make-drracket-buttons)
(module test racket/base) ; suppress testing by `raco test`
(define-runtime-path html-png-path "server-extras/cmd-char.png")
#| for toolbar callbacks, see
http://pkg-build.racket-lang.org/doc/tools/drracket_module-language-tools.html#%28elem._drracket~3atoolbar-buttons%29
|#
(define (make-command-char-button command-char)
(let ([label (format "Insert command char ~a" command-char)]
[bitmap (make-object bitmap% html-png-path 'png/mask)]
[callback (λ (drr-frame)
(define editor (send drr-frame get-definitions-text))
(send editor begin-edit-sequence)
(send editor insert command-char)
(send editor end-edit-sequence))]
[number 99])
(list label bitmap callback number)))
(define (make-drracket-buttons command-char)
(let ([command-char-button (make-command-char-button command-char)])
(list command-char-button)))

@ -1,6 +1,6 @@
#lang racket/base #lang racket/base
(require racket/syntax syntax/strip-context racket/class) (require racket/syntax syntax/strip-context racket/class)
(require (only-in scribble/reader make-at-reader) pollen/file pollen/world pollen/project racket/list) (require (only-in scribble/reader make-at-reader) pollen/world pollen/project racket/list)
(provide define+provide-reader-in-mode (all-from-out pollen/world)) (provide define+provide-reader-in-mode (all-from-out pollen/world))
@ -64,20 +64,28 @@
(define custom-read-syntax (make-custom-read-syntax reader-mode)) (define custom-read-syntax (make-custom-read-syntax reader-mode))
(define custom-read (make-custom-read custom-read-syntax)) (define custom-read (make-custom-read custom-read-syntax))
(define (get-info in mod line col pos) (define (get-info in mod line col pos)
(λ (key default) ;; DrRacket caches source file information per session,
(case key ;; so we can do the same to avoid multiple searches for the command char.
[(color-lexer) (let ([command-char-cache (make-hash)])
(define my-make-scribble-inside-lexer (λ (key default)
(dynamic-require 'syntax-color/scribble-lexer 'make-scribble-inside-lexer (λ () #f))) (case key
(cond [my-make-scribble-inside-lexer [(color-lexer drracket:toolbar-buttons) ; only do source-path searching if we have one of these keys
(define definitions-frame (object-name in)) (define maybe-source-path (with-handlers ([exn:fail? (λ(exn) #f)])
(define maybe-source-path (with-handlers ([exn:fail? (λ(exn) #f)]) ;; Robert Findler does not endorse `get-filename` here,
(send definitions-frame get-filename))) ; will be #f if unsaved file ;; because it's sneaky and may not always work.
(define my-command-char (if maybe-source-path ;; OTOH Scribble relies on it, so IMO it's highly unlikely to change.
(parameterize ([current-directory (dirname maybe-source-path)]) (let ([maybe-definitions-frame (object-name in)])
(world:current-command-char)) (send maybe-definitions-frame get-filename)))) ; will be #f if unsaved file
world:command-char)) (define my-command-char (hash-ref! command-char-cache maybe-source-path (λ _ (world:current-command-char maybe-source-path))))
(my-make-scribble-inside-lexer #:command-char my-command-char)] (case key
[else default])] [(color-lexer)
[else default]))) (define my-make-scribble-inside-lexer
(dynamic-require 'syntax-color/scribble-lexer 'make-scribble-inside-lexer (λ () #f)))
(cond [my-make-scribble-inside-lexer
(my-make-scribble-inside-lexer #:command-char my-command-char)]
[else default])]
[(drracket:toolbar-buttons)
(define my-make-drracket-buttons (dynamic-require 'pollen/drracket-buttons 'make-drracket-buttons))
(my-make-drracket-buttons my-command-char)])]
[else default]))))
(provide (rename-out [custom-read read] [custom-read-syntax read-syntax]) get-info))) (provide (rename-out [custom-read read] [custom-read-syntax read-syntax]) get-info)))

@ -37,6 +37,10 @@ But don't knock the lozenge till you try it.
@subsection{Lozenge helpers} @subsection{Lozenge helpers}
@subsubsection{DrRacket}
When you use DrRacket, you'll see a button in the toolbar that says @onscreen{Insert command char}. This will insert the lozenge (or whatever command character you've defined for your project).
@subsubsection{AHK script} @subsubsection{AHK script}

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

Loading…
Cancel
Save