From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alberto Ramos Subject: :libs header in fortran code blocks Date: Fri, 27 Sep 2019 23:29:27 +0100 Message-ID: <86lfu9jrug.fsf@maths.tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:43395) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDylw-0007Qx-El for emacs-orgmode@gnu.org; Fri, 27 Sep 2019 18:31:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iDylu-0008DN-V1 for emacs-orgmode@gnu.org; Fri, 27 Sep 2019 18:31:32 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:40006) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iDylu-0007nL-L3 for emacs-orgmode@gnu.org; Fri, 27 Sep 2019 18:31:30 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id A1CA9A2A3D for ; Sat, 28 Sep 2019 00:31:25 +0200 (CEST) Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id Hmas01_wMukR for ; Sat, 28 Sep 2019 00:31:21 +0200 (CEST) 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" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi all, I am completely new to this mailing list, and in fact to elisp. I am an user of org-babel, and in particular use a lot of fortran code blocks. One annoyance is that these blocks were not supporting the :libs header: I had to tangle the code and compile it by hand. After asking for a solution in emacs-reddit (https://www.reddit.com/r/emacs/comments/d8krp0/org_mode_code_blocks_and_libraries/), I was suggested to try to contribute with a patch. Here it is. Since it is the first time that I do something like this, please let me know if something is wrong or not done correctly. Thanks to all for the awesome org-mode! A. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-fortran.el-Add-support-for-libs-header.patch >From 5c42f43bc2c1e95a54e0bee0f7f97e4d673238e9 Mon Sep 17 00:00:00 2001 From: Alberto Ramos Date: Fri, 27 Sep 2019 23:11:02 +0100 Subject: [PATCH] ob-fortran.el: Add support for :libs header lisp/ob-fortran.el: Add support for :libs header in fortran code blocks. TINYCHANGE --- lisp/ob-fortran.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lisp/ob-fortran.el b/lisp/ob-fortran.el index f1285f6ab..6e3421a75 100644 --- a/lisp/ob-fortran.el +++ b/lisp/ob-fortran.el @@ -40,6 +40,10 @@ (defvar org-babel-default-header-args:fortran '()) +(defconst org-babel-header-args:fortran '((libs . :any)) + "Fortran-specific header arguments.") + + (defvar org-babel-fortran-compiler "gfortran" "fortran command used to compile a fortran source code file into an executable.") @@ -50,15 +54,23 @@ (tmp-bin-file (org-babel-temp-file "fortran-bin-" org-babel-exeext)) (cmdline (cdr (assq :cmdline params))) (flags (cdr (assq :flags params))) + (libs (org-babel-read + (or (cdr (assq :libs params)) + (org-entry-get nil "libs" t)) + nil)) + (libs (mapconcat #'identity + (if (listp libs) libs (list libs)) + " ")) (full-body (org-babel-expand-body:fortran body params))) (with-temp-file tmp-src-file (insert full-body)) (org-babel-eval - (format "%s -o %s %s %s" + (format "%s -o %s %s %s %s" org-babel-fortran-compiler (org-babel-process-file-name tmp-bin-file) (mapconcat 'identity (if (listp flags) flags (list flags)) " ") - (org-babel-process-file-name tmp-src-file)) "") + (org-babel-process-file-name tmp-src-file) + libs) "") (let ((results (org-trim (org-remove-indentation -- 2.22.0 --=-=-=--