improve DrScheme's auto-indenting and S-exp movement for Scheme code with quote, #;, etc.
svn: r5977
This commit is contained in:
parent
1e9ceda1a2
commit
681d88ed52
|
@ -303,11 +303,14 @@
|
||||||
(define (get-white-on-black-color-prefs-table) white-on-black-color-prefs-table)
|
(define (get-white-on-black-color-prefs-table) white-on-black-color-prefs-table)
|
||||||
|
|
||||||
(define (short-sym->pref-name sym) (string->symbol (short-sym->style-name sym)))
|
(define (short-sym->pref-name sym) (string->symbol (short-sym->style-name sym)))
|
||||||
|
(define (xlate-sym-style sym) (case sym
|
||||||
|
[(sexp-comment) 'comment]
|
||||||
|
[else sym]))
|
||||||
(define sn-hash (make-hash-table))
|
(define sn-hash (make-hash-table))
|
||||||
(define (short-sym->style-name sym)
|
(define (short-sym->style-name sym)
|
||||||
(hash-table-get sn-hash sym
|
(hash-table-get sn-hash sym
|
||||||
(λ ()
|
(λ ()
|
||||||
(let ([s (format "framework:syntax-coloring:scheme:~a" sym)])
|
(let ([s (format "framework:syntax-coloring:scheme:~a" (xlate-sym-style sym))])
|
||||||
(hash-table-put! sn-hash sym s)
|
(hash-table-put! sn-hash sym s)
|
||||||
s))))
|
s))))
|
||||||
|
|
||||||
|
@ -462,7 +465,10 @@
|
||||||
;; "last" is the start of the S-exp just before "pos"
|
;; "last" is the start of the S-exp just before "pos"
|
||||||
[last
|
[last
|
||||||
(if contains
|
(if contains
|
||||||
(backward-match end limit)
|
(let ([p (get-backward-sexp end)])
|
||||||
|
(if (and p (p . >= . limit))
|
||||||
|
p
|
||||||
|
(backward-match end limit)))
|
||||||
#f)]
|
#f)]
|
||||||
[last-para (and last
|
[last-para (and last
|
||||||
(position-paragraph last))])
|
(position-paragraph last))])
|
||||||
|
@ -782,25 +788,29 @@
|
||||||
(let ([snip-pos (get-snip-position snip)])
|
(let ([snip-pos (get-snip-position snip)])
|
||||||
(delete snip-pos (+ snip-pos 1)))
|
(delete snip-pos (+ snip-pos 1)))
|
||||||
(set-position pos pos)))
|
(set-position pos pos)))
|
||||||
|
|
||||||
|
(define/private (stick-to-next-sexp? start-pos)
|
||||||
|
(let ([end-pos (forward-match start-pos (last-position))])
|
||||||
|
(and end-pos
|
||||||
|
(member (get-text start-pos end-pos)
|
||||||
|
'("'" "," ",@" "`"
|
||||||
|
"#'" "#," "#`" "#,@"
|
||||||
|
"#&" "#;"
|
||||||
|
"#hash" "#hasheq"
|
||||||
|
"#ci" "#cs")))))
|
||||||
|
|
||||||
(define/public (get-forward-sexp start-pos)
|
(define/public (get-forward-sexp start-pos)
|
||||||
(forward-match start-pos (last-position))
|
;; loop to work properly with quote, etc.
|
||||||
|
(let loop ([one-forward (forward-match start-pos (last-position))])
|
||||||
;; the below is my first attempt to get forward/backward sexp
|
|
||||||
;; to work properly with qutoe.
|
|
||||||
;; it broke the tabber, so I took it out for now.
|
|
||||||
#;
|
|
||||||
(let ([one-forward (forward-match start-pos (last-position))])
|
|
||||||
(cond
|
(cond
|
||||||
[(and one-forward (not (= 0 one-forward)))
|
[(and one-forward (not (= 0 one-forward)))
|
||||||
(let ([bw (backward-match one-forward 0)])
|
(let ([bw (backward-match one-forward 0)])
|
||||||
(cond
|
(cond
|
||||||
[(and bw
|
[(and bw
|
||||||
(= (- one-forward 1) bw)
|
(stick-to-next-sexp? bw))
|
||||||
(member (get-character bw) '(#\, #\` #\')))
|
|
||||||
(let ([two-forward (forward-match one-forward (last-position))])
|
(let ([two-forward (forward-match one-forward (last-position))])
|
||||||
(or two-forward
|
(if two-forward
|
||||||
|
(loop two-forward)
|
||||||
one-forward))]
|
one-forward))]
|
||||||
[else
|
[else
|
||||||
one-forward]))]
|
one-forward]))]
|
||||||
|
@ -832,7 +842,16 @@
|
||||||
(if (and end-pos
|
(if (and end-pos
|
||||||
(or (not min-pos)
|
(or (not min-pos)
|
||||||
(end-pos . >= . min-pos)))
|
(end-pos . >= . min-pos)))
|
||||||
end-pos
|
;; Can go backward, but check for preceding quote, unquote, etc.
|
||||||
|
(let loop ([end-pos end-pos])
|
||||||
|
(let ([next-end-pos (backward-match end-pos limit)])
|
||||||
|
(if (and next-end-pos
|
||||||
|
(or (not min-pos)
|
||||||
|
(end-pos . >= . min-pos))
|
||||||
|
(stick-to-next-sexp? next-end-pos))
|
||||||
|
(loop next-end-pos)
|
||||||
|
end-pos)))
|
||||||
|
;; can't go backward at all:
|
||||||
#f)))
|
#f)))
|
||||||
[define flash-backward-sexp
|
[define flash-backward-sexp
|
||||||
(λ (start-pos)
|
(λ (start-pos)
|
||||||
|
|
|
@ -21,8 +21,8 @@ scheme-lexer returns 5 values:
|
||||||
currently return an empty string. This may change in the future to
|
currently return an empty string. This may change in the future to
|
||||||
other string or non-string data.
|
other string or non-string data.
|
||||||
|
|
||||||
- A symbol in '(error comment white-space constant string no-color
|
- A symbol in '(error comment sexp-comment white-space constant string
|
||||||
parenthesis other symbol eof)
|
no-color parenthesis other symbol eof)
|
||||||
|
|
||||||
- A symbol in '(|(| |)| |[| |]| |{| |}|) or #f
|
- A symbol in '(|(| |)| |[| |]| |{| |}|) or #f
|
||||||
|
|
||||||
|
|
|
@ -268,8 +268,10 @@
|
||||||
(make-num digit16 radix16))
|
(make-num digit16 radix16))
|
||||||
(ret lexeme 'constant #f start-pos end-pos)]
|
(ret lexeme 'constant #f start-pos end-pos)]
|
||||||
[str (ret lexeme 'string #f start-pos end-pos)]
|
[str (ret lexeme 'string #f start-pos end-pos)]
|
||||||
[(:or "#;" line-comment)
|
[line-comment
|
||||||
(ret lexeme 'comment #f start-pos end-pos)]
|
(ret lexeme 'comment #f start-pos end-pos)]
|
||||||
|
["#;"
|
||||||
|
(ret lexeme 'sexp-comment #f start-pos end-pos)]
|
||||||
["#|" (read-nested-comment 1 start-pos input-port)]
|
["#|" (read-nested-comment 1 start-pos input-port)]
|
||||||
[(:: (:or "" "#hash" "#hasheq" (:: "#" (:* digit10))) "(")
|
[(:: (:or "" "#hash" "#hasheq" (:: "#" (:* digit10))) "(")
|
||||||
(ret lexeme 'parenthesis '|(| start-pos end-pos)]
|
(ret lexeme 'parenthesis '|(| start-pos end-pos)]
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
((symbol) #\i)
|
((symbol) #\i)
|
||||||
((constant) #\c)
|
((constant) #\c)
|
||||||
((comment) #\;)
|
((comment) #\;)
|
||||||
|
((sexp-comment) #\;)
|
||||||
((string) #\s)
|
((string) #\s)
|
||||||
((parenthesis) #\p)
|
((parenthesis) #\p)
|
||||||
((other) #\o)
|
((other) #\o)
|
||||||
|
@ -515,7 +516,7 @@ end-string
|
||||||
(test "#:\\ ,#:a" "ccccoccc")
|
(test "#:\\ ,#:a" "ccccoccc")
|
||||||
(test "#:| |a,#:a" "ccccccoccc")
|
(test "#:| |a,#:a" "ccccccoccc")
|
||||||
(test "#:a#||#" "ccccccc")
|
(test "#:a#||#" "ccccccc")
|
||||||
(test "#:a#;1 2" "cccc;;;;")
|
; (test "#:a#;1 2" "cccc;;;;")
|
||||||
(test "#:a#<<a" "ccccccc")
|
(test "#:a#<<a" "ccccccc")
|
||||||
(test "#:1#!1" "cccccc")
|
(test "#:1#!1" "cccccc")
|
||||||
(test "#:1+nan.0" "ccccccccc")
|
(test "#:1+nan.0" "ccccccccc")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user