3

I want use emacsclient -e "command" to covert org mode file to html file, such as:

emacsclient -e "(org-html-export-as-html ./mynote.org)" > ./mynote.html

hope it will be save output to mynote.html file.
But I'm not familiar with elisp yet. Actually, org-html-export-as-html has many parameter I don't know how to use it.

Drew
  • 29,895
  • 7
  • 74
  • 104
LoranceChen
  • 2,453
  • 2
  • 22
  • 48

2 Answers2

3

A/ You can do it "yourself" with:

emacsclient -e "(progn (find-file \"file.org\") (org-html-export-to-html) (kill-buffer))" 

Caveat: to make it works you should have started Emacs with

emacs --daemon 

or if you already have an Emacs running, type M-x server-start

B/ use a github package

https://github.com/nhoffman/org-export

which creates some compiled lisp executables:

  • org-export html
  • org-export tangle
  • ...

However my personnal experience is that the command line approach is faster.

C/ Bonus, tangling file

You can tangle files with the same command line approach:

emacsclient -e "(org-babel-tangle-file \"file.org\")"

Update, gives more details about C/

"tangling" is a term coined from literate programming

Literate programming (LP) tools are used to obtain two representations from a literate source file: one suitable for further compilation or execution by a computer, the "tangled" code, and another for viewing as formatted documentation, which is said to be "woven" from the literate source.[3] While the first generation of literate programming tools were computer language-specific, the later ones are language-agnostic and exist above the programming languages.

You have a unique file:

#+TITLE: My Org file

* Configuration

#+BEGIN_SRC bash :tangle yes :tangle "tangled.sh" :shebang "#!/bin/bash"
echo "This is my configuration script"
echo "..do something interesting here.."
#+END_SRC

You can html export it (parts A/ or B/), but but can also export the code it contains, here a shell script. From Emacs this can be done with C-c C-v t or, from shell, using the command I provided in C/ part. The result is the automatic generation of the tangled.sh file.

You can have a look here: Babel: active code in Org-mode for further details.

Picaud Vincent
  • 10,518
  • 5
  • 31
  • 70
  • A works great for me! B seems great to but I'm not test yet. C print nil without nothing. Can you give me some explain of C? Document say the method `Extract the bodies of source code blocks in FILE.` I don't know what's the means – LoranceChen Jan 06 '18 at 00:32
  • Hi, can I set body-only when export html file, such as: `emacsclient -e "(progn (setq body-only 1) (find-file \"docker.org\") (org-html-export-to-html) (kill-buffer))"`. I give attempt but it not affect at all. – LoranceChen Jan 06 '18 at 01:50
  • I finally find &optional usage in elisp. Outputting only body could be deal with `emacsclient -e "(progn (find-file \"file.org\") (org-html-export-to-html nil nil nil 1 nil) (kill-buffer))"` is ok. ;-) – LoranceChen Jan 06 '18 at 04:01
  • I have detailed the C part (see Update) – Picaud Vincent Jan 06 '18 at 08:15
  • I always use the "command line" approach (A/ and C/). In the past, I have tested B/ but the commands were significantly slower than a direct emacs server + shell command line approach. Maybe this is no longer the case now, I do not know. – Picaud Vincent Jan 06 '18 at 08:31
0

IMHO, correct way should be

emacsclient -e "(org-html-publish-to-html '()  \"file.org\" \".\")"

But it complains about *ERROR*: ‘org-publish-cache-get’ called, but no cache present - for me it looks like a bug in Org-mode

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • 1
    If you want to export you should use an export function; if you want to publish you should use a publish function. But publishing requires more setup than export does. – NickD Jan 06 '18 at 03:27
  • @Nick - yes, my bad - you're correct... But to use export functions more setup also necessary... – Alex Ott Jan 06 '18 at 10:02
  • Not really: see the other answer. You open the file and you export it. – NickD Jan 06 '18 at 15:11