tags:

views:

89

answers:

3

I want to automate a job involving font lock mode using Emacs. I want to fontify a file and then convert it to HTML using the colouring of font lock mode. The problem is that Emacs refuses to fontify the file unless it thinks it is running in a terminal. In other words it will not fontify when running under -batch. Is there a way to fool Emacs into thinking it is running inside a terminal even when it is being run programmatically?

+1  A: 

You could try using expect to wrap it and see if that fools emacs enough. Another alternative is to dig through the elisp code and frig it to remove whatever checks for isatty or prevents the job from running.

ConcernedOfTunbridgeWells
I tried "expect" but it still prints a lot of garbage onto the screen, which was one of the problems I was trying to avoid. I'll keep on researching into expect to find if there is a way to not have it write output.
Kinopiko
You could just redirect output to /dev/null (unless you need to capture stdout from emacs).
ConcernedOfTunbridgeWells
No, I don't need to capture stdout. Thanks, I've finally got it working.
Kinopiko
+1  A: 

What about using the -batch parameter ?

Sebastien Tanguy
That is exactly the problem; if I run it with -batch it doesn't work.
Kinopiko
Ah, really? What you were doing looks exactly like htmlize.el and I'm pretty sure it used to work in batch mode without any problem. Could you tell us how you solved it?
Sebastien Tanguy
I solved it by using the `expect` program, as described above. Unfortunately it makes the whole thing a bit slow. You are right that I am using htmlize.el, but it doesn't work unless it is connected to a terminal (for me, anyway). Do you need more details?
Kinopiko
+1  A: 

Advanced Programming in the Unix Environment provides a src.tar.gz for all the source code in the book; the 'pty' directory contains sample code for creating a pty master/slave program, which can fake the existence of a tty. I tested this out using cron:

* * * * * /tmp/apue.2e/pty/pty /usr/bin/tty > /tmp/pty.out 2> /tmp/pty.err
* * * * * /usr/bin/tty > /tmp/tty.out 2> /tmp/tty.err

And the output is pleasing:

==> /tmp/pty.out <==
/dev/pts/5

==> /tmp/tty.out <==
not a tty

It's at least good enough to fool tty. :)

sarnold