emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Please add support for dlangs packagemanager to ob-C.el
@ 2022-03-08 22:47 Christian Köstlin
  2022-03-10  8:24 ` tbanelwebmin
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Köstlin @ 2022-03-08 22:47 UTC (permalink / raw)
  To: emacs-orgmode


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

I Hope the patch already contains enough background information why its a
nice feature to have in ob-C.el.

Kind regards,
Christian

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

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

From 0fb0c86b40e0189040534a9cfe416aeb1d8beb3b 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:
#+begin_src D :dependencies '(mir-algorithm=*)
import mir.combinatorics;
import mir.ndslice.fuse;
foreach (permutation; ['a', 'b', 'c'].permutations) {
  writeln(permutation);
}
#+end_src

TINYCHANGE
---
 lisp/ob-C.el | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 4f71a8879..55d2cb6d4 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -85,6 +85,15 @@ parameter may be used, like rdmd --chatty"
   :version "24.3"
   :type 'string)
 
+(defcustom org-babel-D-dub "dub"
+  "Command of the dlang package manager dub.
+May be either a command in the path, like dub
+or an absolute path name, like /usr/local/bin/dub
+parameter may be used, like dub --verbose"
+  :group 'org-babel
+  :version "24.3"
+  :type 'string)
+
 (defvar org-babel-c-variant nil
   "Internal variable used to hold which type of C (e.g. C or C++ or D)
 is currently being evaluated.")
@@ -173,7 +182,9 @@ 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
+		       (pcase (cdr (assq :dependencies params))
+                         ('nil org-babel-D-rdmd)
+                         (_ org-babel-D-dub))
 		       flags
 		       (org-babel-process-file-name tmp-src-file)
 		       cmdline)))
@@ -265,11 +276,22 @@ 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)
@@ -277,6 +299,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.33.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Please add support for dlangs packagemanager to ob-C.el
  2022-03-08 22:47 Please add support for dlangs packagemanager to ob-C.el Christian Köstlin
@ 2022-03-10  8:24 ` tbanelwebmin
  0 siblings, 0 replies; 6+ messages in thread
From: tbanelwebmin @ 2022-03-10  8:24 UTC (permalink / raw)
  To: emacs-orgmode

Thanks Christian for this contribution.

Easily adding DLang dependencies while keeping a single code block seems
quite useful.
I will take a deeper look at your proposal.

Also, you marked your patch as TINYCHANGE, which imply it is less than
15 lines long. However your patch is 24 lines long. This requires that
you assign the copyright for your contributions to the FSF. Have you
signed the assignment? More on this process here:
https://orgmode.org/contribute.html

The best
Thierry
ob-C.el maintainer


Le 08/03/2022 à 23:47, Christian Köstlin a écrit :
> I Hope the patch already contains enough background information why
> its a nice feature to have in ob-C.el.
>
> Kind regards,
> Christian
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Please add support for dlangs packagemanager to ob-C.el
@ 2022-09-26 20:38 Christian Köstlin
  2022-09-27 20:41 ` Bastien
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Köstlin @ 2022-09-26 20:38 UTC (permalink / raw)
  To: emacs-orgmode


[-- 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Please add support for dlangs packagemanager to ob-C.el
  2022-09-26 20:38 Christian Köstlin
@ 2022-09-27 20:41 ` Bastien
  2022-09-29 19:53   ` tbanelwebmin
  0 siblings, 1 reply; 6+ messages in thread
From: Bastien @ 2022-09-27 20:41 UTC (permalink / raw)
  To: Christian Köstlin; +Cc: emacs-orgmode, Thierry Banel

Hi Christian,

thanks for the patch (you forgot to advertize it by adding [PATCH] in
the subject.)

Christian Köstlin <christian.koestlin@gmail.com> writes:

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

I'm CC'ing Thierry as the maintainer of ob-C.el.

The commit message should be reworked - see
https://orgmode.org/worg/org-contribute.html#commit-messages

I would recommend not using source blocks in the message.

I hope Thierry will have time to review it.

Thanks!

-- 
 Bastien


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Please add support for dlangs packagemanager to ob-C.el
  2022-09-27 20:41 ` Bastien
@ 2022-09-29 19:53   ` tbanelwebmin
  2022-10-29  6:34     ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: tbanelwebmin @ 2022-09-29 19:53 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/html, Size: 2583 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Please add support for dlangs packagemanager to ob-C.el
  2022-09-29 19:53   ` tbanelwebmin
@ 2022-10-29  6:34     ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2022-10-29  6:34 UTC (permalink / raw)
  To: tbanelwebmin; +Cc: Org Mode

tbanelwebmin <tbanelwebmin@free.fr> writes:

> Your TINYCHANGE fits into the 15 lines limit. I will review it.
>
> As Bastien said, we follow as much as we can a predefined format for commit messages:
> https://orgmode.org/worg/org-contribute.html#commit-messages
>
> You may also look at past commit messages, for instance this one:
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=0a6a56c804099e358ca558119b7aede0b2b9b90f
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/log/
>
> If you want to further contribute, maybe in another TINYCHANGE, automatic unit tests are very valuable. There
> are already examples of Dlang tests in:
> testing/examples/ob-C-test.org
> testing/lisp/test-ob-C.el

Thierry, do I understand correctly that the only objection if the commit
message format? If so, I can fix it and apply the patch. Will it be ok?

(One month has passed since your review and no response has been given.
Since the patch is useful, we may as well take care about such a small
issue as formatting)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-29  6:34 UTC | newest]

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

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