From f4f75589864371d3a6c50eace36561a73203acee Mon Sep 17 00:00:00 2001 From: David Nalesnik Date: Thu, 26 Mar 2015 10:08:55 -0500 Subject: [PATCH] Issue 4328: Add means to display objects accessible from a grob 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 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 2b2a65c719..a73e2c0324 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -130,6 +130,44 @@ 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 -- 2.39.2