Re: TOC entries listed in order of \include

2022-09-25 Thread Valentin Petzel
Hi Brent,

this is exactly what my suggestion does. There are of course multiple ways of 
achieving things. You could give the toc Items labels and then order them by 
these labels.

But my suggestion simply delays interpretation of \tocItem to the point where 
you need it, by using a function (code is executed while calling the function) 
instead of a macro (code is executed while parsing).

Cheers,
Valentin

24.09.2022 18:52:12 Brent Annable :

> Hey Valentin,
> 
> Thanks so much for the reply, but I have to say I don't understand your 
> suggestion at all. Isn't there a way for me to put in the tocItems so that 
> when I move the scores in the master file, they all just reorder as they 
> should?
> 
> Brent.
> 
> On Sat, 24 Sep 2022, 11:41 pm Valentin Petzel,  wrote:
>> Hi Brent,
>> 
>> you could simply delay the execution of your code until the point where you 
>> need it like this:
>> 
>> bpI =
>> #(define-scheme-function (parser location) ()
>>     #{
>>     \bookpart {
>>     \tocItem "toc1" "a"
>>     { c' }
>>     }
>>     #})
>> 
>> bpII =
>> #(define-scheme-function (parser location) ()
>>     #{
>>     \bookpart {
>>     \tocItem "toc2" "b"
>>     { d' }
>>     }
>>     #})
>> 
>> \markuplist \table-of-contents
>> 
>> $(bpII)
>> $(bpI)
>> 
>> (Sorry for the mess, I'm writing from my phone.)
>> 
>> Cheers,
>> Valentin
>> 
>> 24.09.2022 13:36:04 Brent Annable :
>> 
>>> Hi all,
>>> 
>>> I'm creating a book of music using a master file where I call on \bookpart 
>>> variables from lots of different files, which are included in the master 
>>> file using the \include function. I have a list of included files in a 
>>> separate file, and the master just includes that one file.
>>> 
>>> I want to create a table of contents at the beginning of the book, so I 
>>> need to add a \tocItem to each score. The only place I have found where 
>>> that works is inside the \bookpart variable in each individual file, before 
>>> the score. So in my master file, each score entry looks like this:
>>> 
>>> \bookpart { \myBookPart }
>>> 
>>> And the variables in the individual files look like this:
>>> 
>>> myBookPart = \bookpart {  \tocItem \markup "Name of song"
>>> {c1 c1 c1 c1}
>>> }
>>> 
>>> I'm currently putting all the separate scores into the master file, and I 
>>> plan to shuffle them around later to get the ordering right.
>>> 
>>> I've noticed that when the table of contents is generated, the items are 
>>> always listed *in the order in which the files are \included*, not the 
>>> order in which the scores actually appear in the book. So even though the 
>>> page numbers are correct, the TOC lists the songs in the order in which I 
>>> include the files in the \include file. When I start shifting things around 
>>> later in the master, I really don't want to have to re-order the \include 
>>> list as well, that will be double the work.
>>> 
>>> I've attached some files that replicate my problem. One thing I noticed 
>>> that the master wouldn't compile at all when the version number was set to 
>>> 2.22.1, it only worked when I set it to 2.19.65, the version number in all 
>>> the files I'm using. Does that mean I'm using incorrect syntax for the TOC?
>>> 
>>> Otherwise, is there anywhere else I can put the \tocItem command so that 
>>> the items are automatically re-ordered when I switch them around in the 
>>> master file?
>>> 
>>> Sorry for the voluminous email and thanks for any help,
>>> 
>>> Brent.
>>> 
>>> 


Re: exit-hook never executed

2022-09-25 Thread Jean Abou Samra
Le 22/09/2022 à 18:25, Olivier Dion via General Guile related 
discussions a écrit :

Hi,

`exit-hook' seems to only be executed when in a REPL.  Is there a way for
it to be executed at the end of a none interactive program?

My intend here is that I have a module that load a foreign extension and
initialize its runtime so that other modules of that extension can be
used.  I then add a hook for finalizing the extension, which is
important to save data.

Here's the snippet:
--8<---cut here---start->8---
(define-module (jami)
   #:use-module (system foreing-library))

(let* ((libjami (load-foreign-library "libguile-jami"))
(init (foreign-library-function libjami "init"))
(fini (foreign-library-function libjami "fini")))
   (init)
   (add-hook! exit-hook fini))
--8<---cut here---end--->8---

So I guess the trivial solution would be to ask the user to manually
call the `init' and `fini' procedure before using any procedures of the
extension.

Something like this:
--8<---cut here---start->8---
(define-syntax-rule (with-jami body body* ...)
   (dynamic-wind
 init
 (lambda () body body* ...)
 fini))
--8<---cut here---end--->8---

But it would be nice to a have a hook for finalization like `exit-hook'
that is hidden from the user.

Though?



It looks like Guile only uses exit-hook for (ice-9 readline), so it
doesn't bother to call it when not running as REPL.

Maybe you could use a finalizer attached to a C global variable?
(I didn't test.)