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?
views:
89answers:
3
+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
2010-07-06 08:48:33
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
2010-07-06 09:54:35
You could just redirect output to /dev/null (unless you need to capture stdout from emacs).
ConcernedOfTunbridgeWells
2010-07-06 10:48:13
No, I don't need to capture stdout. Thanks, I've finally got it working.
Kinopiko
2010-07-06 13:26:39
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
2010-07-06 14:11:21
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
2010-07-16 09:30:53
+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
2010-07-06 09:56:57