Subject: bug#73638: 31.0.50; doc-view: imenu index cannot be made for LaTeX PDFs

From: Visuwesh <[email-masked]>
Date: Sun, 06 Oct 2024 16:02:15 +0530

[ஞாயிறு அக்டோபர் 06, 2024] Tassilo Horn wrote:

> Visuwesh <[email-masked]> writes:
>
>> When "mutool run" is called without any script argument, it opens a
>> REPL.  We would need to `process-send-string' to the REPL but the REPL
>> reports syntax error when I try to do so.  This is after trying to
>> "minify" the JS script.  Maybe I am doing something wrong.  I've
>> attached my test lisp at the end.
>
> I've tried doing the same and also get syntax errors.  Same if I just
> copy&paste the script with injected filename in the REPL on a terminal.
> Both for the original script as well as for a minified version.  First
> I've thought that function definitions won't work at all but that's not
> the case, e.g., I can enter this funcion at the REPL and it'll work:
>
>> function bar(i){if(i==0) print("done"); else {print(i);bar(i-1);}}
>> bar(10)
> 10
> 9
> 8
> 7
> 6
> 5
> 4
> 3
> 2
> 1
> done
>
>
> Ok, after experimenting a bit more and minimizing by hand, this version
> of the script can be copy&pasted into the REPL and should probably also
> work with process-send-string.

Thanks for looking into this, and the solution!

> var document = new Document.openDocument("/home/horn/sample.pdf", "application/pdf");
> var outline = document.loadOutline();
> if(!outline) quit();
> function pp(outl, level){print("((level . " + level + ")");print("(title . " + repr(outl.title) + ")");print("(page . " + document.resolveLink(outl.uri) + "))");if(outl.down){for(var i=0; i<outl.down.length; i++){pp(outl.down[i], level+1);}}};
> function run(){print("(");for(var i=0; i<outline.length; i++){pp(outline[i], 1);}print(")");};
> run();
>
> It looks like the REPL wants function definitions on one single but
> separate line.  Sadly, that's not documented so I'm not sure how
> reliable that formatting works across mutool versions or why the REPL
> doesn't accept all valid JS.  The only thing I can find in the man page
> is that the = character at the beginning of a line has the special
> meaning of "print the result of the following expression".

As you expected, your minified version works fine when doing
process-send-string.  I do have not much experience working with async
processes like this before, what do you think about the approach below?