* Language support for C# in org-babel
@ 2025-01-06 17:44 poverobuosodonati
2025-01-06 18:19 ` Leo Butler
0 siblings, 1 reply; 6+ messages in thread
From: poverobuosodonati @ 2025-01-06 17:44 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 947 bytes --]
Hi guys,
I am a newbie in that I've never contributed so far. Thus, I would like to start this journey with pinging the mailing list first as it is indicated in the contributing documentation.
As far as I know, there is currently no language support for C# withi org-babel.
As this (evaluating C# code-blocks) is occasionally helpful for my workflow, I went ahead and wrote an integration following the excellent documentation found here (https://orgmode.org/worg/org-contrib/babel/languages/index.html).
Are there any objections against me trying to upstream this addition? I would go ahead and try to open a pull request following the guidelines from this documentation (https://orgmode.org/worg/org-contribute.html) if there are none. Or is there a better way/no need for it in the first place?
I am happy about any feedback on the matter :)
Thank you very much in advance,
Best regards,
Max
[-- Attachment #2: Type: text/html, Size: 2044 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Language support for C# in org-babel
2025-01-06 17:44 Language support for C# in org-babel poverobuosodonati
@ 2025-01-06 18:19 ` Leo Butler
2025-01-06 21:09 ` Buoso Donati
0 siblings, 1 reply; 6+ messages in thread
From: Leo Butler @ 2025-01-06 18:19 UTC (permalink / raw)
To: poverobuosodonati; +Cc: emacs-orgmode
On Mon, Jan 06 2025, poverobuosodonati <poverobuosodonati@gmail.com> wrote:
>
>
>
>
> Hi guys,
>
>
>
> I am a newbie in that I've never contributed so far. Thus, I would like to start this journey with pinging the mailing list first as it is indicated in the contributing documentation.
>
Welcome.
>
>
> As far as I know, there is currently no language support for C# withi org-babel.
>
> As this (evaluating C# code-blocks) is occasionally helpful for my
> workflow, I went ahead and wrote an integration following the
> excellent documentation found here
> (https://orgmode.org/worg/org-contrib/babel/languages/index.html).
Have you looked at ob-C.el or ob-java.el? I am not sure how similar C#
is to either C/C++/D or Java, but it may make sense to try to extend one
of those.
>
> Are there any objections against me trying to upstream this addition?
> I would go ahead and try to open a pull request following the
> guidelines from this documentation
> (https://orgmode.org/worg/org-contribute.html) if there are none. Or
> is there a better way/no need for it in the first place?
See the instructions at
https://orgmode.org/worg/org-contribute.html#first-patch
Best regards,
Leo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Language support for C# in org-babel
2025-01-06 18:19 ` Leo Butler
@ 2025-01-06 21:09 ` Buoso Donati
2025-01-07 18:04 ` Ihor Radchenko
0 siblings, 1 reply; 6+ messages in thread
From: Buoso Donati @ 2025-01-06 21:09 UTC (permalink / raw)
To: Leo Butler; +Cc: emacs-orgmode
Thanks a lot for your input!
> Have you looked at ob-C.el or ob-java.el? I am not sure how similar C#
> is to either C/C++/D or Java, but it may make sense to try to extend one
> of those.
In fact, I was most inspired by the existing ob-C.el and ob-java.el!
From what I understand C# (in conjunction with csproj-files) is
"different enough" from C/C++ and Java (I don't feel particularly
comfortable judging the D language) that it somewhat makes sense to
create an individual file integrating it (as opposed to increase the
complexity with existing integrations).
I will however consider this and re-evaluate my initial concept with
your feedback.
> See the instructions at
>
> https://orgmode.org/worg/org-contribute.html#first-patch
I would go ahead and follow these instructions trying to contribute the
draft. This also makes it easier for me to show what I mean and
elaborate on the concept (and the differences to existing integrations)
potentially.
Best regards,
Max
On 06.01.25 19:19, Leo Butler wrote:
> On Mon, Jan 06 2025, poverobuosodonati <poverobuosodonati@gmail.com> wrote:
>
>>
>>
>>
>>
>> Hi guys,
>>
>>
>>
>> I am a newbie in that I've never contributed so far. Thus, I would like to start this journey with pinging the mailing list first as it is indicated in the contributing documentation.
>>
> Welcome.
>
>>
>> As far as I know, there is currently no language support for C# withi org-babel.
>>
>> As this (evaluating C# code-blocks) is occasionally helpful for my
>> workflow, I went ahead and wrote an integration following the
>> excellent documentation found here
>> (https://orgmode.org/worg/org-contrib/babel/languages/index.html).
> Have you looked at ob-C.el or ob-java.el? I am not sure how similar C#
> is to either C/C++/D or Java, but it may make sense to try to extend one
> of those.
>
>>
>> Are there any objections against me trying to upstream this addition?
>> I would go ahead and try to open a pull request following the
>> guidelines from this documentation
>> (https://orgmode.org/worg/org-contribute.html) if there are none. Or
>> is there a better way/no need for it in the first place?
> See the instructions at
>
> https://orgmode.org/worg/org-contribute.html#first-patch
>
> Best regards,
> Leo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Language support for C# in org-babel
2025-01-06 21:09 ` Buoso Donati
@ 2025-01-07 18:04 ` Ihor Radchenko
2025-01-26 19:05 ` poverobuosodonati
0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2025-01-07 18:04 UTC (permalink / raw)
To: Buoso Donati; +Cc: Leo Butler, emacs-orgmode
Buoso Donati <poverobuosodonati@gmail.com> writes:
> Are there any objections against me trying to upstream this addition?
C# is a popular language. I have no objections to adding it to the core.
> ... I would go ahead and try to open a pull request following the
> guidelines from this documentation
> (https://orgmode.org/worg/org-contribute.html) if there are none. Or
> is there a better way/no need for it in the first place?
If you can, please do follow what is written in our contribution guide.
But feel free to ask us anything if you encounter difficulties.
You do not have to go through all the requirements alone.
> In fact, I was most inspired by the existing ob-C.el and ob-java.el!
> From what I understand C# (in conjunction with csproj-files) is
> "different enough" from C/C++ and Java (I don't feel particularly
> comfortable judging the D language) that it somewhat makes sense to
> create an individual file integrating it (as opposed to increase the
> complexity with existing integrations).
> I will however consider this and re-evaluate my initial concept with
> your feedback.
Generally, it only makes sense to extend an existing library if there is
very significant code sharing. Otherwise, no need to complicate things.
Also, before you proceed, note that there is ob-csharp in org-contrib
repository:
https://git.sr.ht/~bzg/org-contrib/tree/master/item/lisp/ob-csharp.el
It is very simplistic though. Just letting you know so that you are
aware.
You do not need to reuse that file or anything like that - we *cannot*
use that file because its author did not sign copyright papers. (BTW,
you do need to do it - let me know if you need any assistance)
After your future patch is accepted, we will likely remove ob-csharp
from org-contrib. Which means that you should name the new library
ob-csharp as well - it will serve as the replacement.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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
* Re: Language support for C# in org-babel
2025-01-07 18:04 ` Ihor Radchenko
@ 2025-01-26 19:05 ` poverobuosodonati
2025-02-04 19:19 ` Ihor Radchenko
0 siblings, 1 reply; 6+ messages in thread
From: poverobuosodonati @ 2025-01-26 19:05 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Leo Butler, emacs-orgmode
Thank you so much for your input and guidance.
I have put my "patch request" in a public repository. Please find it here
https://codeberg.org/buoso/csharp-babel
I've tried to document the incentive as well as the usage quite extensive.
I would like to propose to merge this as a maintainer as I'd like to
take care of this library in future. That is, of course, if you think it
is a useful addition and legitimate proposal.
I am very much looking forward to feedback on the code, the process in
general, or anything beyond that.
Thanks again and
Best regards,
Max
On 07.01.25 19:04, Ihor Radchenko wrote:
> Buoso Donati <poverobuosodonati@gmail.com> writes:
>
>> Are there any objections against me trying to upstream this addition?
> C# is a popular language. I have no objections to adding it to the core.
>
>> ... I would go ahead and try to open a pull request following the
>> guidelines from this documentation
>> (https://orgmode.org/worg/org-contribute.html) if there are none. Or
>> is there a better way/no need for it in the first place?
> If you can, please do follow what is written in our contribution guide.
> But feel free to ask us anything if you encounter difficulties.
> You do not have to go through all the requirements alone.
>
>> In fact, I was most inspired by the existing ob-C.el and ob-java.el!
>> From what I understand C# (in conjunction with csproj-files) is
>> "different enough" from C/C++ and Java (I don't feel particularly
>> comfortable judging the D language) that it somewhat makes sense to
>> create an individual file integrating it (as opposed to increase the
>> complexity with existing integrations).
>> I will however consider this and re-evaluate my initial concept with
>> your feedback.
> Generally, it only makes sense to extend an existing library if there is
> very significant code sharing. Otherwise, no need to complicate things.
>
> Also, before you proceed, note that there is ob-csharp in org-contrib
> repository:
> https://git.sr.ht/~bzg/org-contrib/tree/master/item/lisp/ob-csharp.el
> It is very simplistic though. Just letting you know so that you are
> aware.
>
> You do not need to reuse that file or anything like that - we *cannot*
> use that file because its author did not sign copyright papers. (BTW,
> you do need to do it - let me know if you need any assistance)
>
> After your future patch is accepted, we will likely remove ob-csharp
> from org-contrib. Which means that you should name the new library
> ob-csharp as well - it will serve as the replacement.
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Language support for C# in org-babel
2025-01-26 19:05 ` poverobuosodonati
@ 2025-02-04 19:19 ` Ihor Radchenko
0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2025-02-04 19:19 UTC (permalink / raw)
To: poverobuosodonati; +Cc: Leo Butler, emacs-orgmode
poverobuosodonati <poverobuosodonati@gmail.com> writes:
> I have put my "patch request" in a public repository. Please find it here
> https://codeberg.org/buoso/csharp-babel
Thanks!
See my initial comments on the code below:
> ;; default header arguments for C#
> (defvar org-babel-default-header-args:csharp
> '((main . :any)
> (namespace . :any)
> (project . :any)
> (class :any)
> (references :any)
> (usings :any))
> "Csharp specific header arguments.")
Looks like some of the new header arguments can only be "yes"/"no". If
so, you should reflect this fact in this variable.
> (defcustom org-babel-csharp-compiler "dotnet"
> "The program to call for compiling a csharp project.")
ob-csharp from org-contrib uses mcs here. I am wondering why you use
something different. Is there any syntax difference? Something else? (I
have no knowledge of C#)
> (defcustom org-babel-csharp-target-framework "net7.0"
> "The desired target framework to use.")
Do I understand correctly that this more or less a syntax version?
If yes, we may want to customize it per-src block as a header argument
rather than globally.
> (defvar org-babel-csharp-nuget-config nil
> "Pass a valid nuget config as documented here
> https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file.
> This is taken as-is. It should be a string in XML-format.")
Same here. Why not header argument?
> (defvar org-babel-csharp-additinal-projcect-flags nil
> "Will be passed in the 'PropertyGroup' defining the project.
> This is taken as-is. It should be a string in XML-format.")
... and here. (Also, typos in the variable name)
> (defun org-babel--csharp-preprocess-params (params)
> "Make sure PARAMS contains a cons-cell for both `:project' and `:namespace'."
> (unless (assoc :project params)
> (push `(:project . ,(symbol-name (gensym))) params))
> (unless (assoc :namespace params)
> (push `(:namespace . ,(symbol-name (gensym))) params))
> params)
I suggest doing
(project-name (or (alist-get :project params) (gensym)))
(namespace (or (alist-get :namespace params) (gensym)))
inside execute function.
It will be much simpler.
> (defun org-babel--csharp-parse-usings (usings)
> (let ((usinglist))
> (setf usinglist (mapconcat #'(lambda (u) (format "using %s;" u)) usings "\n"))
> usinglist))
I would call this "format" rather than "parse". Parsing is usually
string->data, not data->stirng.
> (defun org-babel-expand-body:csharp (body params ;; processed-params
> )
> (let* ((main-p (not (string= (cdr (assq :main params)) "no")))
> (class-tmp (alist-get :class params))
> (class (pcase class-tmp
Can simply do (pcase (alist-get ...) ...)
> (defun org-babel-execute:csharp (body params)
> "Execute a block of Csharp code with org-babel.
> This function is called by `org-babel-execute-src-block'"
> (message "executing Csharp source code block")
> (org-babel--csharp-preprocess-params params)
> (let* ((processed-params (org-babel-process-params params))
Calling `org-babel-process-params' should not be necessary. It is called
by Org itself, before running org-babel-execute:... functions.
> (dir-param (alist-get :dir params))
> (base-dir (file-name-concat (if dir-param
> (ensure-directories-exist)
What is the purpose of `ensure-directories-exist' here?
To create directory specified in :dir? If yes, you do not need to bother
- it is controlled by standard :mkdirp header argument.
> (file-truename "."))
> project-name))
Why do you create project inside working directory? These files will
remain there for every single src block you run, possibly littering that
directory.
Most of the babel backends that need to create transient files do it in
temp dir via `org-babel-temp-*' functions.
> (compile-cmd (concat
> org-babel-csharp-compiler
> " " "build"
> " " "--output"
> " " (format "%S" bin-dir)
> " " (format "%S"(file-truename base-dir))))
Is it expected that every possible csharp compiler take these exact arguments?
> (unless (file-exists-p base-dir)
> (make-directory base-dir))
Again, babel should take care about this according to :mkdirp. It is not
backend's job to create working directory.
> ;; nuget restore
> (message (format "dotnet restore %S" project-file))
> (org-babel-eval (format "dotnet restore %S" project-file) "")
Why hard-coding "dotnet" command here if it is customizeable?
> (org-babel-eval compile-cmd "")
> (let ((results (unless (eq project-type 'class)
> (org-babel-eval run-cmd ""))))
So, project-type that is not 'class will not produce any results. May
you please explain why it is useful?
> (defun org-babel-csharp-var-to-csharp (var)
> "Convert an elisp var into a string of csharp source code
> specifying a var of the same value."
> (format "var %s = %S;" (car var) (cdr var)))
Please rename this into org-babel-variable-assignments:csharp and let it
accept params argument.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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:[~2025-02-04 19:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-06 17:44 Language support for C# in org-babel poverobuosodonati
2025-01-06 18:19 ` Leo Butler
2025-01-06 21:09 ` Buoso Donati
2025-01-07 18:04 ` Ihor Radchenko
2025-01-26 19:05 ` poverobuosodonati
2025-02-04 19:19 ` 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).