From 644ed77f9c0165e22290549660e71ff3ead573d5 Mon Sep 17 00:00:00 2001 From: Mark Polesky Date: Wed, 1 Jul 2009 16:21:14 -0700 Subject: [PATCH] Add new file lily-sort.scm; improve sorting in docs. - add new file lily-sort.scm - add "lily-sort.scm" to the ly:load list in documentation-generate.scm - "string "ly:string-citexi 'backend pr grob-description))) @@ -61,7 +61,7 @@ (hashq-ref iface->grob-table (car interface) '())) - string #:name name #:text (string-append @@ -139,7 +139,7 @@ node." (cons (cons key val) prior)) '() (ly:all-grob-interfaces))) -(set! interface-description-alist (sort interface-description-alist aliststring lst) stringstring lst) ly:string-citexi 'backend (string->symbol prop) '())) ps)) (texi (description-list->texi descs #f))) diff --git a/scm/document-functions.scm b/scm/document-functions.scm index 34d406f89f..3c7646cc79 100644 --- a/scm/document-functions.scm +++ b/scm/document-functions.scm @@ -34,7 +34,7 @@ (let* ((fdocs (map (lambda (x) (document-scheme-function (car x) (cadr x) (cddr x))) all-scheme-functions)) - (sfdocs (sort fdocs string #:name "Scheme functions" #:desc "Primitive functions exported by LilyPond." diff --git a/scm/document-identifiers.scm b/scm/document-identifiers.scm index 67e282bd86..0d67934288 100644 --- a/scm/document-identifiers.scm +++ b/scm/document-identifiers.scm @@ -46,7 +46,7 @@ (define (identifierstring (car a)) (symbol->string (car b)))) diff --git a/scm/document-markup.scm b/scm/document-markup.scm index af4a65d7c6..ef99452be7 100644 --- a/scm/document-markup.scm +++ b/scm/document-markup.scm @@ -62,7 +62,7 @@ "@end itemize\n")))))) (define (markup-functionstring (procedure-name a)) (symbol->string (procedure-name b)))) + (ly:string-cistring (procedure-name a)) (symbol->string (procedure-name b)))) (define (markup-category-doc-node category) (let* ((category-string (symbol->string category)) diff --git a/scm/document-music.scm b/scm/document-music.scm index b8190d95f4..38960ee531 100644 --- a/scm/document-music.scm +++ b/scm/document-music.scm @@ -10,7 +10,7 @@ #:name "Music properties" #:desc "All music properties, including descriptions." #:text - (let* ((ps (sort (map symbol->string all-music-properties) stringstring all-music-properties) ly:string-citexi 'music (string->symbol prop))) ps)) @@ -55,7 +55,7 @@ (human-listify (sort (map (lambda (x) (ref-ify (symbol->string x))) - (cdr entry)) stringalist music-types->names) alistalist music-types->names) ly:alist-cistring contexts) - stringstring (map car layout-alist)) stringstring (map car layout-alist)) ly:string-ci @@ -243,7 +243,7 @@ (define all-engravers-list (ly:get-all-translators)) (set! all-engravers-list (sort all-engravers-list - (lambda (a b) (stringstring (ly:translator-name a)) + (lambda (a b) (ly:string-cistring (ly:translator-name a)) (symbol->string (ly:translator-name b)))))) (define (all-engravers-doc) @@ -255,7 +255,7 @@ (map engraver-doc all-engravers-list))) (define (translation-properties-doc-string lst) - (let* ((ps (sort (map symbol->string lst) stringstring lst) ly:string-cisymbol ps)) (propdescs (map diff --git a/scm/documentation-generate.scm b/scm/documentation-generate.scm index 04b0a59942..478eb20efc 100644 --- a/scm/documentation-generate.scm +++ b/scm/documentation-generate.scm @@ -17,6 +17,7 @@ ;; todo: naming: grob vs. layout property (map ly:load '("documentation-lib.scm" + "lily-sort.scm" "document-functions.scm" "document-translation.scm" "document-music.scm" diff --git a/scm/lily-sort.scm b/scm/lily-sort.scm new file mode 100644 index 0000000000..96e83b7191 --- /dev/null +++ b/scm/lily-sort.scm @@ -0,0 +1,116 @@ +;;;; lily-sort.scm -- improved sorting of symbols, strings, and alists. +;;;; +;;;; source file of the GNU LilyPond music typesetter +;;;; +;;;; Copyright 2009 Mark Polesky + + +;; This file implements a LilyPond-specific character-sorting algorithm +;; that can be used to sort lists, alists, etc. consistently and +;; predictably throughout the source code. The primary advantage of this +;; algorithm is that lists are sorted in a more intuitive way, which may +;; allow users to find items faster in the documentation. +;; +;; As an example, a user, looking in the documentation to see if there's +;; a function called "ly:grob?", might assume that there isn't one, +;; since it doesn't appear before "ly:grob-alist-chain" (using the +;; default sort). +;; +;; This happens because "-" comes before "?" in the default sort order. +;; But since "?" is more likely to come at the end of a scheme symbol, a +;; more intuitive sort can be achieved by reversing that order. +;; +;; Similarly, non-alphanumeric characters can be ranked in terms of how +;; likely one will be found closer to the end of a symbol. For example, +;; ":" is stronger separator than "-", as can be seen here: +;; +;; "ly:staff-symbol::print" +;; "ly:staff-symbol-referencer::callback" +;; +;; Intuitively, "staff-symbol-referencer" ought to come after +;; "staff-symbol", but since "-" comes before ":" in the default sort +;; order, these symbols are by default listed in the opposite order. +;; +;; Thus the algorithm implemented here ranks the following nine +;; characters (starting with the space character) in order from +;; most-to-least likely to terminate a symbol: " !?<=>:-_". These nine +;; characters are in effect "extracted" from the default order and then +;; "prepended" to it so that they now come first. This is achieved with +;; the function "ly:char-generic-list " !?<=>:-_")) + (mem-a (member a init-list)) + (mem-b (member b init-list))) + (cond ((and mem-a mem-b) (< (length mem-b) (length mem-a))) + (mem-a #t) + (mem-b #f) + (else ((if ci char-cilist str0)) (b (string->list str1))) + (cond ((and (null? a) (null? b)) #f) + ((null? a) (cons #f (car b))) + ((null? b) (cons (car a) #f)) + ((not ((if ci char-ci=? char=?) (car a) (car b))) + (cons (car a) (car b))) + (else (find-mismatch (cdr a) (cdr b)))))) + +(define (ly:string-generic-string a) + (symbol->string b))) + +(define (ly:symbol-cistring a) + (symbol->string b))) + +(define (ly:aliststring (car a)) + (symbol->string (car b)))) + +(define (ly:alist-cistring (car a)) + (symbol->string (car b)))) -- 2.39.2