Re: [PATCH] ob-java, a proposal on import improvement

2021-01-08 Thread Dr. Arne Babenhauserheide

John Herrlin  writes:
> 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

> What do you think about it?

I can’t give an informed opinion about the patch, but the example looks
great! I did not know that Java support in org-babel is that good.

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken


signature.asc
Description: PGP signature


Bug: Images not displaying over tramp [9.3.7 (9.3.7-14-gb2b587-elpaplus @ /home/gallo/.emacs.d/elpa/org-plus-contrib-20200720/)]

2021-01-08 Thread Alejandro Gallo


Your bug report will be posted to the Org mailing list.


When I'm checking out an org mode file over tramp, images are not
displayed, even though tramp seems to fetch the file correctly.
The image that get's shown is the white square that gets shown
whenever an image is not found.

I posted the question also on stackoverflow here:

  
https://stackoverflow.com/questions/65620272/image-preview-does-not-work-in-tramp-for-org-mode


Emacs  : GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.21)
Package: Org mode version 9.3.7 (9.3.7-14-gb2b587-elpaplus @ 
/home/gallo/.emacs.d/elpa/org-plus-contrib-20200720/)

-- 
Alejandro Gallo




[PATCH] ob-java, a proposal on import improvement

2021-01-08 Thread John Herrlin

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

>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



Re: Microsoft Excel spreadsheet editing directly from within emacs.

2021-01-08 Thread H. Dieter Wilhelm
Hongyi Zhao  writes:

> On Tue, Dec 29, 2020 at 5:40 PM Jean Louis  wrote:
>>
>> * Hongyi Zhao  [2020-12-29 07:55]:
>> > From this point of view, if we want to have both full-features and
>> > powerful capabilities in manipulating spreadsheet, it seems that only
>> > the python based programmatic tools/packages, say, openpyxl
>> > , can meet the requirements
>> > currently.
>>
>> What are you requirements?
>
> I use Linux as my working environment exclusively. So, I can't access
> the native MS Office supplied for macOS/Windows. But I sometimes
> really need to manipulate and process MS Office documents, especially
> DOCX and XLSX files. Though there are some free and open source office
> suites, e.g. LibreOffice, but none of them can completely compatible
> with the MS Office.
>
> So, I want to find a way that can be used to programmatically complete
> any possible work done by MS Office word/excel.

For directly reading Excel sheets I highly recommend "readxl" from the
R package bundle "tidyverse".  

  https://r4ds.had.co.nz/

It's an investment though but it pays in the long run for serious data
science.  After processing you should be able to write data in an excel
file with the "writexl" package.  (Did not test it, never had the need
to export into Excel. :-))

By the way, I'm mostly doing data processing in org-mode R source
blocks.  And I'm also converting data into org-mode tables but mostly
small ones for latex table exports. And you can also do spreadsheet
calculations with them

  https://orgmode.org/manual/The-Spreadsheet.html

Here's a small example

   #+LATEX: \definecolor{VitescoYellow}{RGB}{242,229,0}
   #+LATEX: \rowcolors[]{1}{VitescoYellow!100}{VitescoYellow!5}
   #+caption: Required motor torque to reach src_R{N} rpm in src_R{T} s
   | *Cases*| *Torque* in  Nmm |
   |+--|
   | Best case  |  9.5 |
   | Worst case | 11.6 |
   #+TBLFM: @2$2='(org-sbe mintorque):: @3$2='(org-sbe maxtorque)

(Above org table is reading results from named org source blocks.)

If you really, really need to return data in MS formats you might have
to run a virtual machine with Windows, not that I recommend that but
live is ...

Hope that is interesting

 Dieter


-- 
Best wishes
H. Dieter Wilhelm
Zwingenberg, Germany



Re: Org-capture template no longer recognised...

2021-01-08 Thread Ihor Radchenko
Neil Shephard  writes:

> Beyond downgrading each of the packages I listed if anyone has suggestions
> on how to debug this further please let me know, more than happy to work
> through this and post back to the list.

You can try bug-hunter package [1] to narrow down the cause. One example
of using the package: https://github.com/yantar92/org/issues/11

[1] https://github.com/Malabarba/elisp-bug-hunter

Hope it helps.

P.S. Would it make sense to have some write-up about debugging user
configuration in org wiki?

Best,
Ihor



Make org-mode multi line shell session work sensibly

2021-01-08 Thread Samuel Loury
Hi,

I've been trying to work more and more with org-babel recently, and
found out that the session in the shell block does not appear to work
well.

The symptom is the following: When I try to run a code block with noop
lines, like comment, the output gets broken

--8<---cut here---start->8---
#+BEGIN_SRC sh :results output :exports both :session 
c66d4791-003d-42af-a4e0-366f5542c604
  echo a
  # noop
  echo b
#+END_SRC

#+RESULTS:
:
: a
: $ b
--8<---cut here---end--->8---

Of course, I would expect
--8<---cut here---start->8---
#+RESULTS:
: a
: b
--8<---cut here---end--->8---

Actually, I went through the code and I think I understand why it has
this behavior, see here for my analysis ->
https://konubinix.eu/braindump/posts/c66d4791-003d-42af-a4e0-366f5542c604/

I tried to patch the code of org-babel-comint-with-output to make it
work correctly, see here ->
https://konubinix.eu/braindump/posts/25b52cc8-71f8-420f-9161-5c60030cede9/

But it feels like it is more of a work around than an elegant solution
to the issue. I am already facing some corner cases and it does not
handle yet the continuation lines, starting with ">".

I was thinking that maybe, in org-babel-sh-evaluate, instead of sending
the lines one by one and interpreting the result, the code could write a
temporary file with the body and source it. Basically all the evaluation
would be

--8<---cut here---start->8---
$ source tmp-file-
$ echo org-babel-sh-eoe
--8<---cut here---end--->8---

It still would suffer from the no newline behavior I am describing here
-> https://konubinix.eu/braindump/posts/f6206181-09d2-4449-b437-960be2b5dfd2/
But, one step at a time, right?

Then I took though about it. I cannot believe I am the only person
trying to run multi line shell programs with comment in session, am I?

So here are a few questions: Is there anyone with the same use case as I
have? If so, how do you cope with the problem I am facing? If I want to
fix it, what do you think would be the more elegant solution: fixing the
line by line parsing like I was trying to do or sourcing the code to
avoid using line by line parsing?

org-mode is really great, org-babel is awesome and I use it more and
more in my daily life, I hope we will be able to fix this annoying
behavior together.

Thank you for your time,
My best,

PS: the real life use case I am using is the following one: I want to
have a few org-babel snippets to ease my code reviews, as presented in here:
https://konubinix.eu/braindump/posts/564621c3-4a9a-4574-abf8-bd9831b29aa4/

the first snippet has the following output

--8<---cut here---start->8---
: 
: $ $ $ $ $ Ready to make the review of XXX on top of YYY
--8<---cut here---end--->8---

instead of the expected

--8<---cut here---start->8---
: Ready to make the review of XXX on top of YYY
--8<---cut here---end--->8---

And the second one with the header ":results output file", have the
following result

--8<---cut here---start->8---
[[file:
the-directory/diff.diff]]
--8<---cut here---end--->8---

instead of the expected

--8<---cut here---start->8---
[[file:the-directory/diff.diff]]
--8<---cut here---end--->8---

With my workaround, the output is ok.
-- 
Konubinix
GPG Key: 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A


signature.asc
Description: PGP signature


columnview, match and status include all open status

2021-01-08 Thread Uwe Brauer


Hi 

I have the following problem:

#+begin_src 
,* Sheet1 
  :PROPERTIES:
  :COLUMNS:  %10Sheet(Sheet Nr) %10Ej(Exercise Nr)  %17Date(Date) 
%7STATUS(Status){X/}
  :END:

,** Group1 :in:G1:
   :PROPERTIES:
   :ID:   G1
   :Grp1: 1
   :Gr:   Group-1
   :STATUS:   [X]
   :Sheet:H1
   :Ej:   E1
   :END:

,** Group1 :in:G1:
   :PROPERTIES:
   :ID:   G1
   :Grp1: 1
   :Gr:   Group-1
   :STATUS:   [X]
   :Sheet:H1
   :Ej:   E4
   :END:


,** Group2   :out:
   :PROPERTIES:
   :ID:   G2
   :Grp1: 2
   :Gr:   Group-2
   :STATUS:   [X]
   :Sheet: H1
   :Ej:   E2
   :END:

,** Group3   :out:
   :PROPERTIES:
   :ID:   G3
   :Grp1: 3
   :Gr:   Group-3
   :STATUS:   [X]
   :Sheet: H1
   :Ej:   E3
   :END:


,** List of all group members


,#+TBLNAME: Sheet1
,#+BEGIN: columnview   :hlines 2 :skip-empty-rows t :indent nil  :format 
"%5Sheet(Sheet) %5Grp1(Group)  %5Ej(Exercise) %7STATUS(Status){X/}"
| Sheet | Group | Exercise | Status |
|---+---+--+|
|   |   |  | [4/4]  |
|---+---+--+|
| H1| 1 | E1   | [X]|
|---+---+--+|
| H1| 1 | E4   | [X]|
|---+---+--+|
| H1| 2 | E2   | [X]|
|---+---+--+|
| H1| 3 | E3   | [X]|
,#+END

Now I only want a table with the tag G1

,#+TBLNAME: Group1
,#+BEGIN: columnview   :hlines 2 :skip-empty-rows t :indent nil  :match "G1" 
:format "%5Sheet(Sheet) %5Grp1(Group)  %5Ej(Exercise) %7STATUS(Status){X/}"
| Sheet | Group | Exercise | Status |
|---+---+--+|
| H1| 1 | E1   | [X]|
|---+---+--+|
| H1| 1 | E4   | [X]|
,#+END


But I would like to have 

,#+TBLNAME: Sheet1
,#+BEGIN: columnview   :hlines 2 :skip-empty-rows t :indent nil  :format 
"%5Sheet(Sheet) %5Grp1(Group)  %5Ej(Exercise) %7STATUS(Status){X/}"
| Sheet | Group | Exercise | Status |
|---+---+--+|
|   |   |  | [2/2]  |
|---+---+--+|
| H1| 1 | E1   | [X]|
|---+---+--+|
| H1| 1 | E4   | [X]|
,#+END


That seems impossible?

regards

Uwe Brauer 
#+end_src