adjust the way the tabify preferences are saved so that new

additions to the default preferences are seen by everyone

related to PR 13810
This commit is contained in:
Robby Findler 2013-08-19 16:53:08 -05:00
parent a4b994c3cb
commit 940ccc8b5c

View File

@ -140,7 +140,8 @@
(preferences:add-callback 'framework:special-meta-key (λ (p v) (map-command-as-meta-key v))) (preferences:add-callback 'framework:special-meta-key (λ (p v) (map-command-as-meta-key v)))
(map-command-as-meta-key (preferences:get 'framework:special-meta-key)) (map-command-as-meta-key (preferences:get 'framework:special-meta-key))
(preferences:set-default 'framework:fraction-snip-style 'mixed (λ (x) (memq x '(mixed improper decimal)))) (preferences:set-default 'framework:fraction-snip-style
'mixed (λ (x) (memq x '(mixed improper decimal))))
(preferences:set-default 'framework:standard-style-list:font-name (preferences:set-default 'framework:standard-style-list:font-name
(get-family-builtin-face 'modern) (get-family-builtin-face 'modern)
@ -283,9 +284,8 @@
(preferences:set-default 'framework:fixup-parens #t boolean?) (preferences:set-default 'framework:fixup-parens #t boolean?)
(preferences:set-default 'framework:fixup-open-parens #f boolean?) (preferences:set-default 'framework:fixup-open-parens #f boolean?)
(preferences:set-default 'framework:paren-match #t boolean?) (preferences:set-default 'framework:paren-match #t boolean?)
(let ([hash-table (make-hasheq)]) (let ([defaults-ht (make-hasheq)])
(for-each (λ (x) (for-each (λ (x) (hash-set! defaults-ht x 'define))
(hash-set! hash-table x 'define))
'(struct '(struct
local local
@ -293,8 +293,7 @@
define: pdefine: define: pdefine:
define-type define-predicate define-type define-predicate
match-define)) match-define))
(for-each (λ (x) (for-each (λ (x) (hash-set! defaults-ht x 'begin))
(hash-set! hash-table x 'begin))
'(case-lambda case-lambda: pcase-lambda: '(case-lambda case-lambda: pcase-lambda:
match-lambda match-lambda* match-lambda match-lambda*
cond cond
@ -302,8 +301,7 @@
unit compound-unit compound-unit/sig unit compound-unit compound-unit/sig
public private override public private override
inherit sequence)) inherit sequence))
(for-each (λ (x) (for-each (λ (x) (hash-set! defaults-ht x 'lambda))
(hash-set! hash-table x 'lambda))
`( `(
cases cases
instantiate super-instantiate instantiate super-instantiate
@ -360,32 +358,76 @@
for-all for-all
type-case type-case))
))
(preferences:set-default (preferences:set-default
'framework:tabify 'framework:tabify
(list hash-table #rx"^begin" #rx"^def" #f) (list defaults-ht #rx"^begin" #rx"^def" #f)
(λ (x) (λ (x)
(and (list? x) (and (list? x)
(= (length x) 4) (= (length x) 4)
(hash? (car x)) (hash? (car x))
(andmap (λ (x) (or (regexp? x) (not x))) (cdr x))))) (andmap (λ (x) (or (regexp? x) (not x))) (cdr x)))))
(define old-style-pred? (listof (list/c symbol? symbol?)))
(define pref-pred?
(list/c (or/c
;; old-style prefs
old-style-pred?
;; new-style prefs
(list/c (listof (list/c symbol? symbol?)) ;; additions to defaults
(listof (list/c symbol? symbol?)))) ;; deletions
(or/c regexp? #f)
(or/c regexp? #f)
(or/c regexp? #f)))
(define (ht->addition/deletion-lists ht)
(define additions '())
(define deletions '())
(for ([(k v) (in-hash ht)])
(unless (hash-ref defaults-ht k #f)
(set! additions (cons (list k v) additions))))
(for ([(k v) (in-hash defaults-ht)])
(unless (hash-ref ht k #f)
(set! deletions (cons (list k v) deletions))))
(list additions deletions))
(define (addition/deletion-lists->ht lsts)
(define additions (list-ref lsts 0))
(define deletions (list-ref lsts 1))
(define ht (hash-copy defaults-ht))
(for ([pr (in-list deletions)])
(define k (list-ref pr 0))
(define v (list-ref pr 1))
(when (equal? (hash-ref ht k #f) v)
(hash-remove! ht k)))
(for ([pr (in-list additions)])
(define k (list-ref pr 0))
(define v (list-ref pr 1))
(hash-set! ht k v))
ht)
(preferences:set-un/marshall (preferences:set-un/marshall
'framework:tabify 'framework:tabify
(λ (t) (cons (hash-map (car t) list) (λ (t) (cons (ht->addition/deletion-lists (list-ref t 0))
(cdr t))) (cdr t)))
(λ (l) (λ (l)
(and (list? l) (and (pref-pred? l)
(= (length l) 4) (cond
(andmap (λ (x) (or (regexp? x) (not x))) [(old-style-pred? (list-ref l 0))
(cdr l)) ;; when migrating prefs from the old style,
(andmap (λ (x) (and (list? x) ;; get rid of any apparent deletions, as
(= 2 (length x)) ;; they are likely unintentional, a result
(andmap symbol? x))) ;; of moving defaults
(car l)) (define h (make-hasheq))
(let ([h (make-hasheq)]) (for-each (λ (x) (apply hash-set! h x)) (list-ref l 0))
(for-each (λ (x) (apply hash-set! h x)) (car l)) (define lsts (ht->addition/deletion-lists h))
(cons h (cdr l))))))) (cons (addition/deletion-lists->ht (list (list-ref l 0)
'()))
(cdr l))]
[else
(cons (addition/deletion-lists->ht (list-ref l 0))
(cdr l))])))))
(preferences:set-default 'framework:autosave-delay 300 number?) (preferences:set-default 'framework:autosave-delay 300 number?)
@ -432,7 +474,8 @@
(let ([delta (make-object style-delta%)] (let ([delta (make-object style-delta%)]
[style (send (editor:get-standard-style-list) find-named-style color:misspelled-text-color-style-name)]) [style (send (editor:get-standard-style-list) find-named-style
color:misspelled-text-color-style-name)])
(if style (if style
(send style set-delta delta) (send style set-delta delta)
(send (editor:get-standard-style-list) new-named-style color:misspelled-text-color-style-name (send (editor:get-standard-style-list) new-named-style color:misspelled-text-color-style-name