Re: Combining ob-sql, docker-tramp, and tramp ssh?

2020-10-21 Thread Tim Cross


I have done something very similar, but with a few differences which
might help.

In my case, I didn't use tramp, but instead used ssh tunnels that I
defined in my ssh config file e.g.

Host wdb-dev
  HostName dev-example.com
  User fred
  LocalForward localhost:3330 localhost:5432
Host wdb-prod
  HostName prod-example.com
  User fred
  LocalForward localhost:3331 localhost:5432

This allows me to run psql using the -p switch to set the port e.g. 3330
or 3331 with same user name and database name. 

I then used sql's connection alist to define connection names for the
different databases. You could probably use a .dir-locals.el file to do
the same thing on a per directory/project basis.

I would then open a terminal for each connection I needed and do ssh
wdb-dev or ssh wdb-prod to setup the tunneling.

The downside of this setup is that if you lose the ssh connection, you
lose connection to the host and will need to restart it for things to
work (where with the tramp setup it will make the connection when
needed). The advantage is that I could use other tools, like psql or
dbbeaver/pgadmin/whatever at the same time.

If you want things to work in such a way that your org sql blocks all
use the same database name, you can just adjust the ssh config to use
the same port number, but then you can only have one connection active
at a time. However, this means you can setup things to connect to your
dev system, refine and test all your sql blocks and once confident they
are working, just change the ssh connection to point to the prod system
and re-run. 
Jay Zawrotny  writes:

> I've been using ob-sql to document & prune our dev db and it's been
> amazing.
>
> https://media.discordapp.net/attachments/428916969861808130/768589313964507166/image0.gif
>
> The only rough edge has been that I have to expose the SQL ports to my
> host, forward it over ssh (I'm using a remote machine to offload docker
> resources), then install a version of psql required to connect. Lastly I
> then need to symlink psql to point to the targeted version of psql I need.
>
> This means I can only match one setup at a time. A preferred route would be
> to use the :dir property to eval over tramp like:
>
> #+begin_src sql :dir "/sshx:user@devbox|docker:user@vm:/src"
> SELECT count(id) from accounts;
> #+end_src
>
> If I use Python it works, but something specific about this combo is not
> working. Any suggestions to fix this, personal config, docs, or debugging
> steps one could point me to?


-- 
Tim Cross



Combining ob-sql, docker-tramp, and tramp ssh?

2020-10-21 Thread Jay Zawrotny
I've been using ob-sql to document & prune our dev db and it's been
amazing.

https://media.discordapp.net/attachments/428916969861808130/768589313964507166/image0.gif

The only rough edge has been that I have to expose the SQL ports to my
host, forward it over ssh (I'm using a remote machine to offload docker
resources), then install a version of psql required to connect. Lastly I
then need to symlink psql to point to the targeted version of psql I need.

This means I can only match one setup at a time. A preferred route would be
to use the :dir property to eval over tramp like:

#+begin_src sql :dir "/sshx:user@devbox|docker:user@vm:/src"
SELECT count(id) from accounts;
#+end_src

If I use Python it works, but something specific about this combo is not
working. Any suggestions to fix this, personal config, docs, or debugging
steps one could point me to?


Re: Bug: Can’t assign to hline relative reference

2020-10-21 Thread Dante Catalfamo
In the case where I'm using this formula, there are many more rows
between @I..@II. I only used two in the example to keep the email small.
I would also be adding more rows regularly, making it slightly
impractical to be adjusting the beginning and end points of the formula
every time I add or remove a row. I appreciate your suggestion, though I
was hoping for a more convenient solution. If nothing else works, that's
what I'll do.

I'd like to get to the bottom of why hlines aren't permitted in table
formulas, it seems like something that should be allowed.

Thanks,
Dante

‐‐‐ Original Message ‐‐‐
On Wednesday, October 21, 2020 8:43 AM, Daniel Herzig 
 wrote:

> This seems to be related to: 
> https://emacs.stackexchange.com/questions/15185/cant-assign-to-hline-relative-reference
>
> There seem to be restrictions regarding hline-relative-references within 
> table-formulas.
>
> If change 'I' and 'II' for 1 and 2 on the very left of the formula, it works 
> (keeping the other hline-relative parts) . If I stay with the former I get 
> the same error as you (emacs 26.1, orgmode 9.1.9, Debian stable).
>
> I hope this can help,
> Daniel
>
> Am 21. Oktober 2020 03:14:10 MESZ schrieb Dante Catalfamo :
>
>> Hello,
>>
>> I'm trying to create a table where the third column between two hlines is 
>> set by a formula referencing the second column.
>>
>> Here is an example:
>>
>> | a | b |  c |
>>
>> |---+---+|
>>
>> | row 1 | 12.00 | 144.00 |
>>
>> | row 2 |   |  23.00 |
>>
>> |---+---+|
>>
>> | sum   | 12.00 | 167.00 |
>>
>> #+TBLFM: @I$3..II$3=if($2 != 0, 12*$2, 
>> $3);%.2f::@4$2=vsum(@I..II);%.2f::@4$3=vsum(@I..II);%.2f
>>
>> When I try to calculate this table however, I get the error "Can’t assign to 
>> hline relative reference".
>>
>> Why is this now allowed? This seems like a fairly mundane use of a table to 
>> me. It is explicitly disabled in the source, but without explanation, and 
>> searching the mailing list doesn't turn up many answers.
>>
>> Is there a recommended way to handle a situation like this?
>>
>> Could this feature be fixed?
>>
>> Thank you,
>>
>> Dante
>
> --
> Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.

Re: [PATCH] org-table: Add mode flag to enable Calc units simplification mode

2020-10-21 Thread Daniele Nicolodi
Hello,

after working on this I realized that the org-tbl-calc-modes variables
is used only locally despite being declare globally. Maybe a remnant
from pre-lexical-binding times. Attached is a patch (on top of the
others one in this thread) that simplifies things a little.

Cheers,
Dan


On 20/10/2020 15:30, Daniele Nicolodi wrote:
> Hello,
> 
> attached there are a few patches reworking the code, fixing the bug, and
> introducing a new mode flag to enable Calc's units simplification mode
> as discussed in a recent thread on the mailing list.  I haven't updated
> the documentation.  I can do it once we agree that this feature is a
> good idea.
> 
> Cheers,
> Dan
> 
> 
> On 19/10/2020 17:38, Daniele Nicolodi wrote:
>> Hello,
>>
>> I am hacking org-table-eval-formula (see thread about monetary values in
>> org-tables) which uses this inline function:
>>
>> (defsubst org-table--set-calc-mode (var  value)
>>   (if (stringp var)
>>   (setq var (assoc var '(("D" calc-angle-mode deg)
>>   ("R" calc-angle-mode rad)
>>   ("F" calc-prefer-frac t)
>>   ("S" calc-symbolic-mode t)))
>>  value (nth 2 var) var (nth 1 var)))
>>   (if (memq var org-tbl-calc-modes)
>>   (setcar (cdr (memq var org-tbl-calc-modes)) value)
>> (cons var (cons value org-tbl-calc-modes)))
>>   org-tbl-calc-modes)
>>
>> which I am not able to understand or which is not correct.
>>
>> The first (if ...) does some value substitutions, however, IIUC the
>> second (if ...) sets a new value for an entry in the org-tbl-calc-modes
>> plist if the entry is already present and builds a new plist with the
>> entry prepended if the entry is not there. However, the original plist
>> is returned and not the one with the new entry prepended.
>>
>> It does not seem to be the intended behavior.
>>
>> Shouldn't this be simply:
>>
>> (defsubst org-table--set-calc-mode (var  value)
>>   (if (stringp var)
>>   (setq var (assoc var '(("D" calc-angle-mode deg)
>>   ("R" calc-angle-mode rad)
>>   ("F" calc-prefer-frac t)
>>   ("S" calc-symbolic-mode t)))
>>  value (nth 2 var) var (nth 1 var)))
>>   (plist-put org-tbl-calc-modes var value))
>>
>> or, better, the code refactored to do not use this function?
>>
>> Cheers,
>> Dan
>>
> 

From 2d4521a032ec3e4174c97b2b2e9a08491e9870fb Mon Sep 17 00:00:00 2001
From: Daniele Nicolodi 
Date: Wed, 21 Oct 2020 17:47:15 +0200
Subject: [PATCH 4/4] org-table: Remove unused org-tbl-calc-modes variable

* org-table.el (org-tbl-calc-modes): Remove the variable declaration
as the varialble is only used as a local variable in `org-table-eval-formula'.

* org-table.el (org-table--set-calc-mode): Drop convenience macro.

* org-table.el (org-table-eval-formula): Rename `org-tbl-calc-modes`
local variable without the org-table prefix and usr the gained screen
real estate to avoid indirection through covenience macro.
---
 lisp/org-table.el | 29 -
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 6b92656bd..1651decd3 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -676,8 +676,6 @@ Will be filled automatically during use.")
 ("_" . "Names for values in row below this one.")
 ("^" . "Names for values in row above this one.")))
 
-(defvar org-tbl-calc-modes nil)
-
 (defvar org-pos nil)
 
 
@@ -721,9 +719,6 @@ Field is restored even in case of abnormal exit."
 (org-table-goto-column ,column)
 (set-marker ,line nil)
 
-(defsubst org-table--set-calc-mode (var value)
-  (setq org-tbl-calc-modes (plist-put org-tbl-calc-modes var value)))
-
 
 ;;; Predicates
 
@@ -2424,7 +2419,7 @@ location of point."
equation
  (org-table-get-formula equation (equal arg '(4)
   (n0 (org-table-current-column))
-  (org-tbl-calc-modes (copy-sequence org-calc-default-modes))
+  (calc-modes (copy-sequence org-calc-default-modes))
   (numbers nil)   ; was a variable, now fixed default
   (keep-empty nil)
   form form0 formrpl formrg bw fmt ev orig lispp literal
@@ -2440,11 +2435,11 @@ location of point."
  (let ((c (string-to-char (match-string 1 fmt)))
(n (string-to-number (match-string 2 fmt
(cl-case c
- (?p (org-table--set-calc-mode 'calc-internal-prec n))
- (?n (org-table--set-calc-mode 'calc-float-format (list 'float 
n)))
- (?f (org-table--set-calc-mode 'calc-float-format (list 'fix 
n)))
- (?s (org-table--set-calc-mode 'calc-float-format (list 'sci 
n)))
- (?e (org-table--set-calc-mode 'calc-float-format (list 'eng 
n)
+ (?p (setf (cl-getf calc-modes 'calc-internal-prec) n))
+ (?n (setf (cl-getf 

Bug: org-insert-heading-respect-content before first heading [9.4 (9.4-19-gb1de0c-elpaplus @ /home/gustavo/.emacs.d/elpa/org-plus-contrib-20201019/)]

2020-10-21 Thread Gustavo Barros

Hi All,

I just found a misbehaving of `org-insert-heading-respect-content': when 
it's called before the first heading in the buffer, it breaks the 
structure of that fist heading by inserting a new heading on the line 
the previous heading existed.


An ECM to reproduce the issue is:

- Start 'emacs -Q'

- Do an initial setup:
 #+begin_src emacs-lisp
 (add-to-list 'load-path "~/.emacs.d/elpa/org-plus-contrib-20201019")
 #+end_src

- Visit file =test.org= with contents:
 #+begin_src org
 ,#+title: Title


 ,* Foo
 #+end_src

- Place point between the title and the "Foo" heading, and call 
 `org-insert-heading-respect-content' with "C-RET".


- The result is:
 #+begin_src org
 ,#+title: Title


 ,* !* Foo
 #+end_src
 where "!" represents point position.

Which clearly does not "respect content" of the following heading.

Best regards,
Gustavo.


Emacs  : GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 
3.24.20, cairo version 1.16.0)

of 2020-08-11
Package: Org mode version 9.4 (9.4-19-gb1de0c-elpaplus @ 
/home/gustavo/.emacs.d/elpa/org-plus-contrib-20201019/)


current state:
==
(setq
org-src-mode-hook '(org-src-babel-configure-edit-buffer 
org-src-mode-configure-edit-buffer)

org-link-shell-confirm-function 'yes-or-no-p
org-metadown-hook '(org-babel-pop-to-session-maybe)
org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
org-mode-hook '(#[0 "\300\301\302\303\304$\207" [add-hook 
change-major-mode-hook org-show-all append local] 5]

 #[0 "\300\301\302\303\304$\207"
		   [add-hook change-major-mode-hook 
		   org-babel-show-result-all append local] 5]
		 org-babel-result-hide-spec org-babel-hide-all-hashes 
		 org-eldoc-load)

org-archive-hook '(org-attach-archive-delete-maybe)
org-confirm-elisp-link-function 'yes-or-no-p
org-agenda-before-write-hook '(org-agenda-add-entry-text)
org-metaup-hook '(org-babel-load-in-session-maybe)
org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 
"\n\n(fn ENTRY)"]

org-babel-pre-tangle-hook '(save-buffer)
org-tab-first-hook '(org-babel-hide-result-toggle-maybe 
org-babel-header-arg-expand)

org-agenda-loop-over-headlines-in-active-region nil
org-src-lang-modes '(("arduino" . arduino) ("redis" . redis) ("php" 
. php) ("C" . c) ("C++" . c++)
		  ("asymptote" . asy) ("bash" . sh) ("beamer" 
		  . latex) ("calc" . fundamental) ("cpp" . c++)
		  ("ditaa" . artist) ("dot" . fundamental) ("elisp" 
		  . emacs-lisp) ("ocaml" . tuareg)
		  ("screen" . shell-script) ("shell" . sh) ("sqlite" 
		  . sql))

org-occur-hook '(org-first-headline-recenter)
org-cycle-hook '(org-cycle-hide-archived-subtrees 
org-cycle-hide-drawers org-cycle-show-empty-lines

  org-optimize-window-after-visibility-change)
org-speed-command-hook '(org-speed-command-activate 
org-babel-speed-command-activate)

org-export-before-parsing-hook '(org-attach-expand-links)
org-confirm-shell-link-function 'yes-or-no-p
org-link-parameters '(("attachment" :follow org-attach-follow :complete 
org-attach-complete-link)
		   ("id" :follow org-id-open) ("eww" :follow 
		   org-eww-open :store org-eww-store-link)
		   ("rmail" :follow org-rmail-open :store 
		   org-rmail-store-link)
		   ("mhe" :follow org-mhe-open :store 
		   org-mhe-store-link)
		   ("irc" :follow org-irc-visit :store 
		   org-irc-store-link :export org-irc-export)
		   ("info" :follow org-info-open :export 
		   org-info-export :store org-info-store-link)
		   ("gnus" :follow org-gnus-open :store 
		   org-gnus-store-link)
		   ("docview" :follow org-docview-open :export 
		   org-docview-export :store

org-docview-store-link)
		   ("bibtex" :follow org-bibtex-open :store 
		   org-bibtex-store-link)
		   ("bbdb" :follow org-bbdb-open :export 
		   org-bbdb-export :complete org-bbdb-complete-link

:store org-bbdb-store-link)
		   ("w3m" :store org-w3m-store-link) ("file+sys") 
		   ("file+emacs")

   ("shell" :follow org-link--open-shell)
   ("news" :follow
			#[514 "\301\300\302Q\"\207" ["news" browse-url 
":"] 6 "\n\n(fn URL ARG)"])

   ("mailto" :follow
			#[514 "\301\300\302Q\"\207" ["mailto" browse-url 
":"] 6 "\n\n(fn URL ARG)"])

   ("https" :follow
			#[514 "\301\300\302Q\"\207" ["https" browse-url 
":"] 6 "\n\n(fn URL ARG)"])

   ("http" :follow
			#[514 "\301\300\302Q\"\207" ["http" browse-url 
":"] 6 "\n\n(fn URL ARG)"])

   ("ftp" :follow
			#[514 "\301\300\302Q\"\207" ["ftp" browse-url 
":"] 6 "\n\n(fn URL ARG)"])
		   ("help" :follow org-link--open-help) ("file" 
		   :complete org-link-complete-file)
		   ("elisp" :follow org-link--open-elisp) ("doi" 
		   

Re: [PATCH] ob-java

2020-10-21 Thread John Herrlin


ian martins  writes:

>>
>> What do you think about having a configurable list where the user can
>> add =org-babel-java--import-maybe=? In my current use case I could then
>> add RxJava imports to that list and the imports could be removed from
>> the source code block.
>
>
> I think this can already be done. imports can be added to the headers, and
> babel allows file-wide headers, so you could add a =#+HEADER: :import
> rx.Observable= line to the file and all source blocks would get it.  it's
> slightly different in that =org-babel-java--import-maybe= skips imports
> that it thinks aren't needed. also if there are any non-java source blocks
> in the same file, these imports could be added to them which would be bad,
> so when mixing multiple languages in the same file this wouldn't be an
> option.

Thanks for pointing that out! It work just fine!

>
> NIT
>> Some spacing when writing =public static...=
>>
>
> Thanks for fixing the spacing. I don't think I can give you credit for the
> patch, though, without leaving it out until ob-java is accepted.

I dont need any credits, the important part is the result!

I have made a couple of more runs and I cant find anything that doesnt
work!

>
> On Wed, Oct 21, 2020 at 1:59 AM John Herrlin  wrote:
>
>>
>> I did and it looks really good. The difference in this example:
>>
>> #+BEGIN_SRC java
>>   import rx.Observable;
>>
>>   Observable.range(5, 3)
>>   .subscribe((Integer i) ->   { System.out.println("Got: " + i); },
>>  (Throwable t) -> { t.printStackTrace();},
>>  () ->{ System.out.println("Ending
>> stream"); });
>> #+END_SRC
>>
>> from the ones I posted yesterday is tremendous!
>>
>> I am not very experienced with Emacs lisp but I think it's pretty easy
>> to understand how things works and follow the code. The comments are
>> also of good help. I really appreciate the work you have done!
>>
>>
>> What do you think about having a configurable list where the user can
>> add =org-babel-java--import-maybe=? In my current use case I could then
>> add RxJava imports to that list and the imports could be removed from
>> the source code block.
>>
>>
>> NIT
>>
>> Some spacing when writing =public static...=
>>
>>#+BEGIN_SRC diff
>>  diff --git a/lisp/ob-java.el b/lisp/ob-java.el
>>  index 94c3f69cf..4f3904871 100644
>>  --- a/lisp/ob-java.el
>>  +++ b/lisp/ob-java.el
>>  @@ -220,7 +220,7 @@ RESULT-FILE is the temp file to write the result."
>> (org-babel-java--move-past org-babel-java--class-re)
>> (insert "\npublic static void main(String[] args) {
>>   System.out.print(\"success\");
>>  -}\n\n"))
>>  +}\n\n"))
>>
>>   ;; special handling to return value
>>   (when (eq result-type 'value)
>>#+END_SRC
>>
>>
>>
>> ian martins  writes:
>>
>> > Thanks for testing, and thanks for pointing that out. I will fix it so
>> that
>> > `public` is optional.
>> >
>> > btw, in your example you didn't have to specify `:classname` since you
>> > defined the class name in the source block.
>> >
>> > btw2, did you notice that you can C-c C-c on source blocks that don't
>> have
>> > main methods and it'll compile without error?
>> >
>> > On Tue, Oct 20, 2020 at 3:17 PM John Herrlin  wrote:
>> >
>> >>
>> >> Hey,
>> >>
>> >> Did some debugging and found out that my class didn't contained =public=
>> >> and the patch requires it to be.
>> >>
>> >> This works fine:
>> >>
>> >>#+HEADER: :classname Main
>> >>#+HEADER: :dir src
>> >>#+HEADER: :cmdline -classpath ./rxjava-1.3.8.jar:.
>> >>#+HEADER: :cmpflag -classpath ./rxjava-1.3.8.jar
>> >>#+BEGIN_SRC java :results output code
>> >>  import rx.Observable;
>> >>  public class Main {
>> >>  public static void main(String[] args) {
>> >>  Observable.range(5, 5)
>> >>  .subscribe(System.out::println);
>> >>  }
>> >>  }
>> >>#+END_SRC
>> >>
>> >>
>> >>
>> >>
>> >> ian martins  writes:
>> >>
>> >> > I noticed that the tests didn't run with "make test." This updates the
>> >> > patch so that they can. I didn't add java to the list of default
>> >> languages
>> >> > because the java tests are slow.
>> >> >
>> >> > On Mon, Oct 5, 2020 at 9:23 AM ian martins  wrote:
>> >> >
>> >> >> I wrote those examples in an org file so I could test as I wrote
>> them,
>> >> and
>> >> >> then exported it to make it more readable, but the export resulted in
>> >> >> source block headers being lost.  Here is the same without export:
>> >> >> 
>> >> >> * Changes
>> >> >>
>> >> >> - support for functional mode (~:results value~)
>> >> >> - accept variables
>> >> >> - don't require package, class, and main definitions
>> >> >> - write source and result tempfiles to
>> ~org-babel-temporary-directory~,
>> >> >> but respects the ~:dir~ header
>> >> >> - work with tramp
>> >> >>
>> >> >> * Examples
>> >> >> ** 

Re: Bug: Can’t assign to hline relative reference

2020-10-21 Thread Daniel Herzig
This seems to be related to: 
https://emacs.stackexchange.com/questions/15185/cant-assign-to-hline-relative-reference

There seem to be restrictions regarding hline-relative-references within 
table-formulas.

If change 'I' and 'II' for 1 and 2 on the very left of the formula, it works 
(keeping the other hline-relative parts) . If I stay with the former I get the 
same error as you (emacs 26.1, orgmode 9.1.9, Debian stable).

I hope this can help, 
Daniel


Am 21. Oktober 2020 03:14:10 MESZ schrieb Dante Catalfamo :
>Hello,
>
>I'm trying to create a table where the third column between two hlines
>is set by a formula referencing the second column.
>
>Here is an example:
>
>| a | b |  c |
>|---+---+|
>| row 1 | 12.00 | 144.00 |
>| row 2 |   |  23.00 |
>|---+---+|
>| sum   | 12.00 | 167.00 |
>#+TBLFM: @I$3..II$3=if($2 != 0, 12*$2,
>$3);%.2f::@4$2=vsum(@I..II);%.2f::@4$3=vsum(@I..II);%.2f
>
>When I try to calculate this table however, I get the error "Can’t
>assign to hline relative reference".
>
>Why is this now allowed? This seems like a fairly mundane use of a
>table to me. It is explicitly disabled in the source, but without
>explanation, and searching the mailing list doesn't turn up many
>answers.
>
>Is there a recommended way to handle a situation like this?
>
>Could this feature be fixed?
>
>Thank you,
>Dante

-- 
Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.

Re: [PATCH] ob-java

2020-10-21 Thread ian martins
>
> What do you think about having a configurable list where the user can
> add =org-babel-java--import-maybe=? In my current use case I could then
> add RxJava imports to that list and the imports could be removed from
> the source code block.


I think this can already be done. imports can be added to the headers, and
babel allows file-wide headers, so you could add a =#+HEADER: :import
rx.Observable= line to the file and all source blocks would get it.  it's
slightly different in that =org-babel-java--import-maybe= skips imports
that it thinks aren't needed. also if there are any non-java source blocks
in the same file, these imports could be added to them which would be bad,
so when mixing multiple languages in the same file this wouldn't be an
option.

NIT
> Some spacing when writing =public static...=
>

Thanks for fixing the spacing. I don't think I can give you credit for the
patch, though, without leaving it out until ob-java is accepted.

On Wed, Oct 21, 2020 at 1:59 AM John Herrlin  wrote:

>
> I did and it looks really good. The difference in this example:
>
> #+BEGIN_SRC java
>   import rx.Observable;
>
>   Observable.range(5, 3)
>   .subscribe((Integer i) ->   { System.out.println("Got: " + i); },
>  (Throwable t) -> { t.printStackTrace();},
>  () ->{ System.out.println("Ending
> stream"); });
> #+END_SRC
>
> from the ones I posted yesterday is tremendous!
>
> I am not very experienced with Emacs lisp but I think it's pretty easy
> to understand how things works and follow the code. The comments are
> also of good help. I really appreciate the work you have done!
>
>
> What do you think about having a configurable list where the user can
> add =org-babel-java--import-maybe=? In my current use case I could then
> add RxJava imports to that list and the imports could be removed from
> the source code block.
>
>
> NIT
>
> Some spacing when writing =public static...=
>
>#+BEGIN_SRC diff
>  diff --git a/lisp/ob-java.el b/lisp/ob-java.el
>  index 94c3f69cf..4f3904871 100644
>  --- a/lisp/ob-java.el
>  +++ b/lisp/ob-java.el
>  @@ -220,7 +220,7 @@ RESULT-FILE is the temp file to write the result."
> (org-babel-java--move-past org-babel-java--class-re)
> (insert "\npublic static void main(String[] args) {
>   System.out.print(\"success\");
>  -}\n\n"))
>  +}\n\n"))
>
>   ;; special handling to return value
>   (when (eq result-type 'value)
>#+END_SRC
>
>
>
> ian martins  writes:
>
> > Thanks for testing, and thanks for pointing that out. I will fix it so
> that
> > `public` is optional.
> >
> > btw, in your example you didn't have to specify `:classname` since you
> > defined the class name in the source block.
> >
> > btw2, did you notice that you can C-c C-c on source blocks that don't
> have
> > main methods and it'll compile without error?
> >
> > On Tue, Oct 20, 2020 at 3:17 PM John Herrlin  wrote:
> >
> >>
> >> Hey,
> >>
> >> Did some debugging and found out that my class didn't contained =public=
> >> and the patch requires it to be.
> >>
> >> This works fine:
> >>
> >>#+HEADER: :classname Main
> >>#+HEADER: :dir src
> >>#+HEADER: :cmdline -classpath ./rxjava-1.3.8.jar:.
> >>#+HEADER: :cmpflag -classpath ./rxjava-1.3.8.jar
> >>#+BEGIN_SRC java :results output code
> >>  import rx.Observable;
> >>  public class Main {
> >>  public static void main(String[] args) {
> >>  Observable.range(5, 5)
> >>  .subscribe(System.out::println);
> >>  }
> >>  }
> >>#+END_SRC
> >>
> >>
> >>
> >>
> >> ian martins  writes:
> >>
> >> > I noticed that the tests didn't run with "make test." This updates the
> >> > patch so that they can. I didn't add java to the list of default
> >> languages
> >> > because the java tests are slow.
> >> >
> >> > On Mon, Oct 5, 2020 at 9:23 AM ian martins  wrote:
> >> >
> >> >> I wrote those examples in an org file so I could test as I wrote
> them,
> >> and
> >> >> then exported it to make it more readable, but the export resulted in
> >> >> source block headers being lost.  Here is the same without export:
> >> >> 
> >> >> * Changes
> >> >>
> >> >> - support for functional mode (~:results value~)
> >> >> - accept variables
> >> >> - don't require package, class, and main definitions
> >> >> - write source and result tempfiles to
> ~org-babel-temporary-directory~,
> >> >> but respects the ~:dir~ header
> >> >> - work with tramp
> >> >>
> >> >> * Examples
> >> >> ** Example 1
> >> >> This outputs "hello."  If class and main definitions aren't given the
> >> >> code block will be wrapped in generic ones.
> >> >>
> >> >> #+begin_src java :results output silent
> >> >>   System.out.print("hello");
> >> >> #+end_src
> >> >>
> >> >> This is exactly equivalent:
> >> >>
> >> >> #+begin_src java :results output silent
> >> >>   public 

Interview with Rainer König - who's content made me go from vim to emacs for coding :D

2020-10-21 Thread Martin Schröder
Today I had the chance to do a lengthy interview with Rainer König who is
known for creating a very popular Org Mode course.

The first part is about how Rainer got started and the story of how Org
Mode saved his life during a very difficult time:
https://www.youtube.com/watch?v=L_DYO0_eJ6A

In the second part of the interview we look at how Rainer manages his org
mode setup with multiple files and weekly reviews. Rainer is tremendously
methodical and a really good teacher.

Here is the recording of the second part:
https://www.youtube.com/watch?v=kPKhS-QDn7c

Enjoy!

-- 
Best regards,

*Martin Schröder*
*Embedded Systems Consultant, Firmware Expert*

Tel: +46-733-38-76-94
LinkedIn: https://www.linkedin.com/in/martinschroder/

*Learn How To Build Embedded Products From Step 1 to Step 90:*
https://swedishembedded.com/learn/


Re: [PATCH] ob-java

2020-10-21 Thread John Herrlin


I did and it looks really good. The difference in this example:

#+BEGIN_SRC java
  import rx.Observable;

  Observable.range(5, 3)
  .subscribe((Integer i) ->   { System.out.println("Got: " + i); },
 (Throwable t) -> { t.printStackTrace();},
 () ->{ System.out.println("Ending stream"); });
#+END_SRC

from the ones I posted yesterday is tremendous!

I am not very experienced with Emacs lisp but I think it's pretty easy
to understand how things works and follow the code. The comments are
also of good help. I really appreciate the work you have done!


What do you think about having a configurable list where the user can
add =org-babel-java--import-maybe=? In my current use case I could then
add RxJava imports to that list and the imports could be removed from
the source code block.


NIT

Some spacing when writing =public static...=

   #+BEGIN_SRC diff
 diff --git a/lisp/ob-java.el b/lisp/ob-java.el
 index 94c3f69cf..4f3904871 100644
 --- a/lisp/ob-java.el
 +++ b/lisp/ob-java.el
 @@ -220,7 +220,7 @@ RESULT-FILE is the temp file to write the result."
(org-babel-java--move-past org-babel-java--class-re)
(insert "\npublic static void main(String[] args) {
  System.out.print(\"success\");
 -}\n\n"))
 +}\n\n"))

  ;; special handling to return value
  (when (eq result-type 'value)
   #+END_SRC



ian martins  writes:

> Thanks for testing, and thanks for pointing that out. I will fix it so that
> `public` is optional.
>
> btw, in your example you didn't have to specify `:classname` since you
> defined the class name in the source block.
>
> btw2, did you notice that you can C-c C-c on source blocks that don't have
> main methods and it'll compile without error?
>
> On Tue, Oct 20, 2020 at 3:17 PM John Herrlin  wrote:
>
>>
>> Hey,
>>
>> Did some debugging and found out that my class didn't contained =public=
>> and the patch requires it to be.
>>
>> This works fine:
>>
>>#+HEADER: :classname Main
>>#+HEADER: :dir src
>>#+HEADER: :cmdline -classpath ./rxjava-1.3.8.jar:.
>>#+HEADER: :cmpflag -classpath ./rxjava-1.3.8.jar
>>#+BEGIN_SRC java :results output code
>>  import rx.Observable;
>>  public class Main {
>>  public static void main(String[] args) {
>>  Observable.range(5, 5)
>>  .subscribe(System.out::println);
>>  }
>>  }
>>#+END_SRC
>>
>>
>>
>>
>> ian martins  writes:
>>
>> > I noticed that the tests didn't run with "make test." This updates the
>> > patch so that they can. I didn't add java to the list of default
>> languages
>> > because the java tests are slow.
>> >
>> > On Mon, Oct 5, 2020 at 9:23 AM ian martins  wrote:
>> >
>> >> I wrote those examples in an org file so I could test as I wrote them,
>> and
>> >> then exported it to make it more readable, but the export resulted in
>> >> source block headers being lost.  Here is the same without export:
>> >> 
>> >> * Changes
>> >>
>> >> - support for functional mode (~:results value~)
>> >> - accept variables
>> >> - don't require package, class, and main definitions
>> >> - write source and result tempfiles to ~org-babel-temporary-directory~,
>> >> but respects the ~:dir~ header
>> >> - work with tramp
>> >>
>> >> * Examples
>> >> ** Example 1
>> >> This outputs "hello."  If class and main definitions aren't given the
>> >> code block will be wrapped in generic ones.
>> >>
>> >> #+begin_src java :results output silent
>> >>   System.out.print("hello");
>> >> #+end_src
>> >>
>> >> This is exactly equivalent:
>> >>
>> >> #+begin_src java :results output silent
>> >>   public class Main {
>> >>   public static void main(String[] args) {
>> >>   System.out.print("hello");
>> >>   }
>> >>   }
>> >> #+end_src
>> >>
>> >> ** Example 2
>> >> This also outputs "hello."
>> >>
>> >> #+begin_src java :results value silent
>> >>   return "hello";
>> >> #+end_src
>> >>
>> >> ** Example 3
>> >> This generates the class "Example" in the package "org.orgmode" in the
>> >> current directory.
>> >>
>> >> #+begin_src java :results output silent :classname org.orgmode.Example
>> >> :dir .
>> >>   System.out.print("hello, org-mode");
>> >> #+end_src
>> >>
>> >> ** Example 4
>> >> The "Hey" class defines a static method but no main. C-c C-c on the
>> >> "Hey" source block will write "./org/orgmode/Hey.java" and compile it.
>> >>
>> >> The "Main" class calls the "Hey" class. C-c C-c on the "Main" source
>> >> block will write "./org/orgmode/Main.java" and compile and run it.
>> >>
>> >> #+begin_src java :results output silent :dir .
>> >>   package org.orgmode;
>> >>
>> >>   public class Hey {
>> >>   public static String say() {
>> >>   return "hey";
>> >>   }
>> >>   }
>> >> #+end_src
>> >>
>> >> #+begin_src java :results output silent :dir .
>> >>   package org.orgmode;
>> >>
>> >>   public