reorg, add toolbar
parent
d656b4cf7a
commit
6b30895974
@ -1,29 +1,29 @@
|
||||
#lang br
|
||||
(require racket/class describe)
|
||||
(provide drracket-indenter)
|
||||
(provide indenter)
|
||||
|
||||
(define open-braces #f)
|
||||
(define indent-width 2)
|
||||
|
||||
(define (drracket-indenter txt start-pos)
|
||||
(define fresh-indent? (zero? start-pos))
|
||||
(when fresh-indent? (set! open-braces 0))
|
||||
(define (indenter drr-editor start-pos)
|
||||
(when (zero? start-pos) (set! open-braces 0))
|
||||
(define first-pos-in-this-line
|
||||
(for*/first ([pos (in-naturals start-pos)]
|
||||
[c (in-value (send txt get-character pos))]
|
||||
[c (in-value (send drr-editor get-character pos))]
|
||||
#:when (not (char-blank? c)))
|
||||
pos))
|
||||
(define last-pos-in-this-line
|
||||
(send txt find-newline 'forward first-pos-in-this-line))
|
||||
(send drr-editor find-newline 'forward first-pos-in-this-line))
|
||||
(set! open-braces
|
||||
(+ open-braces
|
||||
(for/sum ([pos (in-range first-pos-in-this-line last-pos-in-this-line)])
|
||||
(case (send txt get-character pos)
|
||||
(case (send drr-editor get-character pos)
|
||||
[(#\{) 1]
|
||||
[(#\}) -1]
|
||||
[else 0]))))
|
||||
(define first-char
|
||||
(send drr-editor get-character first-pos-in-this-line))
|
||||
(and (positive? open-braces)
|
||||
(* indent-width
|
||||
(if ((send txt get-character first-pos-in-this-line) . char=? . #\{)
|
||||
(if (first-char . char=? . #\{)
|
||||
(sub1 open-braces)
|
||||
open-braces))))
|
@ -0,0 +1,17 @@
|
||||
#lang br
|
||||
(require racket/draw)
|
||||
(provide buttons)
|
||||
|
||||
(define buttons
|
||||
(list (let ([label "Insert expression"]
|
||||
[bitmap (make-object bitmap% 16 16)]
|
||||
[callback (λ (drr-frame)
|
||||
(define drr-editor (send drr-frame get-definitions-text))
|
||||
(send drr-editor begin-edit-sequence)
|
||||
(send drr-editor insert "@$ $@")
|
||||
(send drr-editor end-edit-sequence)
|
||||
(define pos (send drr-editor get-end-position))
|
||||
(send drr-editor set-position (- pos 3))
|
||||
)]
|
||||
[number 98])
|
||||
(list label bitmap callback number))))
|
Loading…
Reference in New Issue