From: Ihor Radchenko <yantar92@posteo.net>
To: poverobuosodonati <poverobuosodonati@gmail.com>
Cc: Leo Butler <Leo.Butler@umanitoba.ca>,
emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Language support for C# in org-babel
Date: Tue, 04 Feb 2025 19:19:26 +0000 [thread overview]
Message-ID: <87wme5cybl.fsf@localhost> (raw)
In-Reply-To: <9afcec0f-b392-4d22-8249-ffbd143db76d@gmail.com>
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>
prev parent reply other threads:[~2025-02-04 19:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=87wme5cybl.fsf@localhost \
--to=yantar92@posteo.net \
--cc=Leo.Butler@umanitoba.ca \
--cc=emacs-orgmode@gnu.org \
--cc=poverobuosodonati@gmail.com \
/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).