emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dmitri Makarov <dmakarv@gmail.com>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: htmlize doesn't work in --batch mode
Date: Wed, 19 Sep 2012 20:40:56 +0200	[thread overview]
Message-ID: <AE5693F1-F63D-4383-8840-0FD2DBAAC5D6@gmail.com> (raw)
In-Reply-To: <87zk4mgd1i.fsf@bzg.ath.cx>

Hi Bastien

I actually wrote an ant script that controls the off-line publishing.
It's fairly simple, assuming ELPA packages installed in ~/.emacs.d/elpa

Another important thing to note is that font-lock-mode is not enabled by default
in --batch mode.  So I ended up writing an extra .el file that is loaded
specifically for off-line publishing.

I'll paste here the relevant fragments to share in case somebody wants to do
something similar

Here are fragments of org.el loaded by emacs --batch command:

(defun common-hook-actions ()
  "Peform actions common for all programming language modes"
  (font-lock-mode 1)
  ;; a series of set-face-attribute commands to define the
  ;; fontification for SRC blocks
  (set-face-attribute 'font-lock-builtin-face nil
                      :slant 'normal
                      :weight 'normal
                      :underline nil
                      :foreground "#FFFFFF")
  ;; more of the same
)

(add-hook 'c-mode-hook
          (lambda ()
            (common-hook-actions)))

;; more mode-hooks can be added

(setq org-publish-timestamp-directory "../.org-timestamps/")
;; at this point I have (setq org-publish-project-alist
;; for the projects we need to publish

And this is a fragment of my build.xml:

  <target name="find-htmlize"
          description="Find the latest installation of emacs htmlize package">
    <property environment="env"/>
    <exec executable="find"
          outputproperty="find-output"
          resultproperty="find-result">
      <arg value="${env.HOME}/.emacs.d/elpa"/>
      <arg value="-type"/>
      <arg value="d"/>
      <arg value="-name"/>
      <arg value="htmlize*"/>
      <redirector>
        <outputfilterchain>
          <tailfilter lines="1"/>
        </outputfilterchain>
      </redirector>
    </exec>
    <condition property="htmlize"
               value="${find-output}"
               else="htmlize">
      <available file="${find-output}" type="dir"/>
    </condition>
  </target>

  <target name="publish"
          depends="find-htmlize"
          description="Generate HTML and save into web directory on the local disk">
    <condition property="emacs"
               value="/usr/local/bin/emacs"
               else="emacs">
      <available file="/usr/local/bin/emacs"/>
    </condition>
    <exec executable="${emacs}" dir="org" failonerror="true">
      <arg value="--batch"/>
      <arg value="-l"/>
      <arg value="org.el"/>
      <arg value="--eval"/>
      <arg value="(progn (add-to-list 'load-path &quot;${htmlize}&quot;) (load-library &quot;htmlize&quot;))"/>
      <arg value="-f"/>
      <arg value="org-publish-all"/>
    </exec>
  </target>

All of the above creates completely autonomous publishing project. We actually
use it collaboratively, so other people can checkout the repository, edit org
files, build html (or pdf) from the org project and publish updated content on
the web-server without having to modify their ~/.emacs (or ~/.emacs.d/init.el)
files.  Everything is done with two simple shell commands invoking ant.

I hope somebody will find this useful.

Regards,

Dmitri

On Sep 19, 2012, at 7:03 PM, Bastien <bzg@altern.org> wrote:

> Hi Dmitri,
> 
> Dmitri Makarov <dmakarv@gmail.com> writes:
> 
>> If anyone interested, it's easy to explicitly load the required ELPA
>> packages in batch mode.  For example, the following command loads htmlize
>> for publishing org files in batch mode
>> 
>> emacs --batch -l ~/.emacs.d/init.el --eval "(progn (add-to-list 'load-path
>> \"~/.emacs.d/elpa/htmlize-20120616.1716\") (require 'htmlize))" -f
>> org-publish-all
>> 
>> It should be easy to include such a command in a makefile or build.xml and
>> automatically locate the latest installation of necessary packages rather
>> than explicitly specifying the path.
> 
> I let Achim be the final judge on this -- my intuitions in this areas
> are just too fragile.  But my gut feeling is that this would be too
> complicated, and the solution above is simple enough.
> 
>> Still I wonder why ELPA packages are not loaded by default in --batch
>> mode even though (package-initialize) is being evaluated.
> 
> Please ask this on the emacs-devel mailing list, I'm sure this will help
> many other users.  Several users (including me) have been puzzled by the
> way ELPA packages are loaded/initialized in Emacs.
> 
> Best,
> 
> -- 
> Bastien

  parent reply	other threads:[~2012-09-19 18:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-14  9:38 htmlize doesn't work in --batch mode Dmitri Makarov
2012-09-19 17:03 ` Bastien
2012-09-19 18:29   ` Achim Gratz
2012-09-19 18:40   ` Dmitri Makarov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-09-11 13:16 Dmitri Makarov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AE5693F1-F63D-4383-8840-0FD2DBAAC5D6@gmail.com \
    --to=dmakarv@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).