emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Emacs shell-script to tangle org-babel at the command line.
@ 2012-08-13 18:15 Matthew Oesting
  2012-08-13 19:12 ` Andrew Young
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Oesting @ 2012-08-13 18:15 UTC (permalink / raw)
  To: emacs-orgmode

I recently wrote what I thought to be a very simply she'll script to tangle a file; simply call the script on a file, e.g. 'tangle corgi.org' and a file, 'corgi.rb' (assuming one uses Ruby) appears in the local directory.

Tangling the file from within Emacs works normally.  Tangling from this script does not work; the only interesting response is "tangled 0 code blocks from corgi.org".  The same file tangles two blocks from within Emacs.

It seems that the org-babel-tangle function is using some piece of information present in the normal Emacs loading sequence which is not found during the script load.  I could provide a large number of files, but I imagine that the problem will be obvious to someone here.

What is wrong with this code?

#!/usr/bin/emacs --script

;; The subdirectory ~/.emacs.d is to be added to the top-level elisp
;; file search.
(progn (cd "~/.emacs.d") (normal-top-level-add-subdirs-to-load-path))

;; Org-Mode, Org-Babel, and the tangle library are required, if we are
;; to proceed further.
(require 'org-install)
(require 'org)
(require 'ob-tangle)

;; Load the main configuration and setup file.
(require 'ob-ruby)
(require 'ob-python)
(require 'ob-emacs-lisp)
(require 'ob-lisp)

;; Tangle all files given.
(dolist (file command-line-args-left) 
 (princ file)
 (org-babel-tangle-file file))

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

* Re: Emacs shell-script to tangle org-babel at the command line.
  2012-08-13 18:15 Emacs shell-script to tangle org-babel at the command line Matthew Oesting
@ 2012-08-13 19:12 ` Andrew Young
  2012-08-13 22:01   ` Matthew Oesting
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Young @ 2012-08-13 19:12 UTC (permalink / raw)
  To: Matthew Oesting; +Cc: emacs-orgmode

Hi Matthew,

On Mon, Aug 13, 2012 at 2:15 PM, Matthew Oesting <oestingm@me.com> wrote:
> I recently wrote what I thought to be a very simply she'll script to tangle a file; simply call the script on a file, e.g. 'tangle corgi.org' and a file, 'corgi.rb' (assuming one uses Ruby) appears in the local directory.
>
> Tangling the file from within Emacs works normally.  Tangling from this script does not work; the only interesting response is "tangled 0 code blocks from corgi.org".  The same file tangles two blocks from within Emacs.
>
> It seems that the org-babel-tangle function is using some piece of information present in the normal Emacs loading sequence which is not found during the script load.  I could provide a large number of files, but I imagine that the problem will be obvious to someone here.
>
> What is wrong with this code?
>
> #!/usr/bin/emacs --script
>
> ;; The subdirectory ~/.emacs.d is to be added to the top-level elisp
> ;; file search.
> (progn (cd "~/.emacs.d") (normal-top-level-add-subdirs-to-load-path))
>
> ;; Org-Mode, Org-Babel, and the tangle library are required, if we are
> ;; to proceed further.
> (require 'org-install)
> (require 'org)
> (require 'ob-tangle)
>
> ;; Load the main configuration and setup file.
> (require 'ob-ruby)
> (require 'ob-python)
> (require 'ob-emacs-lisp)
> (require 'ob-lisp)
>
> ;; Tangle all files given.
> (dolist (file command-line-args-left)
>  (princ file)
>  (org-babel-tangle-file file))
>
>

The previous code works for me if the file I'm trying to tangle is in
"~/.emacs.d".

I think what may be happening is you are specifying your input files
as relative paths, and when you cd into .emacs.d, you are no longer
loading from the correct directory.

Are you getting output such as
#+begin_example
  Wrote /home/user/.emacs.d/input-file.org
  tangled 0 code blocks from input-file.org
#+end_example

Try replacing:

#+begin_src emacs-lisp
  (progn (cd "~/.emacs.d")
    (normal-top-level-add-subdirs-to-load-path))
#+end_src

with something that doesn't change the current directory of the buffer
permanently. Replace the progn line with following to allow the
assigned value of default-directory to go out of scope:

#+begin_src emacs-lisp
  (let ((default-directory ~/.emacs.d))
    (normal-top-level-add-subdirs-to-load-path))
#+end_src

Andrew

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

* Re: Emacs shell-script to tangle org-babel at the command line.
  2012-08-13 19:12 ` Andrew Young
@ 2012-08-13 22:01   ` Matthew Oesting
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Oesting @ 2012-08-13 22:01 UTC (permalink / raw)
  To: Andrew Young; +Cc: emacs-orgmode

You've hit upon it exactly; this solution works perfectly.  Thank you, Andrew!

This little tidbit, a few lines at the header, and a slightly different script now make my tangled Orgmode files executable at the command line.  Ah, the joys of literate code.

 - M

This message was sent from my iPad.

On Aug 13, 2012, at 12:12 PM, Andrew Young <youngar17@gmail.com> wrote:

> Hi Matthew,
> 
> The previous code works for me if the file I'm trying to tangle is in
> "~/.emacs.d".
> ...

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

end of thread, other threads:[~2012-08-13 22:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-13 18:15 Emacs shell-script to tangle org-babel at the command line Matthew Oesting
2012-08-13 19:12 ` Andrew Young
2012-08-13 22:01   ` Matthew Oesting

Code repositories for project(s) associated with this 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).