[O] Export an org file from the command line in the background

2011-10-19 Thread Viktor Rosenfeld
Hi,

is it possible to export an org file from the command line, so that a
currently running Emacs instance is not disturbed? I want to export the
attached org file and run the included source blocks, so I have an
activity report in the end. I use the shell script pasted below, but
there are two problems:

- my Emacs instance is blocked during the execution of the shell
  scripts contained in the file
- the script globally sets org-confirm-babel-evaluate to nil for my
  Emacs instance

The second problem could possibly be solved with a local file variable.
But the first problem remains. If I use emacs instead of emacsclient, it
complains about a running Emacs instance.

  #!/bin/sh

  emacsclient -c \
  --eval (progn
(find-file \macports.org\))
(setq org-confirm-babel-evaluate nil)
(org-export-as-html 3)
(kill-buffer)
(delete-frame))

I'm using Org-Mode 7.7.

Cheers,
Viktor
#+TITLE: MacPorts Update Report

* Helper functions  
  :noexport:
** Set up =$PATH= environment

Set up =$PATH=:

#+begin_src sh :session port-update :results silent
PATH=$PATH:/opt/local/bin
#+end_src

** Table Header for the list of outdated ports

#+begin_src sh :session port-update :results silent
print_outdated_header() {
echo \|Port\|Installed\|Available\|
echo |--|
}
#+end_src

** Format each row of =port outdated= as table entry

#+begin_src sh :session port-update :results silent
format_port_outdated() {
awk '{print | $1 | $2 | $4 |}'
}
#+end_src

* Outdated ports

The following ports are outdated:

#+begin_src sh :session port-update :results output raw :exports results
print_outdated_header
port -q outdated | format_port_outdated
#+end_src

The following outdated ports are requested:

#+begin_src sh :session port-update :results output raw :exports results
print_outdated_header
port -q outdated and requested | format_port_outdated
#+end_src

* Update log

#+begin_src sh :session port-update :exports results :results verbatim
for i in 1 2 3 4 5 6 7 8 9 0; do echo .; done
#+end_src


Re: [O] Export an org file from the command line in the background

2011-10-19 Thread Jambunathan K

C-h v org-export-run-in-background

 Hi,

 is it possible to export an org file from the command line, so that a
 currently running Emacs instance is not disturbed? I want to export the
 attached org file and run the included source blocks, so I have an
 activity report in the end. I use the shell script pasted below, but
 there are two problems:

 - my Emacs instance is blocked during the execution of the shell
   scripts contained in the file
 - the script globally sets org-confirm-babel-evaluate to nil for my
   Emacs instance

 The second problem could possibly be solved with a local file variable.
 But the first problem remains. If I use emacs instead of emacsclient, it
 complains about a running Emacs instance.

   #!/bin/sh

   emacsclient -c \
   --eval (progn
 (find-file \macports.org\))
 (setq org-confirm-babel-evaluate nil)
 (org-export-as-html 3)
 (kill-buffer)
 (delete-frame))

 I'm using Org-Mode 7.7.

 Cheers,
 Viktor


-- 



Re: [O] Export an org file from the command line in the background

2011-10-19 Thread Viktor Rosenfeld
Hi,

Jambunathan K wrote:

 
 C-h v org-export-run-in-background

This only works for org-export, but not for org-export-as-XXX.

Additionally, it appears that setting org-confirm-babel-evaluate locally
does not have an effect on background exports. Even setting it globally
in a running Emacs instance won't work; the command has to be in a file
that is loaded during Emacs startup.

The help contains the following text which I don't understand:

  This variable is safe as a file local variable if its value
  satisfies the predicate which is byte-compiled expression.

Cheers,
Viktor

 
  Hi,
 
  is it possible to export an org file from the command line, so that a
  currently running Emacs instance is not disturbed? I want to export the
  attached org file and run the included source blocks, so I have an
  activity report in the end. I use the shell script pasted below, but
  there are two problems:
 
  - my Emacs instance is blocked during the execution of the shell
scripts contained in the file
  - the script globally sets org-confirm-babel-evaluate to nil for my
Emacs instance
 
  The second problem could possibly be solved with a local file variable.
  But the first problem remains. If I use emacs instead of emacsclient, it
  complains about a running Emacs instance.
 
#!/bin/sh
 
emacsclient -c \
--eval (progn
  (find-file \macports.org\))
  (setq org-confirm-babel-evaluate nil)
  (org-export-as-html 3)
  (kill-buffer)
  (delete-frame))
 
  I'm using Org-Mode 7.7.
 
  Cheers,
  Viktor
 
 
 -- 
 



Re: [O] Export an org file from the command line in the background

2011-10-19 Thread Nick Dokos
Viktor Rosenfeld listuse...@googlemail.com wrote:

 Hi,
 
 Jambunathan K wrote:
 
  
  C-h v org-export-run-in-background
 
 This only works for org-export, but not for org-export-as-XXX.
 
 Additionally, it appears that setting org-confirm-babel-evaluate locally
 does not have an effect on background exports. Even setting it globally
 in a running Emacs instance won't work; the command has to be in a file
 that is loaded during Emacs startup.
 
 The help contains the following text which I don't understand:
 
   This variable is safe as a file local variable if its value
   satisfies the predicate which is byte-compiled expression.
 
 Cheers,
 Viktor
 
  
   Hi,
  
   is it possible to export an org file from the command line, so that a
   currently running Emacs instance is not disturbed? I want to export the
   attached org file and run the included source blocks, so I have an
   activity report in the end. I use the shell script pasted below, but
   there are two problems:
  
   - my Emacs instance is blocked during the execution of the shell
 scripts contained in the file
   - the script globally sets org-confirm-babel-evaluate to nil for my
 Emacs instance
  
   The second problem could possibly be solved with a local file variable.
   But the first problem remains. If I use emacs instead of emacsclient, it
   complains about a running Emacs instance.
  
 #!/bin/sh
  
 emacsclient -c \
 --eval (progn
   (find-file \macports.org\))
   (setq org-confirm-babel-evaluate nil)
   (org-export-as-html 3)
   (kill-buffer)
   (delete-frame))
  
   I'm using Org-Mode 7.7.
  


The usual method is to run a separate emacs in batch mode: that will avoid any 
conflicts
with the running instance. But batch implies -q, so you will have to provide a 
minimal .emacs
file that sets up enough structure to enable you to do what you want:

 emacs --batch -l ~/minimal.emacs \
   --eval '(let ((org-confirm-babel-evaluate nil))
(find-file macports.org)
(org-export-as-html 3))'

should do it.

minimal.emacs would just load org - modulo path differences, something like:

--8---cut here---start-8---
;;; -*- mode: emacs-lisp -*-
;;; constant part
(add-to-list 'load-path (expand-file-name ~/src/emacs/org/org-mode/lisp))
(add-to-list 'load-path (expand-file-name 
~/src/emacs/org/org-mode/contrib/lisp))
(add-to-list 'auto-mode-alist '(\\.\\(org\\|org_archive\\|txt\\)$ . org-mode))
(require 'org-install)
--8---cut here---end---8---

Also note the let bind of org-confirm-babel-evaluate: that would alleviate the
second problem you mentioned above in the emacsclient case (and although it's
irrelevant in the emacs case, I still prefer the let bind over the explicit 
setq).

HTH,
Nick









Re: [O] Export an org file from the command line in the background

2011-10-19 Thread Viktor Rosenfeld
Hi Nick,

Nick Dokos wrote:

 The usual method is to run a separate emacs in batch mode: that will avoid 
 any conflicts
 with the running instance. But batch implies -q, so you will have to provide 
 a minimal .emacs
 file that sets up enough structure to enable you to do what you want:
 
  emacs --batch -l ~/minimal.emacs \
--eval '(let ((org-confirm-babel-evaluate nil))
 (find-file macports.org)
   (org-export-as-html 3))'
 
 should do it.

Thanks for your help. I got it running using a similar setup. One more
question, it doesn't matter if I put the code in the file that is loaded
via -l or in the --eval block, correct? I've included the code in the my
org file, so I can tangle it. I find it better to have all the Emacs
code in one location.

Here's what I came up with:

  (add-to-list 'load-path (expand-file-name ~/unix/src/org-mode/lisp))
  (add-to-list 'load-path (expand-file-name ~/unix/src/org-mode/contrib/lisp))
  (require 'org)
  (require 'ob-sh)
  (require 'ansi-color)
  (let ((ansi-color-for-comint-mode nil)
(org-confirm-babel-evaluate nil)
(org-use-sub-superscripts nil))
(find-file ~/org/projects/macports/macports.org)
(org-with-point-at
(org-id-find 83583083-47B7-44DF-8474-1C6D03491C97 'marker)
  (org-babel-execute-subtree))
(org-export-as-html t)
(kill-buffer))

Thanks again,
Viktor



Re: [O] Export an org file from the command line in the background

2011-10-19 Thread Nick Dokos
Viktor Rosenfeld listuse...@googlemail.com wrote:

 ... 
 One more question, it doesn't matter if I put the code in the
 file that is loaded via -l or in the --eval block, correct? I've
 included the code in the my org file, so I can tangle it. I find it
 better to have all the Emacs code in one location.


Correct. Which is preferable is very much a matter of usage patterns and
taste.

 Here's what I came up with:
 
   (add-to-list 'load-path (expand-file-name ~/unix/src/org-mode/lisp))
   (add-to-list 'load-path (expand-file-name 
 ~/unix/src/org-mode/contrib/lisp))
   (require 'org)
   (require 'ob-sh)
   (require 'ansi-color)
   (let ((ansi-color-for-comint-mode nil)
 (org-confirm-babel-evaluate nil)
 (org-use-sub-superscripts nil))
 (find-file ~/org/projects/macports/macports.org)
 (org-with-point-at
 (org-id-find 83583083-47B7-44DF-8474-1C6D03491C97 'marker)
   (org-babel-execute-subtree))
 (org-export-as-html t)
 (kill-buffer))

You don't need the kill-buffer if emacs is just going to exit. But it doesn't 
hurt.

Nick