Re: Babel: parse error when output contains opening bracket

2020-06-27 Thread Jarmo Hurri


>> ian martins  writes:
>> 
>> Would it be possible for us to fix the current version without
>> introducing a new one? Can you identify the parts of your code that fix
>> the issue?
>>
> The existing code creates the java program and runs it correctly, but
> it uses `org-babel-import-elisp-from-file' to interpret the results,
> and that sees the bracket and tries to make the response into a list,
> and errors when it can't. I don't see a quick fix for it. If you allow
> unbalanced brackets but that would be a change in ob-core and would
> probably cause unwanted results in other places. If you don't try to
> convert the output into a list, you can't present java results as
> lists or tables.  Really the problem is that ob-java doesn't support
> functional mode, so it tries to guess if scripting mode output should
> be a table or list.  The version I wrote supports functional and
> scripting modes and doesn't use `org-babel-import-elisp-from-file'.

Ok.

>> I am already a contributor, so if you can post your solution here I
>> can create a patch and give you the credit.
>>
> I would really appreciate that if you are willing, but it's a
> significant change (code is 400 lines, 600 lines of tests and test
> data) and there might be iterations so you might be signing up for
> more than you realize.

Fair enough.

1. Have you considered writing a patch yourself?

2. If not, I think you lose nothing by posting your code here and
   patiently waiting if I can create something out of it.

All the best,

Jarmo




Re: [bug] select TODO items and unexpected behaviour

2020-06-27 Thread Russell Adams
On Sat, Jun 27, 2020 at 04:16:53PM -0500, Mario Frasca wrote:
> when I select subsequent TODO items, whole lines, and I do M-,
> they get demoted by one star, so something like
>
> * header
> * a1
> * a2
> * a3
> * header
>
> after I hit M- will become
>
> * header
> ** a1
> ** a2
> ** a3
> * header
>
> which is what I expected, even if I would not expect the region to be
> deactivated.

I thought shift-meta-right added a shift to subtrees in addition to the current
headline.

You expected it to work with the region? I always use multiple-cursors mode for
that...

https://orgmode.org/org.html#Structure-Editing

This doesn't mention working on the region. Did you read that somewhere?

--
Russell Adamsrlad...@adamsinfoserv.com

PGP Key ID: 0x1160DCB3   http://www.adamsinfoserv.com/

Fingerprint:1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3



Re: [bug] select TODO items and unexpected behaviour

2020-06-27 Thread Mario Frasca
if I change those 'right and 'left, to :right and :left, the handling 
them over and over as symbols will not start confusing them as 
variables, and keep them as symbols.


On 27/06/2020 16:43, Mario Frasca wrote:
this behaviour comes after somehow my 
`org-loop-over-headlines-in-active-region' became nil.


if I set it back to t, I get the message "Symbol's value as variable 
is void: right".


I had enabled debugging, and my guess is that this might have left the 
value of `org-loop-over-headlines-in-active-region' at the 
"inside-looping" setting.  just guessing.


On 27/06/2020 16:16, Mario Frasca wrote:
when I select subsequent TODO items, whole lines, and I do M-, 
they get demoted by one star, so something like


* header
* a1
* a2
* a3
* header

after I hit M- will become

* header
** a1
** a2
** a3
* header

which is what I expected, even if I would not expect the region to be 
deactivated.


but if I now reactivate the region, andhit S- (that's 
shift-right), the effect is only at the , not on the selection:


* header
** TODO a1
** a2
** a3
* header

I would have expected all lines to get the TODO.Same effect, if I hit 
C-c C-t: only the line at the point gets the TODO status rotated.


looks like a bug to me, but I would not know where to start looking 
for how to fix this.


Mario





Re: [bug] select TODO items and unexpected behaviour

2020-06-27 Thread Mario Frasca
this behaviour comes after somehow my 
`org-loop-over-headlines-in-active-region' became nil.


if I set it back to t, I get the message "Symbol's value as variable is 
void: right".


I had enabled debugging, and my guess is that this might have left the 
value of `org-loop-over-headlines-in-active-region' at the 
"inside-looping" setting.  just guessing.


On 27/06/2020 16:16, Mario Frasca wrote:
when I select subsequent TODO items, whole lines, and I do M-, 
they get demoted by one star, so something like


* header
* a1
* a2
* a3
* header

after I hit M- will become

* header
** a1
** a2
** a3
* header

which is what I expected, even if I would not expect the region to be 
deactivated.


but if I now reactivate the region, andhit S- (that's 
shift-right), the effect is only at the , not on the selection:


* header
** TODO a1
** a2
** a3
* header

I would have expected all lines to get the TODO.Same effect, if I hit 
C-c C-t: only the line at the point gets the TODO status rotated.


looks like a bug to me, but I would not know where to start looking 
for how to fix this.


Mario





[bug] select TODO items and unexpected behaviour

2020-06-27 Thread Mario Frasca
when I select subsequent TODO items, whole lines, and I do M-, 
they get demoted by one star, so something like


* header
* a1
* a2
* a3
* header

after I hit M- will become

* header
** a1
** a2
** a3
* header

which is what I expected, even if I would not expect the region to be 
deactivated.


but if I now reactivate the region, andhit S- (that's 
shift-right), the effect is only at the , not on the selection:


* header
** TODO a1
** a2
** a3
* header

I would have expected all lines to get the TODO.Same effect, if I hit 
C-c C-t: only the line at the point gets the TODO status rotated.


looks like a bug to me, but I would not know where to start looking for 
how to fix this.


Mario




Re: [patch] simplify-compact initial data extraction from plist

2020-06-27 Thread tomas
On Sat, Jun 27, 2020 at 10:18:21AM -0500, Mario Frasca wrote:
> this is a result of some help I received a few days ago in the
> #emacs irc chat room on freenode.
> 
> I was wondering why we were adding a semicolon in front of names,
> before creating symbols, and I understand this is because such
> symbols work as keys.

I assume you mean a "colon", like this `:'

Those :foo thingies have another nice property: they are self-evaluating,
like numbers. If you try, e.g. to eval foo, the evaluator tries to find
a variable named foo and the result is then that variable's value.

If you evaluate 'foo, the result is the symbol foo.

If you evaluate :foo, the result is :foo, like when you evaluate 1234,
where the result is simply 1234.

Cheers
-- t


signature.asc
Description: Digital signature


Re: use-package examples?

2020-06-27 Thread Diego Zamboni
Hi Bill,

Glad you found my config already. For custom faces, I do a lot of
configuration interactively with =customize-face=, because it allows me to
play more freely with them. But you can see some examples in my config, and
also in my post at https://zzamboni.org/post/beautifying-org-mode-in-emacs/.

One tip I have found very useful when customizing org's faces is to use the
=what-cursor-position= command (bound by default to C-u C-x =) to show
information about the character under the cursor, including the face which
is being used for it. This helps a lot to know which face you have to
customize to fix something.

Have fun :)

--Diego


On Mon, Jun 22, 2020 at 11:06 PM William Denton  wrote:

> It could be useful to have some documentation about installing and
> configuring Org with use-package [1].
>
> I just redid my Org config this way, and I'm happy to say it works, though
> a
> use-package wizard would probably cut it in half.  (To me use-package is
> advanced magic, and I don't understand all the incantations.)
>
> If anyone can suggest some good examples to look at, I'll try starting
> some
> documentation about it.  I know about Diego Zamboni [2] and Sacha Chua
> [3], but
> there must be more.  Things with custom faces and such would be especially
> welcome.
>
> Bill
>
> [1] https://github.com/jwiegley/use-package
> [2] https://github.com/zzamboni/dot-emacs/
> [3] https://github.com/sachac/.emacs.d
> --
> William Denton :: Toronto, Canada   ---   Listening to Art:
> https://listeningtoart.org/
> https://www.miskatonic.org/ ---   GHG.EARTH: https://ghg.earth/
> Caveat lector.  ---   STAPLR: https://staplr.org/
>
>


Re: [PATCH] allow for multiline headers

2020-06-27 Thread Mario Frasca

Hi Nicolas and the whole world,

On 24/06/2020 02:19, Nicolas Goaziou wrote:



This could be extracted as an independent function, which would return
the header, or nil. We can also imagine a function returning a cons cell
(HEADER . BODY), both HEADER and BODY being list of rows (possibly
empty).

I was thinking of this myself too.  but, after all, the goal of this
function is not only to find the header, but to collapse it into
a single line.

I suggested this because you were saying earlier in this thread IIRC
that Org has no tooling to handle table headers.
I would like to discuss this in a chat, who's available to join 
#org-mode on freenode?

if it was splitting the header from the body, then yes, it would
definitely make sense, the cons cell you suggest.

It _is_ splitting the header from the body. Barring initial `hline'
symbols, header-lines and trailer variables are exactly HEADER and BODY
above.
same as above, I wish to hear opinions, collect them, and that we take a 
decision with shorter communication lines.



+  (table (org-table-collapse-header (org-table-to-lisp)))
+  (num-cols (length (car table

Note that there is no guarantee that all rows have the same length.
E.g.,

   | a |
   | b | c |


many other points in the code assume rows have the same length. I 
haven't checked if the assumption is correct, I just used it as I saw 
the code already does.



I think I have processed most other remarks in the new patch.

and I have signed and received confirmation of reception of my FSF 
paperwork :-)


ciao,

Mario

>From ca92fb1e4ee66ed39e5b567880faccc513d263d4 Mon Sep 17 00:00:00 2001
From: mfrasca 
Date: Fri, 12 Jun 2020 11:42:34 -0500
Subject: [PATCH] lisp/org-table.el: Allow collapsing header into single line

* lisp/org-table.el (org-table-collapse-header): New function.

* lisp/org-plot.el (org-plot/gnuplot): Use org-table-collapse-header
and trust there will be no more leading `hline' symbols in lisp table.

* testing/lisp/test-org-table.el (test-org-table/to-lisp):
Adding tests to already existing to-lisp function.
(test-org-table/collapse-header): Adding tests to new
collapse-header function.

* testing/lisp/test-ox.el (test-org-export/has-header-p): Testing
exporting table with multi-line header.
---
 lisp/org-plot.el   |  8 ++---
 lisp/org-table.el  | 27 +++-
 testing/lisp/test-org-table.el | 58 ++
 testing/lisp/test-ox.el| 10 ++
 4 files changed, 97 insertions(+), 6 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..35077cfc3 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -289,14 +289,12 @@ line directly before or after the table."
 	(setf params (plist-put params (car pair) (cdr pair)
 ;; collect table and table information
 (let* ((data-file (make-temp-file "org-plot"))
-	   (table (org-table-to-lisp))
-	   (num-cols (length (if (eq (nth 0 table) 'hline) (nth 1 table)
-			   (nth 0 table)
+	   (table (org-table-collapse-header (org-table-to-lisp)))
+	   (num-cols (length (car table
   (run-with-idle-timer 0.1 nil #'delete-file data-file)
-  (while (eq 'hline (car table)) (setf table (cdr table)))
   (when (eq (cadr table) 'hline)
 	(setf params
-	  (plist-put params :labels (nth 0 table))) ; headers to labels
+	  (plist-put params :labels (car table))) ; headers to labels
 	(setf table (delq 'hline (cdr table ; clean non-data from table
   ;; Collect options.
   (save-excursion (while (and (equal 0 (forward-line -1))
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 6462b99c4..248b1ed50 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -5458,6 +5458,31 @@ The table is taken from the parameter TXT, or from the buffer at point."
 	  (forward-line))
 (nreverse table)
 
+(defun org-table-collapse-header (table  separator max-header-lines)
+  "Collapse the lines before 'hline into a single header.
+
+The given TABLE is a list of lists as returned by `org-table-to-lisp'.
+The leading lines before the first `hline' symbol are considered
+forming the table header.  This function collapses all leading header
+lines into a single header line, followed by the `hline' symbol, and
+the rest of the TABLE.  Header cells are glued together with a space,
+or the given SEPARATOR."
+  (while (eq (car table) 'hline) (pop table))
+  (let* ((separator (or separator " "))
+	 (max-header-lines (or max-header-lines 4))
+	 (trailer table)
+	 (header-lines (cl-loop for line in table
+until (eq 'hline line)
+collect (pop trailer
+(if (and trailer (<= (length header-lines) max-header-lines))
+	(cons (apply #'mapcar
+		 (lambda ( x)
+		   (org-trim
+			(mapconcat #'identity x separator)))
+		 header-lines)
+	  trailer)
+  table)))
+
 (defun orgtbl-send-table ( maybe)
   "Send a transformed version of table at point to the receiver position.
 With 

[patch] simplify-compact initial data extraction from plist

2020-06-27 Thread Mario Frasca
this is a result of some help I received a few days ago in the #emacs 
irc chat room on freenode.


I was wondering why we were adding a semicolon in front of names, before 
creating symbols, and I understand this is because such symbols work as 
keys.  next, I could not find how we were taking advantage of this in 
the code, asked further, looked for references and examples, and 
discovered how to use `cl-destructuring-bind' to define something 
looking and behaving like a `let' block, based on the content of a plist.


hope this helps.

I have signed my FSF papers, and received confirmation of reception.

ciao,

Mario

>From 00e2bc506085b0a0343237810b63b7f213aeb67e Mon Sep 17 00:00:00 2001
From: mfrasca 
Date: Sat, 27 Jun 2020 09:58:45 -0500
Subject: [PATCH] cl-destructuring-bind simplifies initial repeating let block

* lisp/org-table.el (org-table--to-generic-row): introduce
`cl-destructuring-bind', simplifying leading `let'.
(org-table--to-generic-cell): introduce `cl-destructuring-bind',
simplifying leading `let'.

* lisp/org-list.el (org-list--to-generic-plain-list): introduce
`cl-destructuring-bind', simplifying leading `let'.
(org-list--to-generic-item): introduce `cl-destructuring-bind',
simplifying leading `let'.

These two files use a leading `let' block to extract keywords from a
plist.  This sequence of uniform invocations of `plist-get-params' can
be done more compactly with `cl-destructuring-bind', without repeating
names, without risking confusing name changes in the process (that's
the case in `org-plot.el'), evidentiating the uniformity of the
procedure.
---
 lisp/org-list.el  |  30 ++--
 lisp/org-plot.el  | 340 +-
 lisp/org-table.el |  28 ++--
 3 files changed, 204 insertions(+), 194 deletions(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 7a5133dbe..6a353e726 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -3388,14 +3388,10 @@ it is called with arguments ARGS."
 (defun org-list--to-generic-plain-list (params)
   "Return a transcoder for `plain-list' elements.
 PARAMS is a plist used to tweak the behavior of the transcoder."
-  (let ((ustart (plist-get params :ustart))
-	(uend (plist-get params :uend))
-	(ostart (plist-get params :ostart))
-	(oend (plist-get params :oend))
-	(dstart (plist-get params :dstart))
-	(dend (plist-get params :dend))
-	(splice (plist-get params :splice))
-	(backend (plist-get params :backend)))
+  (cl-destructuring-bind
+  ( ustart uend ostart oend dstart dend splice backend
+	)
+  params
 (lambda (plain-list contents info)
   (let* ((type (org-element-property :type plain-list))
 	 (depth (org-list--depth plain-list))
@@ -3428,19 +3424,11 @@ PARAMS is a plist used to tweak the behavior of the transcoder."
 (defun org-list--to-generic-item (params)
   "Return a transcoder for `item' elements.
 PARAMS is a plist used to tweak the behavior of the transcoder."
-  (let ((backend (plist-get params :backend))
-	(istart (plist-get params :istart))
-	(iend (plist-get params :iend))
-	(isep (plist-get params :isep))
-	(icount (plist-get params :icount))
-	(ifmt (plist-get params :ifmt))
-	(cboff (plist-get params :cboff))
-	(cbon  (plist-get params :cbon))
-	(cbtrans (plist-get params :cbtrans))
-	(dtstart (plist-get params :dtstart))
-	(dtend (plist-get params :dtend))
-	(ddstart (plist-get params :ddstart))
-	(ddend (plist-get params :ddend)))
+  (cl-destructuring-bind
+  ( backend istart iend isep icount ifmt cboff
+	cbon cbtrans dtstart dtend ddstart ddend
+	)
+  params
 (lambda (item contents info)
   (let* ((type
 	  (org-element-property :type (org-element-property :parent item)))
diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..790621e69 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -34,6 +34,19 @@
 (require 'org)
 (require 'org-table)
 
+(defmacro let-plist (plist  body)
+  (declare (indent 1))
+  (let ((syms (make-symbol "syms"))
+(vals (make-symbol "vals"))
+(list (make-symbol "list")))
+`(let ((,list ,plist)
+   ,syms ,vals)
+   (while ,list
+ (push (intern (substring (symbol-name (pop ,list)) 1)) ,syms)
+ (push (pop ,list) ,vals))
+   (cl-progv ,syms ,vals
+ ,@body
+
 (declare-function gnuplot-delchar-or-maybe-eof "ext:gnuplot" (arg))
 (declare-function gnuplot-mode "ext:gnuplot" ())
 (declare-function gnuplot-send-buffer-to-gnuplot "ext:gnuplot" ())
@@ -46,60 +59,70 @@
 
 (defvar org-plot-timestamp-fmt nil)
 
-(defun org-plot/add-options-to-plist (p options)
-  "Parse an OPTIONS line and set values in the property list P.
-Returns the resulting property list."
-  (when options
-(let ((op '(("type". :plot-type)
-		("script"  . :script)
-		("line". :line)
-		("set" . :set)
-		("title"   . :title)
-		("ind" . :ind)
-		("deps". :deps)
-		("with". :with)
-		("file". :file)
-		("labels"  . :labels)
-		("map" . :map)
-		

Re: Babel: parse error when output contains opening bracket

2020-06-27 Thread ian martins
On Sat, Jun 27, 2020 at 1:25 AM Jarmo Hurri  wrote:

> ian martins  writes:
>
> Hello.
>
> > I've written an alternative org-java.el that doesn't have that
> > problem. I wanted to add it to contrib/ but haven't been able to get
> > access. if you want to try it I can post it somewhere.
>
> Sounds excellent.
>
> Would it be possible for us to fix the current version without
> introducing a new one? Can you identify the parts of your code that fix
> the issue?
>
The existing code creates the java program and runs it correctly, but it
uses `org-babel-import-elisp-from-file' to interpret the results, and that
sees the bracket and tries to make the response into a list, and errors
when it can't. I don't see a quick fix for it. If you allow unbalanced
brackets but that would be a change in ob-core and would probably cause
unwanted results in other places. If you don't try to convert the output
into a list, you can't present java results as lists or tables.  Really the
problem is that ob-java doesn't support functional mode, so it tries to
guess if scripting mode output should be a table or list.  The version I
wrote supports functional and scripting modes and doesn't use
`org-babel-import-elisp-from-file'.


>
> I am already a contributor, so if you can post your solution here I can
> create a patch and give you the credit.
>
I would really appreciate that if you are willing, but it's a significant
change (code is 400 lines, 600 lines of tests and test data) and there
might be iterations so you might be signing up for more than you realize.


>
> How does that sound?
>
> Jarmo
>
>
>