From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [babel] Need different beginning for tangled script Date: Wed, 03 Feb 2010 10:42:47 -0500 Message-ID: <87hbpygwaw.fsf@stats.ox.ac.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NchNX-0006jo-Tl for emacs-orgmode@gnu.org; Wed, 03 Feb 2010 10:42:55 -0500 Received: from [199.232.76.173] (port=55035 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NchNX-0006jK-7z for emacs-orgmode@gnu.org; Wed, 03 Feb 2010 10:42:55 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NchNT-0005qV-WC for emacs-orgmode@gnu.org; Wed, 03 Feb 2010 10:42:55 -0500 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:51934) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NchNT-0005qR-KE for emacs-orgmode@gnu.org; Wed, 03 Feb 2010 10:42:51 -0500 In-Reply-To: (Rainer M. Krug's message of "Wed, 3 Feb 2010 16:14:22 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rainer M Krug Cc: emacs-orgmode Rainer M Krug writes: > Hi > > I want to use org-mode to create a submit script for a cluster, and would= need > the first lines to be as follow: > > #!/bin/bash > #$ -cwd -j y > #$ -t 1-5 > #$ -l mem_free=3D4G > > at the moment I get: > > #!/usr/bin/env sh > # generated by org-babel-tangle > # [[file:~/Documents/Projects/BiocontrolAndAlienDynamics/HakeaLandscape/t= runc/R > /spreadSim.org::*submit%20scripts][block-19]] > #$ -cwd -j y > #$ -t 1-5 > #$ -l mem_free=3D4G > > 1) Is the first line customizable, or do I have to change org-babel-sh.el= to > use #!/bin/bash=C2=A0instead? > 2) Can I ommit the second and third line (the comments added by tangle)? Hi Rainer, Yes, I've also wanted control over these things from time to time. Here's a patch. It introduces two new variables; you would turn off both behaviours as follows: (setq org-babel-tangle-include-shebang nil) (setq org-babel-tangle-include-org-coordinates nil) If Eric approves, he'll apply the patch to the main org-mode git repo. I suspect you're using git already, but if not then you probably do want to use it for org-mode. Dan >From ebc119693ca9daf104f935e794b5e2122127fa05 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Wed, 3 Feb 2010 10:41:10 -0500 Subject: [PATCH] babel: provide control over additional content in tangled = files New variables: * org-babel-tangle-include-shebang Whether to include shebang * org-babel-tangle-include-org-coordinates Whether to include links to org file etc. --- contrib/babel/lisp/org-babel-tangle.el | 32 ++++++++++++++++++++++++++--= ---- 1 files changed, 26 insertions(+), 6 deletions(-) diff --git a/contrib/babel/lisp/org-babel-tangle.el b/contrib/babel/lisp/or= g-babel-tangle.el index 66e2c26..c019c43 100644 --- a/contrib/babel/lisp/org-babel-tangle.el +++ b/contrib/babel/lisp/org-babel-tangle.el @@ -40,6 +40,22 @@ to use when writing out the language to file, and an opt= ional fourth element is a flag which when true indicates that the language does not support comments.") =20 +(defvar org-babel-tangle-include-shebang t + "If non-nil the first line of tangled output will be a +'shebang'-style line, for example, + +#!/bin/sh + +On UNIX/linux-like operating systems these lines serve to specify +an interpreter for the code contained in the file.") + +(defvar org-babel-tangle-include-org-coordinates t + "If non-nil (and if a comment syntax is defined), each block in +the tangled output will be (a) preceded by a commented org-style +link back to the source block in the source org file, and (b) +followed by a commented statement indicating which block has just +ended.") + (defun org-babel-load-file (file) "Load the contents of the Emacs Lisp source code blocks in the org-mode formatted FILE. This function will first export the @@ -117,12 +133,12 @@ exported source code blocks by language." ;; drop source-block to file (with-temp-buffer (funcall lang-f) - (when (and she-bang (not (member file-name she-banged)= )) + (when (and org-babel-tangle-include-shebang she-bang (= not (member file-name she-banged))) (insert (concat she-bang "\n")) (setq she-banged (cons file-name she-banged))) - (when commentable + (when (and commentable org-babel-tangle-include-org-co= ordinates) (comment-region - (point) (progn (insert "generated by org-babel-tang= le") (point))) + (point) (progn (insert "Generated by org-babel-tang= le") (point))) (move-end-of-line nil)) (org-babel-spec-to-string spec) (append-to-file nil nil file-name)) @@ -188,8 +204,8 @@ form =20 (link source-name params body)" (flet ((insert-comment (text) + (insert "\n") (when commentable - (insert "\n") (comment-region (point) (progn (insert text) (p= oint))) (move-end-of-line nil) (insert "\n")))) @@ -197,9 +213,13 @@ form (source-name (second spec)) (body (fourth spec)) (commentable (not (fifth spec)))) - (insert-comment (format "[[%s][%s]]" (org-link-escape link) source-n= ame)) + (if org-babel-tangle-include-org-coordinates + (insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name= )) + (insert "\n")) (insert (format "%s" (org-babel-chomp body))) - (insert-comment (format "%s ends here" source-name))))) + (if org-babel-tangle-include-org-coordinates + (insert-comment (format "%s ends here" source-name)) + (insert "\n"))))) =20 (provide 'org-babel-tangle) ;;; org-babel-tangle.el ends here --=20 1.6.3.3