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

Matthew Butterick 9 years ago
parent 2ac1bf0ad3
commit ae161ceda8

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

@ -37,6 +37,10 @@ But don't knock the lozenge till you try it.
@subsection{Lozenge helpers}
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}

Binary file not shown.


Width:  |  Height:  |  Size: 163 B