emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* :libs header in fortran code blocks
@ 2019-09-27 22:29 Alberto Ramos
  0 siblings, 0 replies; only message in thread
From: Alberto Ramos @ 2019-09-27 22:29 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 665 bytes --]


  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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-fortran.el-Add-support-for-libs-header.patch --]
[-- Type: text/x-patch, Size: 1810 bytes --]

From 5c42f43bc2c1e95a54e0bee0f7f97e4d673238e9 Mon Sep 17 00:00:00 2001
From: Alberto Ramos <alberto.ramos@desy.de>
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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-27 22:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27 22:29 :libs header in fortran code blocks Alberto Ramos

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