From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id +Kw1OfhnomcxhQAA62LTzQ:P1 (envelope-from ) for ; Tue, 04 Feb 2025 19:18:17 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id +Kw1OfhnomcxhQAA62LTzQ (envelope-from ) for ; Tue, 04 Feb 2025 20:18:17 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="dhbFl/GW"; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1738696696; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=r2qZ+n1YnvsRfVzJO9WIhnCeqnfrXI88ZT6ajEENN/c=; b=nvVnSYsPhg5ugeNPJjmzsIdurgjJWQsjujuJ7Nfo871qSglMN9kzJ9fqP4SwzBi+SVCcok 2sL69wxqbnJwTJCdg1IUOSStN+P/Y01pG3YesSTC7NeFp2s+Sm2KjsXnglOzCn0x8+NU+m hGcaFR4/aFu3sQQJtLn4rfgyWurVUHmUdz5K0I5R9EO7d13HnI5Pq+aYalOalFI34Df+mC 31Xg18dRFLIYWWzDgmT3cdjsFcAkUCZHCPZH0yhfTCAjhNLqh0J8D7e16eQ5mrAjcGGrDr VJNOC/OX10pu6yfLa2LbVbWi78EpwqRYfWZJNVQDQq1ODhv+Qt5ChFC+KVKu5A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="dhbFl/GW"; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1738696696; a=rsa-sha256; cv=none; b=dRnowdjKp9HUkkyz0NJ6gym856Oemd+ayc69xwPv/YzOGoo6C0WYYuvCuxDAWtK2i0kPsP REg3U+2l9g5EFz/zqlMSLMWmzdg5UNJ2IsubxgrTdnvStsvGGT1bUf+CIn3oeiMLxnNr6r oFTsHRGlGd2eqj9A+TaFD72lq7Ug3xaIaOIKmngrLz7J/z0hnvyXKsyt2rn9IY/NAH1Tgh 8q8OPk9hPhtkcvqQ1LaBIcDzfnibiuDQoIy1ylQxN9wzdh6sk9Y0+hO+13pFcxUhMxUwY+ XxYW9aVzclx5m/X+GFPYjafj5jiFQOXQTp0I9LpMCR5mW2E9piWLWH2OU4RHUQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B7EF06A69 for ; Tue, 04 Feb 2025 20:18:16 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tfOQC-0004l8-Lr; Tue, 04 Feb 2025 14:17:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tfOQA-0004kj-SL for emacs-orgmode@gnu.org; Tue, 04 Feb 2025 14:17:19 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tfOQ8-0001IK-C2 for emacs-orgmode@gnu.org; Tue, 04 Feb 2025 14:17:18 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 3DA45240101 for ; Tue, 4 Feb 2025 20:17:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1738696632; bh=pKfIjlDXjlvMwCs22BGiHUFEWiqCJvWuyyhsDeJ0B2A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=dhbFl/GW2V0YByn64KCIPV6QTgR259R9YOxJuQ0RusYTIb9mvv3z0Dp4Qfpb19qY5 Tledr9tQYh8r9U7LRhyjsQXBlZo3JTS1N3ZGI5qmeNqZ+OsipuDw2yDEwoXm9LYRA2 4zm828P+xCGaiDOotEf7X8er+aMC0IPK39PDDuxk7elnwGroheTZ/GLyph0zidONyc zu3nDZX2ApuBPRu53n4cOxwtUn8aL9PQUdnuPz7DKGAI0TM3BGKxDfN2IUB7tywPFC gzC9iosP2MrFXfrH72ImyLB5v1VAigSao9Y0/026BoOEVf4mOJDmMIYlyKLeogcu/O y41iGwCkx9GPQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4YnY5g4hYcz9rxS; Tue, 4 Feb 2025 20:17:11 +0100 (CET) From: Ihor Radchenko To: poverobuosodonati Cc: Leo Butler , emacs-orgmode Subject: Re: Language support for C# in org-babel In-Reply-To: <9afcec0f-b392-4d22-8249-ffbd143db76d@gmail.com> References: <87y0zn24bk.fsf@t14.reltub.ca> <7d0db99b-f926-42b1-a867-2b05e0224323@gmail.com> <878qrm33hi.fsf@localhost> <9afcec0f-b392-4d22-8249-ffbd143db76d@gmail.com> Date: Tue, 04 Feb 2025 19:19:26 +0000 Message-ID: <87wme5cybl.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -8.71 X-Spam-Score: -8.71 X-Migadu-Queue-Id: B7EF06A69 X-TUID: L4qfrPdEMVzI poverobuosodonati 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 . Support Org development at , or support my work at