adjust the square-bracket prefs so they are saved
relative to some default settings instead of saving the actual values so changes to the default imply changes to everyone's actual values for the prefs closes PR 13810
This commit is contained in:
parent
5b7532c864
commit
5f0c06956a
|
@ -1,6 +1,7 @@
|
||||||
#lang racket/unit
|
#lang racket/unit
|
||||||
(require racket/class
|
(require racket/class
|
||||||
racket/contract
|
racket/contract
|
||||||
|
racket/list
|
||||||
"sig.rkt"
|
"sig.rkt"
|
||||||
"../preferences.rkt"
|
"../preferences.rkt"
|
||||||
mred/mred-sig)
|
mred/mred-sig)
|
||||||
|
@ -74,7 +75,7 @@
|
||||||
|
|
||||||
(preferences:set-default 'framework:paren-color-scheme 'basic-grey symbol?)
|
(preferences:set-default 'framework:paren-color-scheme 'basic-grey symbol?)
|
||||||
|
|
||||||
(preferences:set-default 'framework:square-bracket:cond/offset
|
(define cond/offset-defaults
|
||||||
'(("case-lambda" 0)
|
'(("case-lambda" 0)
|
||||||
("match-lambda" 0)
|
("match-lambda" 0)
|
||||||
("match-lambda*" 0)
|
("match-lambda*" 0)
|
||||||
|
@ -84,22 +85,81 @@
|
||||||
("match" 1)
|
("match" 1)
|
||||||
("new" 1)
|
("new" 1)
|
||||||
("case" 1)
|
("case" 1)
|
||||||
|
("datum-case" 1)
|
||||||
("match" 1)
|
("match" 1)
|
||||||
("match*" 1)
|
("match*" 1)
|
||||||
("syntax-rules" 1)
|
("syntax-rules" 1)
|
||||||
("syntax-case" 2)
|
("syntax-case" 2)
|
||||||
("syntax-case*" 3)
|
("syntax-case*" 3)
|
||||||
("kernel-syntax-case" 2)
|
("kernel-syntax-case" 2)
|
||||||
("kernel-syntax-case*" 3))
|
("kernel-syntax-case*" 3)))
|
||||||
(λ (x) (and (list? x) (andmap (λ (x) (and (pair? x)
|
(preferences:set-default 'framework:square-bracket:cond/offset
|
||||||
(string? (car x))
|
cond/offset-defaults
|
||||||
(pair? (cdr x))
|
(listof (list/c string? exact-nonnegative-integer?)))
|
||||||
(number? (cadr x))
|
|
||||||
(null? (cddr x))))
|
(preferences:set-un/marshall
|
||||||
x))))
|
'framework:square-bracket:cond/offset
|
||||||
(preferences:set-default 'framework:square-bracket:local
|
(λ (val)
|
||||||
'("local")
|
(define deletions (for/list ([line (in-list cond/offset-defaults)]
|
||||||
(λ (x) (and (list? x) (andmap string? x))))
|
#:unless (ormap (λ (val-line)
|
||||||
|
(equal? (car line) (car val-line)))
|
||||||
|
val))
|
||||||
|
(list-ref line 0)))
|
||||||
|
(define additions/changes (for/list ([line (in-list val)]
|
||||||
|
#:when (not (member line cond/offset-defaults)))
|
||||||
|
line))
|
||||||
|
(list additions/changes deletions))
|
||||||
|
(λ (marsh)
|
||||||
|
(cond
|
||||||
|
[((listof (list/c string? exact-nonnegative-integer?)) marsh)
|
||||||
|
;; old style prefs: don't try to find any deletions, as they are
|
||||||
|
;; probably caused by a stale defaults setting
|
||||||
|
(define ht (make-hash (map (λ (x) (cons (list-ref x 0) (list-ref x 1))) cond/offset-defaults)))
|
||||||
|
(for ([line (in-list marsh)])
|
||||||
|
(hash-set! ht (list-ref line 0) (list-ref line 1)))
|
||||||
|
(hash-map ht list)]
|
||||||
|
[((list/c (listof (list/c string? exact-nonnegative-integer?)) (listof string?)) marsh)
|
||||||
|
;; new style-pref
|
||||||
|
(define additions/changes (list-ref marsh 0))
|
||||||
|
(define deletions (list-ref marsh 1))
|
||||||
|
(define ht (make-hash (map (λ (x) (cons (list-ref x 0) (list-ref x 1))) cond/offset-defaults)))
|
||||||
|
(for ([del (in-list deletions)])
|
||||||
|
(hash-remove! ht del))
|
||||||
|
(for/list ([line (in-list additions/changes)])
|
||||||
|
(hash-set! ht (list-ref line 0) (list-ref line 1)))
|
||||||
|
(hash-map ht list)])))
|
||||||
|
|
||||||
|
|
||||||
|
(define (set-square-bracket-nonum-pref pref-sym defaults)
|
||||||
|
(preferences:set-default pref-sym defaults (listof string?))
|
||||||
|
(preferences:set-un/marshall
|
||||||
|
pref-sym
|
||||||
|
(λ (val)
|
||||||
|
(define additions '())
|
||||||
|
(define deletions '())
|
||||||
|
(for ([itm (in-list val)])
|
||||||
|
(unless (member itm defaults)
|
||||||
|
(set! additions (cons itm additions))))
|
||||||
|
(for ([def (in-list defaults)])
|
||||||
|
(unless (member def val)
|
||||||
|
(set! deletions (cons def deletions))))
|
||||||
|
(list additions deletions))
|
||||||
|
(λ (marshed)
|
||||||
|
(cond
|
||||||
|
[((listof string?) marshed)
|
||||||
|
;; this is the old preference; in this case
|
||||||
|
;; we ignore any deletions while unmarshalling
|
||||||
|
;; as those are likely caused by a defaults
|
||||||
|
;; set that got bigger
|
||||||
|
(remove-duplicates (append marshed defaults))]
|
||||||
|
[((list/c (listof string?) (listof string?)) marshed)
|
||||||
|
(define additions (list-ref marshed 0))
|
||||||
|
(define deletions (list-ref marshed 1))
|
||||||
|
(append additions (remove* deletions defaults))]))))
|
||||||
|
|
||||||
|
|
||||||
|
(set-square-bracket-nonum-pref 'framework:square-bracket:local
|
||||||
|
'("local"))
|
||||||
|
|
||||||
(define all-fors
|
(define all-fors
|
||||||
(let ()
|
(let ()
|
||||||
|
@ -117,7 +177,7 @@
|
||||||
untyped-fors)))
|
untyped-fors)))
|
||||||
all-fors))
|
all-fors))
|
||||||
|
|
||||||
(preferences:set-default 'framework:square-bracket:letrec
|
(set-square-bracket-nonum-pref 'framework:square-bracket:letrec
|
||||||
(append (map symbol->string all-fors)
|
(append (map symbol->string all-fors)
|
||||||
'("let"
|
'("let"
|
||||||
"let*" "let-values" "let*-values"
|
"let*" "let-values" "let*-values"
|
||||||
|
@ -126,8 +186,7 @@
|
||||||
"letrec"
|
"letrec"
|
||||||
"letrec-syntaxes" "letrec-syntaxes+values" "letrec-values"
|
"letrec-syntaxes" "letrec-syntaxes+values" "letrec-values"
|
||||||
"parameterize" "parameterize*"
|
"parameterize" "parameterize*"
|
||||||
"with-syntax"))
|
"with-syntax" "with-handlers")))
|
||||||
(λ (x) (and (list? x) (andmap string? x))))
|
|
||||||
|
|
||||||
(preferences:set-default 'framework:white-on-black? #f boolean?)
|
(preferences:set-default 'framework:white-on-black? #f boolean?)
|
||||||
|
|
||||||
|
@ -362,11 +421,7 @@
|
||||||
(preferences:set-default
|
(preferences:set-default
|
||||||
'framework:tabify
|
'framework:tabify
|
||||||
(list defaults-ht #rx"^begin" #rx"^def" #f)
|
(list defaults-ht #rx"^begin" #rx"^def" #f)
|
||||||
(λ (x)
|
(list/c hash? (or/c #f regexp?) (or/c #f regexp?) (or/c #f regexp?)))
|
||||||
(and (list? x)
|
|
||||||
(= (length x) 4)
|
|
||||||
(hash? (car x))
|
|
||||||
(andmap (λ (x) (or (regexp? x) (not x))) (cdr x)))))
|
|
||||||
(define old-style-pred? (listof (list/c symbol? symbol?)))
|
(define old-style-pred? (listof (list/c symbol? symbol?)))
|
||||||
(define pref-pred?
|
(define pref-pred?
|
||||||
(list/c (or/c
|
(list/c (or/c
|
||||||
|
|
Loading…
Reference in New Issue
Block a user