markup->string and user markup commands

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

markup->string and user markup commands

Jérôme Plût-2

#(begin
; after http://lsr.di.unimi.it/LSR/Snippet?id=969
(define-markup-command (with-background layout props color arg) (color? markup?)
   (let* ((stencil (interpret-markup layout props arg))
          (X-ext (ly:stencil-extent stencil X))
          (Y-ext (ly:stencil-extent stencil Y)))
     (ly:stencil-add (ly:make-stencil
                      (list 'color color
                        (ly:stencil-expr (ly:round-filled-box X-ext Y-ext 0))
                        X-ext Y-ext)) stencil)))
(display "\"")
(display (markup->string (markup #:with-background `(1. 0. 0.) "something")))
(display "\"")
)

This should display "something". However it displays an empty string.
How could I fix this?

(I tried to manually debug markup->string (in scm/markup.scm): as I
understand it, the problem is likely that with-background does not
belong to the 'lily module. However, I am completely unfamiliar with
guile's module system, so I don't have the slightest idea about how to
fix this).

Thanks,

--
        Jérôme

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: markup->string and user markup commands

Thomas Morley-2
Am Do., 8. Nov. 2018 um 21:00 Uhr schrieb Jérôme Plût <[hidden email]>:

>
>
> #(begin
> ; after http://lsr.di.unimi.it/LSR/Snippet?id=969
> (define-markup-command (with-background layout props color arg) (color? markup?)
>    (let* ((stencil (interpret-markup layout props arg))
>           (X-ext (ly:stencil-extent stencil X))
>           (Y-ext (ly:stencil-extent stencil Y)))
>      (ly:stencil-add (ly:make-stencil
>                       (list 'color color
>                         (ly:stencil-expr (ly:round-filled-box X-ext Y-ext 0))
>                         X-ext Y-ext)) stencil)))
> (display "\"")
> (display (markup->string (markup #:with-background `(1. 0. 0.) "something")))
> (display "\"")
> )
>
> This should display "something". However it displays an empty string.
> How could I fix this?
>
> (I tried to manually debug markup->string (in scm/markup.scm): as I
> understand it, the problem is likely that with-background does not
> belong to the 'lily module. However, I am completely unfamiliar with
> guile's module system, so I don't have the slightest idea about how to
> fix this).
>
> Thanks,
>
> --
>         Jérôme

You could do

    (define all-relevant-markup-commands
      ;; Returns a list containing the names of all markup-commands and
      ;; markup-list-commands with predicate @code{cheap-markup?} or
      ;; @code{markup-list?} in their @code{markup-command-signature}.
      ;; @code{table-of-contents} is not caught, same for user-defined commands.
      ;; markup-commands from @code{markup-commands-to-ignore} are removed.
      (lset-difference eq?
        (map car
          (filter
            (lambda (x)
              (let* ((predicates (markup-command-signature (cdr x))))
                (and predicates
                     (not
                       (null?
                         (lset-intersection eq?
                           '(cheap-markup? markup-list?)
                           (map procedure-name predicates)))))))
;;;; !!!!!!!!!!!!!!
         (append
           (ly:module->alist (current-module))
           (ly:module->alist (resolve-module '(lily))))))
        markup-commands-to-ignore))

in markup->string from markup.scm

Not sure about unwished side-effects, though.

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user