lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme code for extracting LilyPond header properties?


From: Nicolas Sceaux
Subject: Re: Scheme code for extracting LilyPond header properties?
Date: Wed, 03 Oct 2007 22:29:20 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin)

John Zaitseff <address@hidden> writes:

> [...]  What I would like to do, however, is to replace
> the "\fromproperty #'header:maintainer" with something like:
>
>     \with-url #"mailto:address@hidden";
>         \fromproperty #'header:maintainer
>
> except that I would like to extract the actual e-mail address from
> header:maintainerEmail: something like:
>
>     \with-url #(string-append "mailto:"; XXX)

Ok so basicaly you want a \email-property markup command that looks for
a header property and outputs something equivalent to:

  \with-url #"mailto:..."; "..."

First look at the \fromproperty code in scm/define-markup-command.scm,
to find out how the property is got:

(define-builtin-markup-command (fromproperty layout props symbol) (symbol?)
  "Read the @var{symbol} from property settings, and produce a stencil
from the markup contained within.  If @var{symbol} is not defined, it
returns an empty markup."
  (let* ((m (chain-assoc-get symbol props)))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Your \email-property markup command will begin the same way:

(define-markup-command (email-property layout props symbol) (symbol?)
  (let ((address (chain-assoc-get symbol props)))

(use `define-markup-command' for user defined commands).

Then, figure out out to build the markup with this address
argument. Inspect other markup commands in that file, and the
documentation. Supposing for the moment that address is a string:

  (markup #:with-url (string-append "mailto:"; address) address)

which is the scheme way of building the markup:

  \markup \with-url #(string-append "mailto:"; address) \address

Finally, as you can notice by reading other markup command definitions,
markup commands shall return a stencil, not a markup. You do that by
calling `interpret-markup':

  (interpret-markup layout props (markup ...))

So you markup command definition may look like that:

(define-markup-command (email-property layout props symbol) (symbol?)
  (let ((address (chain-assoc-get symbol props)))
    (interpret-markup layout props
                      (markup #:with-url (string-append "mailto:"; address)
                                         address))))

Actually address is not necessarily a string, so you may want to add a
test here, in case address is actually a markup:

(define-markup-command (email-property layout props symbol) (symbol?)
  (let ((address (chain-assoc-get symbol props)))
    (interpret-markup layout props
                      (if (string? address)
                          (markup #:with-url (string-append "mailto:"; address)
                                              address)
                          address))))


------- test-email.ly  -------
#(define-markup-command (email-property layout props symbol) (symbol?)
  (let ((address (chain-assoc-get symbol props)))
    (interpret-markup layout props
                      (if (string? address)
                          (markup #:with-url (string-append "mailto:"; address)
                                              address)
                          address))))

\header {
  email = "address@hidden"
  emailMarkup = \markup \bold address@hidden
  tagline = \markup \column {
    Emails:
    \email-property #'header:email
    \email-property #'header:emailMarkup
  } 
}

\markup Test
------- test-email.ly  -------

nicolas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]