]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4328: Add means to display objects accessible from a grob
authorDavid Nalesnik <david.nalesnik@gmail.com>
Thu, 26 Mar 2015 15:08:55 +0000 (10:08 -0500)
committerDavid Nalesnik <david.nalesnik@gmail.com>
Sat, 28 Mar 2015 13:09:51 +0000 (08:09 -0500)
A convenient way to display the grobs and grob-objects pointed to by
various internal properties of a given grob would be very helpful for
debugging and development purposes.  For example, it would facilitate the
creation of advanced tweaks, which frequently require "lateral" access
to other grobs.

The output of the function 'grob::display-objects' shows all of the grobs
accessible to a given grob through ly:grob-object together with the relevant
interfaces and properties.  It includes properties which are empty: not all
properties within an interface may be set for or used by a grob supporting
that interface.

scm/output-lib.scm

index 2b2a65c719f12ec575c6587c206180e8bf89fb8b..a73e2c0324977e6046d45c8cfb736bd59ec4c644 100644 (file)
 
     line-thickness))
 
+(define (grob::objects-from-interface grob iface)
+  "For grob @var{grob} return the name and contents of all properties
+ within interface @var{iface} having type @code{ly:grob?} or
+ @code{ly:grob-array?}."
+  (let* ((iface-entry (hashq-ref (ly:all-grob-interfaces) iface))
+         (props (if iface-entry (last iface-entry) '()))
+         (pointer-props
+          (filter
+           (lambda (prop)
+             (let ((type (object-property prop 'backend-type?)))
+               (or (eq? type ly:grob?)
+                   (eq? type ly:grob-array?))))
+           props)))
+    (if (null? pointer-props)
+        '()
+        (list iface
+          (map
+           (lambda (prop) (list prop (ly:grob-object grob prop)))
+           pointer-props)))))
+
+(define-public (grob::all-objects grob)
+  "Return a list of the names and contents of all properties having type
+ @code{ly:grob?} or @code{ly:grob-array?} for all interfaces supported by
+ grob @var{grob}."
+  (let loop ((ifaces (ly:grob-interfaces grob)) (result '()))
+    (if (null? ifaces)
+        (cons grob (list result))
+        (let ((entry (grob::objects-from-interface grob (car ifaces))))
+          (if (pair? entry)
+              (loop (cdr ifaces) (append result (list entry)))
+              (loop (cdr ifaces) result))))))
+
+(use-modules (ice-9 pretty-print))
+(define-public (grob::display-objects grob)
+  "Display all objects stored in properties of grob @var{grob}."
+  (pretty-print (grob::all-objects grob))
+  (newline))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; beam slope