From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Young Subject: Re: Emacs shell-script to tangle org-babel at the command line. Date: Mon, 13 Aug 2012 15:12:34 -0400 Message-ID: References: <060745A0-24ED-40CC-B501-B35969434F5F@me.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:37567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1045-0006cG-Sl for emacs-orgmode@gnu.org; Mon, 13 Aug 2012 15:12:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1044-0001tS-Cj for emacs-orgmode@gnu.org; Mon, 13 Aug 2012 15:12:37 -0400 Received: from mail-wg0-f49.google.com ([74.125.82.49]:61291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1044-0001tD-6o for emacs-orgmode@gnu.org; Mon, 13 Aug 2012 15:12:36 -0400 Received: by wgbez12 with SMTP id ez12so2981346wgb.30 for ; Mon, 13 Aug 2012 12:12:35 -0700 (PDT) In-Reply-To: <060745A0-24ED-40CC-B501-B35969434F5F@me.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matthew Oesting Cc: "emacs-orgmode@gnu.org" Hi Matthew, On Mon, Aug 13, 2012 at 2:15 PM, Matthew Oesting wrote: > I recently wrote what I thought to be a very simply she'll script to tang= le 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 s= cript does not work; the only interesting response is "tangled 0 code block= s 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 inform= ation present in the normal Emacs loading sequence which is not found durin= g 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