unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* colored fonts in batch mode
@ 2008-05-08  9:15 Carsten Dominik
  2008-05-08 11:22 ` Jason Rumney
  2008-05-08 16:02 ` Johan Bockgård
  0 siblings, 2 replies; 9+ messages in thread
From: Carsten Dominik @ 2008-05-08  9:15 UTC (permalink / raw)
  To: help-gnu-emacs


Hi,

I am trying to use emacs in batch mode to convert org-mode files to
HTML.  In the process, I would like to use font-lock to fontify some
snippets, and then use htmlize.el to convert the fontification into
HTML.

This works great in interactive work, when I actually have a window
system running.  However, in batch mode, Emacs seems to think that it
is displaying on a black-and-white device, so the fontification is much
poorer in this case.

Is there a way to run Emacs in batch mode (i.e. without any display at
all) and still make it use the fonts/colors for a full color display?

Thanks.

- Carsten


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: colored fonts in batch mode
  2008-05-08  9:15 colored fonts in batch mode Carsten Dominik
@ 2008-05-08 11:22 ` Jason Rumney
  2008-05-08 12:23   ` Carsten Dominik
  2008-05-08 16:02 ` Johan Bockgård
  1 sibling, 1 reply; 9+ messages in thread
From: Jason Rumney @ 2008-05-08 11:22 UTC (permalink / raw)
  To: help-gnu-emacs

On May 8, 10:15 am, Carsten Dominik <domi...@science.uva.nl> wrote:

> This works great in interactive work, when I actually have a window
> system running.  However, in batch mode, Emacs seems to think that it
> is displaying on a black-and-white device, so the fontification is much
> poorer in this case.

Try putting the following in a file (batch-color.el) and loading it as
the first part of your batch operation:

(set-frame-parameter nil 'display-type 'color)
(defun display-color-cells (&optional display)
  "Fake hicolor display"
  65536)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: colored fonts in batch mode
  2008-05-08 11:22 ` Jason Rumney
@ 2008-05-08 12:23   ` Carsten Dominik
  2008-05-08 14:18     ` Eli Zaretskii
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Carsten Dominik @ 2008-05-08 12:23 UTC (permalink / raw)
  To: help-gnu-emacs

Jason Rumney <jasonrumney@gmail.com> writes:

> On May 8, 10:15 am, Carsten Dominik <domi...@science.uva.nl> wrote:
>
>> This works great in interactive work, when I actually have a window
>> system running.  However, in batch mode, Emacs seems to think that it
>> is displaying on a black-and-white device, so the fontification is much
>> poorer in this case.
>
> Try putting the following in a file (batch-color.el) and loading it as
> the first part of your batch operation:
>
> (set-frame-parameter nil 'display-type 'color)
> (defun display-color-cells (&optional display)
>   "Fake hicolor display"
>   65536)

Hmmm, I see where you are heading.  However, in batch mode,
set-frame-parameter does not seem to be defined as a function....  Also
a (require 'frame) does not seem to help.

Any further ideas?

Thanks!

- Carsten



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: colored fonts in batch mode
  2008-05-08 12:23   ` Carsten Dominik
@ 2008-05-08 14:18     ` Eli Zaretskii
       [not found]     ` <mailman.11327.1210256313.18990.help-gnu-emacs@gnu.org>
  2008-05-08 15:45     ` Jason Rumney
  2 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2008-05-08 14:18 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Carsten Dominik <dominik@science.uva.nl>
> Date: Thu, 08 May 2008 14:23:36 +0200
> Distribution: world
> 
> > (set-frame-parameter nil 'display-type 'color)
> > (defun display-color-cells (&optional display)
> >   "Fake hicolor display"
> >   65536)
> 
> Hmmm, I see where you are heading.  However, in batch mode,
> set-frame-parameter does not seem to be defined as a function....  Also
> a (require 'frame) does not seem to help.
> 
> Any further ideas?

How about using the --color=NUMBER command-line switch, does this
help in any way?  E.g., try with 8 as NUMBER.

I must say that what you are trying to do might simply be impossible
with Emacs, as Emacs uses frame-type specific methods to turn colors
on and off, so it needs to know what kind of frame is it dealing with.

IOW, you are trying to piggy-back on the Emacs display engine, so you
need to play by its rules.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: colored fonts in batch mode
       [not found]     ` <mailman.11327.1210256313.18990.help-gnu-emacs@gnu.org>
@ 2008-05-08 15:42       ` Dan Espen
  2008-05-09 13:45         ` Carsten Dominik
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Espen @ 2008-05-08 15:42 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Carsten Dominik <dominik@science.uva.nl>
>> Date: Thu, 08 May 2008 14:23:36 +0200
>> Distribution: world
>> 
>> > (set-frame-parameter nil 'display-type 'color)
>> > (defun display-color-cells (&optional display)
>> >   "Fake hicolor display"
>> >   65536)
>> 
>> Hmmm, I see where you are heading.  However, in batch mode,
>> set-frame-parameter does not seem to be defined as a function....  Also
>> a (require 'frame) does not seem to help.
>> 
>> Any further ideas?
>
> How about using the --color=NUMBER command-line switch, does this
> help in any way?  E.g., try with 8 as NUMBER.
>
> I must say that what you are trying to do might simply be impossible
> with Emacs, as Emacs uses frame-type specific methods to turn colors
> on and off, so it needs to know what kind of frame is it dealing with.
>
> IOW, you are trying to piggy-back on the Emacs display engine, so you
> need to play by its rules.

I'm more familiar with XEmacs than emacs, but I think
the concept applies.

Rather using batch invocation wouldn't using the emacs
equivalent of "gnudoit" be a solution?
(gnudoit sends lisp commands to a running XEmacs.)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: colored fonts in batch mode
  2008-05-08 12:23   ` Carsten Dominik
  2008-05-08 14:18     ` Eli Zaretskii
       [not found]     ` <mailman.11327.1210256313.18990.help-gnu-emacs@gnu.org>
@ 2008-05-08 15:45     ` Jason Rumney
  2 siblings, 0 replies; 9+ messages in thread
From: Jason Rumney @ 2008-05-08 15:45 UTC (permalink / raw)
  To: help-gnu-emacs

On May 8, 1:23 pm, Carsten Dominik <domi...@science.uva.nl> wrote:
> Jason Rumney <jasonrum...@gmail.com> writes:

> > (set-frame-parameter nil 'display-type 'color)
> > (defun display-color-cells (&optional display)
> >   "Fake hicolor display"
> >   65536)
>
> Hmmm, I see where you are heading.  However, in batch mode,
> set-frame-parameter does not seem to be defined as a function....  Also
> a (require 'frame) does not seem to help.

What version of Emacs are you using?

In both 22.2 and current CVS, set-frame-parameter works for me
(frame.el is dumped into Emacs, so functions it defines should always
be available).

I haven't actually tried htmlize with it to check that the faces are
defined as expected, but looking at face-spec-set-match-display, it
should cover the use of :class and :min-colors in face definitions.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: colored fonts in batch mode
  2008-05-08  9:15 colored fonts in batch mode Carsten Dominik
  2008-05-08 11:22 ` Jason Rumney
@ 2008-05-08 16:02 ` Johan Bockgård
  2008-05-09 13:46   ` Carsten Dominik
  1 sibling, 1 reply; 9+ messages in thread
From: Johan Bockgård @ 2008-05-08 16:02 UTC (permalink / raw)
  To: help-gnu-emacs

Carsten Dominik <dominik@science.uva.nl> writes:

> This works great in interactive work, when I actually have a window
> system running.  However, in batch mode, Emacs seems to think that it
> is displaying on a black-and-white device, so the fontification is
> much poorer in this case.

The easiest may be to define the faces explicitly:

  (set-face-attribute 'default nil :foreground "white" :background "blue")
  ;; etc.

-- 
Johan Bockgård


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: colored fonts in batch mode
  2008-05-08 15:42       ` Dan Espen
@ 2008-05-09 13:45         ` Carsten Dominik
  0 siblings, 0 replies; 9+ messages in thread
From: Carsten Dominik @ 2008-05-09 13:45 UTC (permalink / raw)
  To: help-gnu-emacs

Dan Espen <daneNO@MORE.mk.SPAMtelcordia.com> writes:

>
> I'm more familiar with XEmacs than emacs, but I think
> the concept applies.
>
> Rather using batch invocation wouldn't using the emacs
> equivalent of "gnudoit" be a solution?
> (gnudoit sends lisp commands to a running XEmacs.)

No, I don't think that would help.  This is an emacs progress on a
webserver that is updating our pages at orgmode.org.

OK, here is what I ended up doing:


- I created a CSS file that contains many emacs face definitions.  I
  grabbed these definitions during an interactive Emacs session, by
  creating a buffer that contained one letter with each available Emacs
  face.  Then I applied htmlize-region to this buffer, and copied the
  class definitions from the css file.  Pretty long list, but ok, I can
  clean it up if I need to.

   (with-temp-buffer
     (let ((fl (face-list))
   	(htmlize-css-name-prefix "org-")
   	(htmlize-output-type 'css)
   	f i)
       (while (setq f (pop fl)
   		 i (and f (face-attribute f :inherit)))
         (when (and (symbolp f) (or (not i) (not (listp i))))
   	(insert (org-add-props (copy-sequence "1") nil 'face f))))
       (htmlize-region (point-min) (point-max))))
   (switch-to-buffer "*html*")


- The batch process now runs htmlize not with inline-css as its method,
  but the css.  I can do this in any display, and even in batch mode,
  font-lock will still assign the correct face names to keywords in the
  buffer, and htmlize will pick up those font names rather than the
  display dependent specifications.


(defun org-export-htmlize-region-for-paste (beg end)
  "Convert the region to HTML, using htmlize.el.
This is much like `htmlize-region-for-paste', only that it uses
the settings define in the org-... variables."
  (let* ((htmlize-output-type 'css)
	 (htmlize-css-name-prefix
	  org-export-htmlize-css-font-prefix)
	 (htmlbuf (htmlize-region beg end)))
    (unwind-protect
	(with-current-buffer htmlbuf
	  (buffer-substring
	   (plist-get htmlize-buffer-places 'content-start)
	   (plist-get htmlize-buffer-places 'content-end)))
      (kill-buffer htmlbuf))))

- Now I can publish pages with source code with classes on all keywords,
  and because of the css file I have control over how things get
  displayed.  Pretty happy with that!

Thanks to everyone who replied, I did try a couple of the ideas, but in
the end the dependence in the current display is too deeply engraved in
the emacs internals, so this system is not easy to fool in a stable way.

- Carsten



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: colored fonts in batch mode
  2008-05-08 16:02 ` Johan Bockgård
@ 2008-05-09 13:46   ` Carsten Dominik
  0 siblings, 0 replies; 9+ messages in thread
From: Carsten Dominik @ 2008-05-09 13:46 UTC (permalink / raw)
  To: help-gnu-emacs

bojohan+news@dd.chalmers.se (Johan Bockgård) writes:

> Carsten Dominik <dominik@science.uva.nl> writes:
>
>> This works great in interactive work, when I actually have a window
>> system running.  However, in batch mode, Emacs seems to think that it
>> is displaying on a black-and-white device, so the fontification is
>> much poorer in this case.
>
> The easiest may be to define the faces explicitly:
>
>   (set-face-attribute 'default nil :foreground "white" :background "blue")
>   ;; etc.

Yes.  I ended up doing something in this direction, but differently.
See my other post.

Thanks.

- Carsten


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-05-09 13:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-08  9:15 colored fonts in batch mode Carsten Dominik
2008-05-08 11:22 ` Jason Rumney
2008-05-08 12:23   ` Carsten Dominik
2008-05-08 14:18     ` Eli Zaretskii
     [not found]     ` <mailman.11327.1210256313.18990.help-gnu-emacs@gnu.org>
2008-05-08 15:42       ` Dan Espen
2008-05-09 13:45         ` Carsten Dominik
2008-05-08 15:45     ` Jason Rumney
2008-05-08 16:02 ` Johan Bockgård
2008-05-09 13:46   ` Carsten Dominik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).