From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gGhiLXyI+F9mWwAA0tVLHw (envelope-from ) for ; Fri, 08 Jan 2021 16:29:48 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id ONEsKXyI+F+DfQAA1q6Kng (envelope-from ) for ; Fri, 08 Jan 2021 16:29:48 +0000 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 3CDAB940276 for ; Fri, 8 Jan 2021 16:29:48 +0000 (UTC) Received: from localhost ([::1]:60560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxue2-0005ZI-Ml for larch@yhetil.org; Fri, 08 Jan 2021 11:29:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxucz-0005Xk-19 for emacs-orgmode@gnu.org; Fri, 08 Jan 2021 11:28:41 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:33367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kxucw-0005b0-K9 for emacs-orgmode@gnu.org; Fri, 08 Jan 2021 11:28:40 -0500 Received: by mail-wr1-x42a.google.com with SMTP id t30so9610335wrb.0 for ; Fri, 08 Jan 2021 08:28:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:cc:subject:message-id:date:mime-version; bh=tUIkuSbMfRQE17CzNBXk9KMBoX5h3UNEn4xdE5kaKHg=; b=X8eyzXtjV3R2y3xMEWdlQxYS07kqHCB0PPNQihxoZFWM54ZUpwp2JIiQT3pvVCtYTS OSs8SKLQVE+Wu/HJ8dYnpGxGVKgeMIdh427UW6tp1btGv36mF6pd/Jdi+QSmAy9QQWgI D1lNYQb2lVB1Hr9Osty0xoMeUTOyi9nQlEUoQTF+/umc7vELfHVtpiRJh26QSAQZhLCZ bHFo1S5BY95LxRlgTDWr/uIMSex1e/NHd+Zkqlt6oNaJHlJH16Lqbh98zgYMNq0EuQAi k2qLvCA7KDEcNH/Bp9qKTrrnIyn+pRkfe/3sksKRxSVqxYMmQ1mCdTvbd7B8Qgx0SDpQ zqrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:cc:subject:message-id:date :mime-version; bh=tUIkuSbMfRQE17CzNBXk9KMBoX5h3UNEn4xdE5kaKHg=; b=OXivGJg1Tcqxp6kznqtUj9TQVowdRZH1hzeX+ET+JdH8P2j/00mqGVlNrrkstvWCJm iFgjxE+R8fl9iKVu2snglsj/JTx/r43yhjX+linptHJcTNMhi3YvDxGFDF1O/z9fl61V T9HEOg5MpuECQ9bGGdBC8feM8jTT2UD8AusVYU6zuC89GbeA5iu3RFlTCGwB3YNLz2de UxnkoXXkwid+OabJ2oHtL/60buTiL+tRAMfLh0pmnRMe2yD/4fRKp3rn4Nm6F/3cEKmr UVf3UHgz4k+mqravy4lUBf38nKLNu2UV37c+oULZahMQoDvT6JrhxJQtusjEZLhPeUg/ 6ovg== X-Gm-Message-State: AOAM532LthR8MM6Rv7gNSIl6ET5ffDmASH4CH1Y0NCrX1Njm63qZ9HMj 4l1Tsf1uin7QVawA2kgKUJJ/OPs+30w= X-Google-Smtp-Source: ABdhPJyiH3lnM7rW848WSbHimzQF8aWU4Nic3qdn0zJAyrXW+BG5XF0NqmdGJbH66VE0mtGjSb2tmg== X-Received: by 2002:a5d:40d2:: with SMTP id b18mr4299615wrq.369.1610123315952; Fri, 08 Jan 2021 08:28:35 -0800 (PST) Received: from fnox ([194.132.212.123]) by smtp.gmail.com with ESMTPSA id v20sm12387783wml.34.2021.01.08.08.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:28:34 -0800 (PST) User-agent: mu4e 1.4.13; emacs 27.1 From: John Herrlin To: ian martins Subject: [PATCH] ob-java, a proposal on import improvement Message-ID: <87o8hzv1e8.fsf@gmail.com> Date: Fri, 08 Jan 2021 17:28:33 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=jherrlin@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: org-mode-email Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -3.05 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=X8eyzXtj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 3CDAB940276 X-Spam-Score: -3.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: ZClU/nt+817f --=-=-= Content-Type: text/plain Hey, Happy new year and a good continuation! I would like to combine imports from header-args with imports from a source block. Here is an example: * RxJava :PROPERTIES: :header-args: :dir src :results output code :header-args:java: :cmdline -classpath ./rxjava-1.3.8.jar:src:. :cmpflag -classpath ./rxjava-1.3.8.jar:src:. :imports rx.Observable rx.Subscriber :END: #+BEGIN_SRC java import static rx.Observable.empty; import static rx.Observable.just; import static rx.Observable.range; Observable .range(5, 5) .flatMap(x -> just(x * 2)) .flatMap(x -> (x != 10) ? just(x) : empty()) .subscribe(System.out::println); #+END_SRC I didnt get the to work so I made a patch. What do you think about it? Stay safe! Best regards John --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ob-java.el-imports-in-source-block-improvement.patch >From a602a86e42c2da5cb531ada6c13184d3c307a0db Mon Sep 17 00:00:00 2001 From: John Herrlin Date: Fri, 8 Jan 2021 17:11:56 +0100 Subject: [PATCH] lisp/ob-java.el: imports in source block improvement * lisp/ob-java.el (re-seq): Improve imports when expanding --- lisp/ob-java.el | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lisp/ob-java.el b/lisp/ob-java.el index f70a50192..a5b6649ca 100644 --- a/lisp/ob-java.el +++ b/lisp/ob-java.el @@ -86,7 +86,7 @@ like javac -verbose." (1+ space) (group (1+ (in alnum ?_ ?.))) ; capture the package name (0+ space) ?\; line-end) "Regexp for the package statement.") -(defconst org-babel-java--imports-re (rx line-start (0+ space) "import" +(defconst org-babel-java--imports-re (rx line-start (0+ space) "import" (opt space "static") (1+ space) (group (1+ (in alnum ?_ ?.))) ; capture the fully qualified class name (0+ space) ?\; line-end) "Regexp for import statements.") @@ -308,6 +308,15 @@ RESULT-FILE is the temp file to write the result." (org-babel-java--move-past org-babel-java--package-re) (insert (concat "import " package "." class ";\n"))))) +(defun re-seq (regexp string) + "Get a list of all regexp matches in a string" + (save-match-data + (let ((pos 0) matches) + (while (string-match regexp string pos) + (push (match-string 0 string) matches) + (setq pos (match-end 0))) + matches))) + (defun org-babel-expand-body:java (body params) "Expand BODY with PARAMS. BODY could be a few statements, or could include a full class @@ -323,7 +332,9 @@ is simplest to expand the code block from the inside out." (imports-val (assq :imports params)) (imports (if imports-val (split-string (org-babel-read (cdr imports-val) nil) " ") - nil))) + nil)) + (imports-in-body (re-seq org-babel-java--imports-re body)) + (body (string-trim (replace-regexp-in-string org-babel-java--imports-re "" body)))) (with-temp-buffer (insert body) @@ -364,6 +375,12 @@ is simplest to expand the code block from the inside out." (org-babel-java--move-past org-babel-java--package-re) ; if package is defined, move past it (insert (mapconcat (lambda (package) (concat "import " package ";")) imports "\n") "\n")) + ;; add imports from source block + (when imports-in-body + (goto-char (point-min)) + (org-babel-java--move-past org-babel-java--package-re) ; if package is defined, move past it + (insert (mapconcat (lambda (import) import) imports-in-body "\n") "\n")) + ;; add package at the top (goto-char (point-min)) (when (and packagename (not (re-search-forward org-babel-java--package-re nil t))) -- 2.30.0 --=-=-=--