emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Please add support for dlangs packagemanager to ob-C.el
@ 2022-10-01 19:29 Christian Köstlin
  0 siblings, 0 replies; only message in thread
From: Christian Köstlin @ 2022-10-01 19:29 UTC (permalink / raw)
  To: emacs-orgmode


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

Thanks a lot for you feedbacks!

I rebased my change now, and I hope my changed commit message now conforms
more the the projects standard.
I will send in another patchset including some unittests, if I can get them
to work locally at my machine.

Thanks in advance,
Christian

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

[-- Attachment #2: 0001-lisp-ob-C.el-Support-dub-in-ob-D.patch --]
[-- Type: application/octet-stream, Size: 2500 bytes --]

From 17cf9c9c1a4cde9760dd80e582b3177b0be57858 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 in ob-D

Dlangs official package manager dub (https://dub.pm/) supports running
single files that carry dub-dependency information in a 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=1.0.0 ...)`.
The version specifier can be left out or be used with `*` which then
resolves to the latest version of the package.

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 74309a0e9..b3a4f61cb 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


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

only message in thread, other threads:[~2022-10-01 19:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-01 19:29 [PATCH] Please add support for dlangs packagemanager to ob-C.el Christian Köstlin

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).