emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Christian Köstlin" <christian.koestlin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Please add support for dlangs packagemanager to ob-C.el
Date: Mon, 26 Sep 2022 22:38:59 +0200	[thread overview]
Message-ID: <CAG741+YvASTSV+ubTuvMikRiP4F7BZH9P0nAZ5dwewsDRS1QVA@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 120 bytes --]

Please see the patch comment. I reworked my original patch to fit into the
TINYPATCH category.

Kind regards,
Christian

[-- Attachment #1.2: Type: text/html, Size: 177 bytes --]

[-- Attachment #2: 0001-lisp-ob-C.el-Support-dub-dependencies-for-dlang.patch --]
[-- Type: application/octet-stream, Size: 2922 bytes --]

From 85ee67484d85c42babc4dd616597f554099070b5 Mon Sep 17 00:00:00 2001
From: Christian Koestlin <christian.koestlin@gmail.com>
Date: Tue, 8 Mar 2022 23:12:31 +0100
Subject: [PATCH] lisp/ob-C.el: Support dub dependencies for dlang

Dlangs official package manager dub (https://dub.pm/) supports running
single files that carry dependency information in a /+ dub.sdl comment
block.

This patch switches from rdmd to dub if dependencies are used in the
source block. The dependency format used in the sourceblocks is
`:dependencies '(dep1=v1 ...)`.
The version specifier can be left out or be used with `*` which then
resolves to the latest version of the package.

Example: test.org
#+BEGIN_SRC D :dependencies '(mir-algorithm=3.16.2 dyaml=0.9.2) :results value pp
    import mir.combinatorics : permutations;
    import dyaml;
    foreach (permutation; ['a', 'b', 'c'].permutations) {
        writeln(permutation);
    }
    import std.array : appender;
    auto buffer = appender!string;
    dumper().dump(buffer, Node([1,2,3]));
    writeln(buffer.data);
#+END_SRC
TINYCHANGE
---
 lisp/ob-C.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index e9951cb79..ae97b27a1 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -176,7 +176,7 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
 	       (concat tmp-bin-file cmdline))
 	      (`d
 	       (format "%s %s %s %s"
-		       org-babel-D-compiler
+		       (if (eq 'nil (cdr (assq :dependencies params))) org-babel-D-rdmd "dub")
 		       flags
 		       (org-babel-process-file-name tmp-src-file)
 		       cmdline)))
@@ -268,11 +268,20 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
 		    (org-babel-C-ensure-main-wrap body)
 		  body) "\n") "\n")))
 
+(defun org-babel-D-dependencies (dependencies)
+  "Convert DEPENDENCIES to dub.sdl code."
+  (mapconcat (lambda (x) (let* ((s (split-string (symbol-name x) "="))
+                                (d (car s))
+                                (v (or (car (cdr s)) "*")))
+                               (format "dependency \"%s\" version=\"%s\"" d v)))
+   dependencies "\n"))
+
 (defun org-babel-C-expand-D (body params)
   "Expand a block of D code with org-babel according to its header arguments."
   (let ((vars (org-babel--get-vars params))
 	(colnames (cdr (assq :colname-names params)))
 	(main-p (not (string= (cdr (assq :main params)) "no")))
+	(dependencies (cdr (assq :dependencies params)))
 	(imports (or (cdr (assq :imports params))
 		     (org-babel-read (org-entry-get nil "imports" t)))))
     (when (stringp imports)
@@ -280,6 +289,9 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
     (setq imports (append imports '("std.stdio" "std.conv")))
     (mapconcat 'identity
 	       (list
+		"/+ dub.sdl:"
+		(org-babel-D-dependencies dependencies)
+		"+/"
 		"module mmm;"
 		;; imports
 		(mapconcat
-- 
2.37.3


             reply	other threads:[~2022-09-26 20:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 20:38 Christian Köstlin [this message]
2022-09-27 20:41 ` Please add support for dlangs packagemanager to ob-C.el Bastien
2022-09-29 19:53   ` tbanelwebmin
2022-10-29  6:34     ` Ihor Radchenko
  -- strict thread matches above, loose matches on Subject: below --
2022-03-08 22:47 Christian Köstlin
2022-03-10  8:24 ` tbanelwebmin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAG741+YvASTSV+ubTuvMikRiP4F7BZH9P0nAZ5dwewsDRS1QVA@mail.gmail.com \
    --to=christian.koestlin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).