Re: WIP: Org-plot work

2020-09-07 Thread Mario Frasca
Hi all. Temporarily with hardly any connection. I dropped attempting to have my patches accepted after a couple of RFCs were met with silence. My understanding is that org-plot is abandoned, in favour of babel blocks, and I have too little interest in learning that. I possibly created a personal fork on gitlab, my user name is mariotomo.Sent from a Google-owned 华为 Mobile Original Message Subject: Re: WIP: Org-plot workFrom: TEC To: Bastien CC: org-mode-email ,Mario Frasca ,Eric Schulte Bastien  writes:> Sure, please go ahead.Will do! :)> Great -- because I know Mario shared a lot of proposals, many of which> where probably ignored or dismissed because the patches did not follow> our conventions closely enough (despite his notable efforts).>> It is of foremost importance that we stick to these conventions: they> help reduce the burden of Org maintainance.  But it is a pity that we> lose contributions because contributors cannot follow them and find it> difficult to do so.>> So, be free to both cooperate on making org-plot.el more useful!Thanks. I suspect my work will need reworking to fit, but as long aspeople are willing to point out what needs changing, I'm willing to takea look at it :D> Also, org-plot.el would do better with a maintainer - would you like> to step in?Simply on the basis that I'm actively interested in the functionality -I'd be happy to sign up for this. As long as you don't mind someone abit green being assigned (I'm yet to use Emacs for a whole year, but Idon't see myself stopping any time soon!).All the best,Timothy.

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

2020-07-12 Thread Mario Frasca

Anyone?



 Forwarded Message 
Subject:[patch] simplify-compact initial data extraction from plist
Date:   Sat, 27 Jun 2020 10:18:21 -0500
From:   Mario Frasca 
To: emacs-orgmode@gnu.org



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 th

Re: empty/nil in table cells

2020-07-10 Thread Mario Frasca

On 09/07/2020 16:59, Nicolas Goaziou wrote:

and it simplifies a lot writing functions.

How so?


thank you Michael, for answering Nicolas' question, in a different and 
much structured way than I did in my original message.


the formula you provided —I reduced it slightly, hard coding a constant— 
looks like this:


(if (> @# 4) (format "%.2f" (/ (apply '+ (subseq '(@I$2..@II$2) (- @# 1 
4) (- @# 1))) 4.0)) ""));N


my impression is this programs in the spreadsheet something that should 
be part of the org-table software.


if we let references leading outside the table return 'nil instead of 
raising an error, and represent 'nil by the empty string, then this is 
enough:


(when (> @# 4) (/ (+ @-3$2..$2) 4.0));L%0.2f

my suggestion is to associate 'nil with empty cells "both ways", in the 
sense that a formula returning 'nil causes an empty org-table cell (see 
above), and that the empty cell, through the L filter evaluates to nil 
and not to the empty string.  this for symmetry, and for uniformity with 
reference leading outside the table.


regards,

MF



Re: empty/nil in table cells

2020-07-09 Thread Mario Frasca

I think we really need a bug-tracking mechanism, you know?

see attachment

On 09/07/2020 16:59, Nicolas Goaziou wrote:

Hello,

Mario Frasca  writes:


I've been experimenting with associating the empty cell with the value
nil,

Where?


both ways,

What do you mean?


and it simplifies a lot writing functions.

How so?


also, I've removed the error generation when reading from outside the
table (instead of giving up with a user-error, I now get a nil).

Would you mind explaining?


it works for me, and I don't see counterindications.  is it
worthwhile, offering you the patch?

Thank you. It may be so, but I may be missing some context.

Regards,
--- Begin Message ---
sorry for the messed up setting of the table, trying again, and adding a 
web-paste


http://ix.io/2qMC

|  date | measure | running avg |
|---+-+-|
| 01-27 | 604 | |
| 01-28 | 314 | |
| 01-29 | 636 | |
| 01-30 | 305 | |
| 01-31 | 760 | |
| 02-01 | 531 | |
| 02-02 | 331 |  497.29 |
| 02-03 |  77 |  422.00 |
| 02-04 | 621 |  465.86 |
| 02-05 | 406 |  433.00 |
| 02-06 | 621 |  478.14 |
| 02-07 | 975 |  508.86 |
| 02-08 | 252 |  469.00 |
| 02-09 | 794 |  535.14 |
| 02-10 |  36 |  529.29 |
#+TBLFM: $3='(unless (> @# 7) "skipped")
#+TBLFM: $3='(when (> @# 7) (/ (apply #'+ '(@-6$2..$2)) 7.0));N%0.2f
#+TBLFM: $3='(/ (apply #'+ '(@-6$2..$2)) 
7.0);N%0.2f::@2$3='(string)::@3$3='(string)::@4$3='(string)::@5$3='(string)::@6$3='(string)::@7$3='(string)

On 03/07/2020 09:53, Mario Frasca wrote:

hi again,

I haven't found how to solve this, short of removing the evaluation of 
`user-error' from the org-table.el code, or stuffing my TBLFM line 
with field formulas.


a very simple use case: three columns: the date, a daily measurement, 
and a running 4-days average.


|  date | measure | running avg ||---+-+-|| 
01-27 | 604 | skipped || 01-28 | 314 | skipped || 01-29 
| 636 | skipped || 01-30 | 305 | skipped || 01-31 | 
760 | skipped || 02-01 | 531 | skipped || 02-02 | 331 | 
nil || 02-03 |  77 | nil || 02-04 | 621 | nil || 02-05 
| 406 | nil || 02-06 | 621 | nil || 02-07 | 975 | 
nil || 02-08 | 252 | nil || 02-09 | 794 | nil 
|| 02-10 |  36 | nil |#+TBLFM: $3='(unless (> @# 7) "skipped") 
#+TBLFM: $3='(when (> @# 7) (/ (apply #'+ '(@-6$2..$2)) 7.0));N%0.2f 
#+TBLFM: $3='(/ (apply #'+ '(@-6$2..$2)) 
7.0);N%0.2f::@2$3='(string)::@3$3='(string)::@4$3='(string)::@5$3='(string)::@6$3='(string)::@7$3='(string)


the first TBLFM shows you which cells I'm skipping, that is, where I'm 
not applying the @-6 reference.  the status of the table results from 
evaluation of that TBLFM line.


the second TBLFM line skips all @-6 references, but still fails with 
the message


user-error: Row descriptor -6 leads outside table

the third TBLFM line "solves" the problem, in one of the ugliestests 
ways.


how would you people approach this?


On 29/06/2020 12:03, Mario Frasca wrote:

Hi,

I need some help understanding how to use org-mode/org-table for 
references leading outside my table.


I have a series of daily figures, and I am computing the series of 
running sums.  column one is the daily data, column two is the 
running sum of the preceding 14 values from column 1.


http://ix.io/2qu7

problem is the @-13$1 reference in the function for the second 
column: it hits a software-generated "user-error: Row descriptor -13 
leads outside table".


this happens even if the formula says (if (> @# 13) (apply '+ 
'(@-13$1..$1)) 0), that is, even if the formula is not evaluated on 
the cells where the reference does indeed lead out of the table.


this happens around line 2809 of org-table.el, inside 
org-table--row-type


I've tried to catch the user-error with a `condition-case', but even 
there, the error seems to happen before evaluation.


I've replaced the `(user-error)' function with a `nil', and it works 
for me, but that's a very rough measure I'm afraid.


--- End Message ---


empty/nil in table cells

2020-07-09 Thread Mario Frasca

Hi people,

I've been experimenting with associating the empty cell with the value 
nil, both ways, and it simplifies a lot writing functions. also, I've 
removed the error generation when reading from outside the table 
(instead of giving up with a user-error, I now get a nil).


it works for me, and I don't see counterindications.  is it worthwhile, 
offering you the patch?


MF




Re: [PATCH] allow for multiline headers

2020-07-04 Thread Mario Frasca

Hi Nicolas,

On 04/07/2020 03:58, Nicolas Goaziou wrote:

I'm sure this PLOT extension is useful.

My point is that complexity should be moved to Org Babel, if possible,
not into affiliated keywords. IOW, it would be nice if gnuplot source
code blocks were as easy to use as your extension.


I do not use org-babel, and I do not plan to move to it.  I'm happy with 
my extension, but I do see that there's no positive reaction from users, 
only the group of reviewers who doesn't like the idea.  as said, let's 
just keep it this way.




It already might be as simple, or there may be some work to do. I'd
appreciate some enlightenment on the topic. For example, could you show
what code your extension generates with the table above?


your above request suggests me you're missing the point.  there is 
nothing to be seen in the generated gnuplot source, because all is 
solved in lisp.  or it's me missing your point, that can be, too.


anyhow, these are a couple of webpastes for you:

this is the complete gnuplot session, showing the code produced with 
`use:1' and then with `use:2', given the table I already shared.


http://ix.io/2qRq

what will show you the logic is the lisp code, which I thought I already 
shared, but I guess I did not insist up to the latest version.  anyhow, 
here are a couple of snippets, partial or complete rewrites of 
org-plot.el code.


http://ix.io/2qRs/elisp

http://ix.io/2qRt/elisp

http://ix.io/2qRu

best regards,

MF





Re: bug: Row descriptor <...> leads outside table

2020-07-03 Thread Mario Frasca
sorry for the messed up setting of the table, trying again, and adding a 
web-paste


http://ix.io/2qMC

|  date | measure | running avg |
|---+-+-|
| 01-27 | 604 | |
| 01-28 | 314 | |
| 01-29 | 636 | |
| 01-30 | 305 | |
| 01-31 | 760 | |
| 02-01 | 531 | |
| 02-02 | 331 |  497.29 |
| 02-03 |  77 |  422.00 |
| 02-04 | 621 |  465.86 |
| 02-05 | 406 |  433.00 |
| 02-06 | 621 |  478.14 |
| 02-07 | 975 |  508.86 |
| 02-08 | 252 |  469.00 |
| 02-09 | 794 |  535.14 |
| 02-10 |  36 |  529.29 |
#+TBLFM: $3='(unless (> @# 7) "skipped")
#+TBLFM: $3='(when (> @# 7) (/ (apply #'+ '(@-6$2..$2)) 7.0));N%0.2f
#+TBLFM: $3='(/ (apply #'+ '(@-6$2..$2)) 
7.0);N%0.2f::@2$3='(string)::@3$3='(string)::@4$3='(string)::@5$3='(string)::@6$3='(string)::@7$3='(string)

On 03/07/2020 09:53, Mario Frasca wrote:

hi again,

I haven't found how to solve this, short of removing the evaluation of 
`user-error' from the org-table.el code, or stuffing my TBLFM line 
with field formulas.


a very simple use case: three columns: the date, a daily measurement, 
and a running 4-days average.


|  date | measure | running avg ||---+-+-|| 
01-27 | 604 | skipped || 01-28 | 314 | skipped || 01-29 
| 636 | skipped || 01-30 | 305 | skipped || 01-31 | 
760 | skipped || 02-01 | 531 | skipped || 02-02 | 331 | 
nil || 02-03 |  77 | nil || 02-04 | 621 | nil || 02-05 
| 406 | nil || 02-06 | 621 | nil || 02-07 | 975 | 
nil || 02-08 | 252 | nil || 02-09 | 794 | nil 
|| 02-10 |  36 | nil |#+TBLFM: $3='(unless (> @# 7) "skipped") 
#+TBLFM: $3='(when (> @# 7) (/ (apply #'+ '(@-6$2..$2)) 7.0));N%0.2f 
#+TBLFM: $3='(/ (apply #'+ '(@-6$2..$2)) 
7.0);N%0.2f::@2$3='(string)::@3$3='(string)::@4$3='(string)::@5$3='(string)::@6$3='(string)::@7$3='(string)


the first TBLFM shows you which cells I'm skipping, that is, where I'm 
not applying the @-6 reference.  the status of the table results from 
evaluation of that TBLFM line.


the second TBLFM line skips all @-6 references, but still fails with 
the message


user-error: Row descriptor -6 leads outside table

the third TBLFM line "solves" the problem, in one of the ugliestests 
ways.


how would you people approach this?


On 29/06/2020 12:03, Mario Frasca wrote:

Hi,

I need some help understanding how to use org-mode/org-table for 
references leading outside my table.


I have a series of daily figures, and I am computing the series of 
running sums.  column one is the daily data, column two is the 
running sum of the preceding 14 values from column 1.


http://ix.io/2qu7

problem is the @-13$1 reference in the function for the second 
column: it hits a software-generated "user-error: Row descriptor -13 
leads outside table".


this happens even if the formula says (if (> @# 13) (apply '+ 
'(@-13$1..$1)) 0), that is, even if the formula is not evaluated on 
the cells where the reference does indeed lead out of the table.


this happens around line 2809 of org-table.el, inside 
org-table--row-type


I've tried to catch the user-error with a `condition-case', but even 
there, the error seems to happen before evaluation.


I've replaced the `(user-error)' function with a `nil', and it works 
for me, but that's a very rough measure I'm afraid.




bug: Row descriptor <...> leads outside table

2020-07-03 Thread Mario Frasca

hi again,

I haven't found how to solve this, short of removing the evaluation of 
`user-error' from the org-table.el code, or stuffing my TBLFM line with 
field formulas.


a very simple use case: three columns: the date, a daily measurement, 
and a running 4-days average.


|  date | measure | running avg ||---+-+-|| 
01-27 | 604 | skipped || 01-28 | 314 | skipped || 01-29 
| 636 | skipped || 01-30 | 305 | skipped || 01-31 | 
760 | skipped || 02-01 | 531 | skipped || 02-02 | 331 | 
nil || 02-03 |  77 | nil || 02-04 | 621 | 
nil || 02-05 | 406 | nil || 02-06 | 621 | 
nil || 02-07 | 975 | nil || 02-08 | 252 | 
nil || 02-09 | 794 | nil || 02-10 |  36 | 
nil |#+TBLFM: $3='(unless (> @# 7) "skipped") #+TBLFM: $3='(when 
(> @# 7) (/ (apply #'+ '(@-6$2..$2)) 7.0));N%0.2f #+TBLFM: $3='(/ (apply 
#'+ '(@-6$2..$2)) 
7.0);N%0.2f::@2$3='(string)::@3$3='(string)::@4$3='(string)::@5$3='(string)::@6$3='(string)::@7$3='(string)


the first TBLFM shows you which cells I'm skipping, that is, where I'm 
not applying the @-6 reference.  the status of the table results from 
evaluation of that TBLFM line.


the second TBLFM line skips all @-6 references, but still fails with the 
message


user-error: Row descriptor -6 leads outside table

the third TBLFM line "solves" the problem, in one of the ugliestests ways.

how would you people approach this?


On 29/06/2020 12:03, Mario Frasca wrote:

Hi,

I need some help understanding how to use org-mode/org-table for 
references leading outside my table.


I have a series of daily figures, and I am computing the series of 
running sums.  column one is the daily data, column two is the running 
sum of the preceding 14 values from column 1.


http://ix.io/2qu7

problem is the @-13$1 reference in the function for the second column: 
it hits a software-generated "user-error: Row descriptor -13 leads 
outside table".


this happens even if the formula says (if (> @# 13) (apply '+ 
'(@-13$1..$1)) 0), that is, even if the formula is not evaluated on 
the cells where the reference does indeed lead out of the table.


this happens around line 2809 of org-table.el, inside org-table--row-type

I've tried to catch the user-error with a `condition-case', but even 
there, the error seems to happen before evaluation.


I've replaced the `(user-error)' function with a `nil', and it works 
for me, but that's a very rough measure I'm afraid.






Re: [PATCH] allow for multiline headers

2020-07-01 Thread Mario Frasca

Good morning Nicolas,

On 01/07/2020 05:46, Nicolas Goaziou wrote:

There are multiple ways to draw a diagram from a table. […]

I didn't check but I think Org Plot predates Org Babel. It probably
wouldn't exist otherwise.


I'm happy it exists.  it has a very low entrance threshold, just use it 
and tweak it bit by bit.  the other methods, apart from gnuplot itself, 
are out of reach on my system, a Maemo-freemantle N900.  it's not my 
original system, just a recent replacement, and I had some trouble to 
find all software I was used to.




I don't know if there's much difference between writing multiple PLOT
lines and writing a gnuplot script. It may be interesting to compare use
cases.


it's data about the pandemic that I'm collecting, http://ix.io/2qDf.  as 
said, I have never used ob-gnuplot, so I would not know how would the 
equivalent code look like.


I wanted to comment out a couple of lines, then switch them back again, 
and it was easier to do it with the new `use´ keyword.


regards, MF




Re: [PATCH] allow for multiline headers

2020-06-29 Thread Mario Frasca

On 29/06/2020 13:36, Nicolas Goaziou wrote:

IMO, Org Plot should be very basic, and complexity
should go into Babel code blocks, which are more capable.


IMO, we are keeping org-plot artificially basic.  But you know what?  
I'm just happy with my additions, my point was to share them with the 
wider public.  I can also keep my own branch in my own repository.  I'm 
fine either way.  When solving conflicts will become a burden, I'll 
write again to the list.


I haven't yet delved into Babel code blocks.  I would need to write 
code, isn't it?  Now I just need defining settings.  … sounds easier, so 
I'll keep it this way, here on my PC at least.


anyhow, cheers, Mario.




question on user-error reference leading out of table

2020-06-29 Thread Mario Frasca

Hi,

I need some help understanding how to use org-mode/org-table for 
references leading outside my table.


I have a series of daily figures, and I am computing the series of 
running sums.  column one is the daily data, column two is the running 
sum of the preceding 14 values from column 1.


http://ix.io/2qu7

problem is the @-13$1 reference in the function for the second column: 
it hits a software-generated "user-error: Row descriptor -13 leads 
outside table".


this happens even if the formula says (if (> @# 13) (apply '+ 
'(@-13$1..$1)) 0), that is, even if the formula is not evaluated on the 
cells where the reference does indeed lead out of the table.


this happens around line 2809 of org-table.el, inside org-table--row-type

I've tried to catch the user-error with a `condition-case', but even 
there, the error seems to happen before evaluation.


I've replaced the `(user-error)' function with a `nil', and it works for 
me, but that's a very rough measure I'm afraid.





Re: [PATCH] allow for multiline headers

2020-06-29 Thread Mario Frasca

Hi Nicolas,

sorry for not explaining it clearly.  see, I'm considering from the 
point of view of a user, who organizes a table in terms of logical 
units, like a header, one or more body blocks, and a summary line.  
these concepts are not yet all supported by the org-table code, and 
again, I'm not considering what the code implements, just looking at the 
table from the user's point of view.


again, my idea is that we're describing something new, and I'm wondering 
what lisp construct could be used to describe a table like this one:


| h1 | h2 | h3 |
|++|
| 11 | 12 | 13 |
| 21 | 22 | 23 |
| 31 | 32 | 33 |
|++|
| a1 | a2 | a3 |
| b1 | b2 | b3 |
|++|
|  5 |  8 |  9 |

and my guess in the above case would be '(:header ("h1" "h2" "h3") :body 
((11 12 13)(21 22 23)(31 32 33)) :body ((a1 a2 a3)(b1 b2 b3)) :body ((5 
8 9)))


with a option for collapsing all :body parts into one, like in '(:header 
("h1" "h2" "h3") :body ((11 12 13)(21 22 23)(31 32 33)(a1 a2 a3)(b1 b2 
b3)(5 8 9)))


with a option for separating the last row (if the one-but-last is a 
'hline) as a summary, like in '(:header ("h1" "h2" "h3") :body ((11 12 
13)(21 22 23)(31 32 33)) :body ((a1 a2 a3)(b1 b2 b3)) :summary (5 8 9))


or using both options, like in '(:header ("h1" "h2" "h3") :body ((11 12 
13)(21 22 23)(31 32 33)(a1 a2 a3)(b1 b2 b3)) :summary (5 8 9))


your suggestion as a cons cell would only cover the first case, as in 
'(("h1" "h2" "h3") . ((11 12 13)(21 22 23)(31 32 33)(a1 a2 a3)(b1 b2 
b3)(5 8 9)))


in my very brief experience with org-tables, mostly from the point of 
view of org-plot, I think this (separating the bottom "summary" line) 
would be useful (I had to remove the "country summary" bottom line from 
a demographics histogram table).  for sure, if I follow your hint to use 
gnuplot code and refer to the table, then org-plot can stay as it is 
now.  in fact it would not need any maintenance, would it?


cheers,

Mario

On 29/06/2020 07:50, Nicolas Goaziou wrote:

Hello,

Mario Frasca  writes:


not only this … it could also be like (:header HEADER :body BODY :body
BODY), that is, repeating block.

I'm not sure about what you mean.


I don't know, just doubting how to be more general.

in practice, I'm thinking of the case when I have a header, a body,
and a summary, and I'm only interested in the header and body, not the
summary.

just scattered thoughts … who fills in?

There is no such thing as a "table summary" in Org syntax.

Regards,




Re: [PATCH] allow for multiline headers

2020-06-28 Thread Mario Frasca

On 28/06/2020 18:17, 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).


not only this … it could also be like (:header HEADER :body BODY :body 
BODY), that is, repeating block.


I don't know, just doubting how to be more general.

in practice, I'm thinking of the case when I have a header, a body, and 
a summary, and I'm only interested in the header and body, not the summary.


just scattered thoughts … who fills in?




[PATCH] partial rewrite of gnuplot-to-grid-data

2020-06-28 Thread Mario Frasca
according to me, this looks better, I'm curious about the reactions from 
the list.


in particular, I was surprised finding a duplicated evaluation of 
(string-to-number (nth col (nth row table))) inside a (dotimes (col 
num-cols) (dotimes (row num-rows) …))



>From 9822748dfbdb99f1ea534e695e818d7533920a61 Mon Sep 17 00:00:00 2001
From: mfrasca 
Date: Sun, 28 Jun 2020 16:24:54 -0500
Subject: [PATCH] org-plot/gnuplot-to-grid-data: code review for speed and
 readability

* lisp/org-plot.el (org-plot/gnuplot-to-grid-data): partial rewrite.

Optimizing for speed and readability: preprocessing data in order to
simplify removal on non-plotting columns; using available functions
like set-difference and org-remove-by-index; loop over elements
instead of counting indices and invoking `nth' (in a double loop).
---
 lisp/org-plot.el | 81 +---
 1 file changed, 36 insertions(+), 45 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index bf81d3c37..38749c069 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -130,53 +130,44 @@ Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE."
 (defun org-plot/gnuplot-to-grid-data (table data-file params)
   "Export the data in TABLE to DATA-FILE for gnuplot.
 This means in a format appropriate for grid plotting by gnuplot.
-PARAMS specifies which columns of TABLE should be plotted as independent
-and dependent variables."
-  (interactive)
-  (let* ((ind (- (plist-get params :ind) 1))
-	 (deps (if (plist-member params :deps)
-		   (mapcar (lambda (val) (- val 1)) (plist-get params :deps))
-		 (let (collector)
-		   (dotimes (col (length (nth 0 table)))
-		 (setf collector (cons col collector)))
-		   collector)))
-	 (counter 0)
-	 row-vals)
-(when (>= ind 0) ;; collect values of ind col
-  (setf row-vals (mapcar (lambda (row) (setf counter (+ 1 counter))
-			   (cons counter (nth ind row)))
-			 table)))
-(when (or deps (>= ind 0)) ;; remove non-plotting columns
-  (setf deps (delq ind deps))
-  (setf table (mapcar (lambda (row)
-			(dotimes (col (length row))
-			  (unless (memq col deps)
-(setf (nth col row) nil)))
-			(delq nil row))
-			  table)))
+PARAMS specifies which columns of TABLE should be plotted as
+independent and dependent variables.  Return the ind-column, as
+list of (cons 0-based-row-num . cell-value)."
+  (let* ((last-col (1- (length (car table
+ (ind (1- (plist-get params :ind)))
+ (deps (delq ind (if (plist-member params :deps)
+ (mapcar #'1- (plist-get params :deps))
+   (number-sequence 0 last-col
+ (skip-deps (set-difference
+ (number-sequence 0 last-col)
+ deps))
+ (row-vals ; the return value - indexed values from the ind column
+  (unless (< ind 0)
+(let ((i -1)) (mapcar (lambda (row)
+(incf i)
+(cons i (nth ind row)))
+  table)
+;; remove non-plotting columns
+(setq table (mapcar (lambda (row) 
+  (org-remove-by-index row skip-deps))
+table))
 ;; write table to gnuplot grid datafile format
 (with-temp-file data-file
-  (let ((num-rows (length table)) (num-cols (length (nth 0 table)))
-	(gnuplot-row (lambda (col row value)
-			   (setf col (+ 1 col)) (setf row (+ 1 row))
-			   (format "%f  %f  %f\n%f  %f  %f\n"
-   col (- row 0.5) value ;; lower edge
-   col (+ row 0.5) value))) ;; upper edge
-	front-edge back-edge)
-	(dotimes (col num-cols)
-	  (dotimes (row num-rows)
-	(setf back-edge
-		  (concat back-edge
-			  (funcall gnuplot-row (- col 1) row
-   (string-to-number (nth col (nth row table))
-	(setf front-edge
-		  (concat front-edge
-			  (funcall gnuplot-row col row
-   (string-to-number (nth col (nth row table)))
-	  ;; only insert once per row
-	  (insert back-edge) (insert "\n") ;; back edge
-	  (insert front-edge) (insert "\n") ;; front edge
-	  (setf back-edge "") (setf front-edge ""
+  (let ((gnuplot-row (lambda (c r value)
+   (format "%f  %f  %s\n%f  %f  %s\n"
+   c (+ r 0.5) value
+   c (+ r 1.5) value
+(dotimes (c (length (car table)))
+  (let ((column (mapcar (lambda (row) (nth c row)) table))
+(r 0)
+front-edge back-edge)
+(dolist (cell column)
+  (setq back-edge (concat back-edge
+  (funcall gnuplot-row c r cell)))
+  (setq front-edge (concat front-edge
+   (funcall gnuplot-row (1+ c) r cell)))
+  (incf r))
+(insert (concat back-edge "\n" front-edge "\n"))
 row-vals))
 

Re: [bug] select TODO items and unexpected behaviour

2020-06-28 Thread Mario Frasca

On 28/06/2020 01:32, Kyle Meyer wrote:

Thanks for reporting. Looks like org-todo's call to org-map-entries has
been broken since its introduction in 7.8.05.  Should be fixed with
8a2eb7d1b.


3ed035ce3

with this patch, you don't need to locally redefine the 
org-loop-over-headlines-in-active-region variable, do you?





Re: [bug] select TODO items and unexpected behaviour

2020-06-28 Thread Mario Frasca
the "somehow", I can confirm it happened in the same session.  it was 
left like that when I ran toggle-debug-on-error and landed in the debugger.


I also noticed that the behaviour on the selection is only implemented 
for some actions, not all.


if you select items, then S- (to raise priority), the result is … 
difficult to describe, non-selected parts of the buffer disappear, I am 
asked about a Tag, for whatever reason, at this point I hit C-g, and the 
raise-priority is applied, but only on the line containing the point.


went looking in the code for these functions, and the leading test, 
recursively implementing the action on the selected lines, I only saw it 
repeated with variations in a couple such functions. as said, 
org-priority does not have it.  I think the block could better be 
generalized, my guess is by defining a well suited macro.


regards, MF

On 28/06/2020 01:32, Kyle Meyer wrote:

Mario Frasca writes:


this behaviour comes after somehow my
`org-loop-over-headlines-in-active-region' became nil.

Perhaps not the "somehow" but the default value of this option is
different between the last release and master.  It changed from nil to t
in e360cd8f3 (Change the default values for several options,
2020-02-21).


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

Thanks for reporting.  Looks like org-todo's call to org-map-entries has
been broken since its introduction in 7.8.05.  Should be fixed with
8a2eb7d1b.




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] 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: [PATCH] may we focus on readability?

2020-06-16 Thread Mario Frasca

On 16/06/2020 11:56, Nicolas Goaziou wrote:

what about waiting until bureaucracy
is over?


I'm fine with it, but I'm accumulating several adjustments, and it's 
being difficult to keep track of each of them separately.



Of course, this assumes you're planning to sign FSF papers.

I have signed and sent them in, 5th of June.

like … I'm adding a way to collect #+PLOT lines depending on which set 
of settings I want, to produce the graph.


#+PLOT[1]: set:"yrange [0:4200]"
#+PLOT[1]: set:"key at 33,4100 top left spacing 1.4"
#+PLOT[1]: set:"arrow from 59.5,0 rto 0,4200 nohead ls 1"
#+PLOT[2]: set:"yrange [50:1]" set:"logscale y 10"
#+PLOT[2]: set:"key at 35,9000 top left spacing 1.4"
#+plot[2]: set:"arrow from 59.5,50 rto 0,200 nohead ls 1"
#+PLOT: set:"xtics rotate by 90" set:"mouse mouseformat ' '"
#+PLOT: ind:1 deps:(6 3 7 4 10) xticdep:15
#+plot: use:2
|  n |  data | prove, |  casi, | ratio |   prove, |    casi, | 7run | 
casi*6 |  casi, | cum-p | cum-c | cum-r |   ++% | lunes |
|    |   | valore | valore |   |    media |    media |  
|    | m.c.*5 |   |   |   |   | |


the #+plot: use:2 tells the program to collect PLOT[2] lines and to skip 
plot[1] definitions.


it needs be the first one met by the program, or at least precede any 
such lines.


oh, and the xticdep is an other addition

both I haven't shared yet, because it's a bit complicated doing so while 
the code doesn't contain the previous changes.


ciao, Mario




Re: [PATCH] may we focus on readability?

2020-06-15 Thread Mario Frasca

second thought about testing:

if I did that, it would become longer than 15 lines, I would need 
refactoring quite a bit of stuff, and both things would require time, 
bureaucratic time, and programming time.


I had a closer look at my changes, re-read it, and used it a bit, and I 
think this is o.k.


see it yourself, when we have the agreement allowing you accept changes 
longer than 15 lines, I'll consider the needed refactoring and test-writing.


ciao,

Mario

On 15/06/2020 09:49, Mario Frasca wrote:
Hi Nicolas, I think that the hint on testing is very correct, I'm 
afraid I changed the semantics of one of the original tests, and I 
found that there's other cl functions other than just cl-some, also 
cl-every, cl-notevery, and cl-notany.  I'll have a closer look at 
this.  and write some tests before changing the code.


I also looked for the strange idiom used here, and these two are the 
only two locations I found.


how do I run tests from the command line (I'm using make test) but 
then limited to one lisp file?  or one specific test?


ciao,

Mario

On 14/06/2020 14:32, Nicolas Goaziou wrote:

[…]
Also, further nit: (not (cl-every ...)) will apply `not' only once.

In any case, it would be better if refactoring happens while introducing
unit tests *hint*.

Regards,
>From 49f1cfbb80a3d5ffdbac4eea60bb3d45991c4423 Mon Sep 17 00:00:00 2001
From: mfrasca 
Date: Sun, 14 Jun 2020 10:52:41 -0500
Subject: [PATCH] lisp/org-plot.el: reducing complexity of test.

* lisp/org-plot.el (org-plot/gnuplot): readability of test, looking
for some non satisfying elements.

I'm rewriting a complicated construction where there's an equality
test on the length of the list of non matching elements, with a
simpler cl-some invocation.  The replacing code is self explanatory.
---
 lisp/org-plot.el | 34 ++
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..bf81d3c37 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -309,26 +309,20 @@ line directly before or after the table."
 	(`grid (let ((y-labels (org-plot/gnuplot-to-grid-data
 table data-file params)))
 		 (when y-labels (plist-put params :ylabels y-labels)
-  ;; Check for timestamp ind column.
-  (let ((ind (1- (plist-get params :ind
-	(when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))
-	  (if (= (length
-		  (delq 0 (mapcar
-			   (lambda (el)
-			 (if (string-match org-ts-regexp3 el) 0 1))
-			   (mapcar (lambda (row) (nth ind row)) table
-		 0)
-	  (plist-put params :timeind t)
-	;; Check for text ind column.
-	(if (or (string= (plist-get params :with) "hist")
-		(> (length
-			(delq 0 (mapcar
- (lambda (el)
-   (if (string-match org-table-number-regexp el)
-   0 1))
- (mapcar (lambda (row) (nth ind row)) table
-		   0))
-		(plist-put params :textind t)
+  ;; Check type of ind column (timestamp? text?)
+  (when (eq `2d (plist-get params :plot-type))
+	(let* ((ind (1- (plist-get params :ind)))
+	   (ind-column (mapcar (lambda (row) (nth ind row)) table)))
+	  (cond ((< ind 0) nil) ; ind is implicit
+		((cl-every (lambda (el)
+			 (string-match org-ts-regexp3 el))
+			   ind-column)
+		 (plist-put params :timeind t)) ; ind holds timestamps
+		((or (string= (plist-get params :with) "hist")
+		 (cl-notevery (lambda (el)
+(string-match org-table-number-regexp el))
+  ind-column))
+		 (plist-put params :textind t) ; ind holds text
   ;; Write script.
   (with-temp-buffer
 	(if (plist-get params :script)	; user script
-- 
2.20.1



Re: [PATCH] may we focus on readability?

2020-06-15 Thread Mario Frasca
Hi Nicolas, I think that the hint on testing is very correct, I'm afraid 
I changed the semantics of one of the original tests, and I found that 
there's other cl functions other than just cl-some, also cl-every, 
cl-notevery, and cl-notany.  I'll have a closer look at this.  and write 
some tests before changing the code.


I also looked for the strange idiom used here, and these two are the 
only two locations I found.


how do I run tests from the command line (I'm using make test) but then 
limited to one lisp file?  or one specific test?


ciao,

Mario

On 14/06/2020 14:32, Nicolas Goaziou wrote:

[…]
Also, further nit: (not (cl-every ...)) will apply `not' only once.

In any case, it would be better if refactoring happens while introducing
unit tests *hint*.

Regards,




[PATCH] may we focus on readability?

2020-06-14 Thread Mario Frasca

I'm rewriting a complicated construction where there's an equality
test on the length of the list of non matching elements, with a
simpler cl-some invocation.  The replacing code is self explanatory.

>From 918b0e7ba2db438cc9b81131317501b93a45b1d8 Mon Sep 17 00:00:00 2001
From: mfrasca 
Date: Sun, 14 Jun 2020 10:52:41 -0500
Subject: [PATCH] lisp/org-plot.el: reducing complexity of test.

* lisp/org-plot.el (org-plot/gnuplot): readability of test, looking
for some non satisfying elements.

I'm rewriting a complicated construction where there's an equality
test on the length of the list of non matching elements, with a
simpler cl-some invocation.  The replacing code is self explanatory.
---
 lisp/org-plot.el | 19 ++-
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..f50ad09a9 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -312,22 +312,15 @@ line directly before or after the table."
   ;; Check for timestamp ind column.
   (let ((ind (1- (plist-get params :ind
 	(when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))
-	  (if (= (length
-		  (delq 0 (mapcar
-			   (lambda (el)
-			 (if (string-match org-ts-regexp3 el) 0 1))
-			   (mapcar (lambda (row) (nth ind row)) table
-		 0)
+	  (if (cl-some (lambda (el)
+			 (not (string-match org-ts-regexp3 el)))
+		   (mapcar (lambda (row) (nth ind row)) table))
 	  (plist-put params :timeind t)
 	;; Check for text ind column.
 	(if (or (string= (plist-get params :with) "hist")
-		(> (length
-			(delq 0 (mapcar
- (lambda (el)
-   (if (string-match org-table-number-regexp el)
-   0 1))
- (mapcar (lambda (row) (nth ind row)) table
-		   0))
+		(cl-some (lambda (el)
+			   (not (string-match org-table-number-regexp el)))
+			 (mapcar (lambda (row) (nth ind row)) table
 		(plist-put params :textind t)
   ;; Write script.
   (with-temp-buffer
-- 
2.20.1



Re: [PATCH] allow for multiline headers

2020-06-13 Thread Mario Frasca

Hi Nicolas,

On 13/06/2020 17:18, Nicolas Goaziou wrote:

Hello,

Mario Frasca  writes:


I can leave existing loops in peace, or edit them keeping them
cl-loop-free.  as for myself, I find it practical and readable.

Then you'll enjoy reading, e.g., `org-contacts-try-completion-prefix'.
FWIW, I don't.


oops.

I do see your point here.  no, at this level, it's not pleasant any more.


I don't know Org Plot enough, but these expectations should be located
in "org-plot.el". I expect `org-table-to-lisp' to be as faithful as
possible. In particular, this function is used in `org-table-align'; as
such, it should not do anything fancy.


I have removed the changes, and added some tests that freeze the current 
behaviour.


that was already in the last patch I sent.


Unit tests are not worth a formal definition. However, "test-ox.el"
contains unit tests.


I'm not sure what you mean by the first sentence, but I found the header 
tests in the test-ox.el file, and added one where multiple lines header 
is accepted.  is it related enough as to be included in my proposal?


to me, unit tests are readable function definitions, often the best form 
of technical documentation.  I have had colleagues writing tests that 
weren't "unitary" at all, mixing all sort of elements together.  when 
written as an after-thought, it's a serious risk.



So, if your question is: "should Org support multiple lines headers?",
I'd say that it already does, but it should definitely be made more
consistent across the various libraries (e.g., Org Plot).


I can move the org-table-collapse-header function from org-table.el to 
org-plot.el, but to me it makes little sense, relegating a generic 
function to a sub-module: others will look for the functionality in 
org-table, not see it, and duplicate the function somewhere else.


for example, do I understand it correctly, that the concept defined in 
the export functionality, but not in org-table itself?


anyhow, what do we do next?

MF

>From b407252fc82d29646d267974c626dbc30145f07f 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 that
collapses multiple header lines into one list.

* 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   |  6 ++--
 lisp/org-table.el  | 27 
 testing/lisp/test-org-table.el | 58 ++
 testing/lisp/test-ox.el| 10 ++
 4 files changed, 97 insertions(+), 4 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..662d38e54 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -289,11 +289,9 @@ 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 (nth 0 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
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 6462b99c4..c40ad5bea 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -5458,6 +5458,33 @@ The table is taken from the parameter TXT, or from the buffer at point."
 	  (forward-line))
 (nreverse table)
 
+(defun org-table-collapse-header (table  glue 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 character."
+  (setq glue (or glue " "))
+  (setq max-header-lines (or max-header-lines 4))
+  (while (equal 'hline (car table))
+(setq table (cdr table)))
+  (let* ((trailer table)
+	 (header-lines (cl-loop for line in table
+until (equal line 'hline)
+collect line
+do (setq trailer

Re: [PATCH] allow for multiline headers

2020-06-13 Thread Mario Frasca

what about these two groups of tests, and the header collapse function?

>From ceb21024159a75dbdb9fef32eebe1fc8c7076d2f 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 that
collapses multiple header lines into one list.

* 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.
---
 lisp/org-plot.el   |  6 ++--
 lisp/org-table.el  | 27 
 testing/lisp/test-org-table.el | 58 ++
 3 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..662d38e54 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -289,11 +289,9 @@ 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 (nth 0 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
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 6462b99c4..c40ad5bea 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -5458,6 +5458,33 @@ The table is taken from the parameter TXT, or from the buffer at point."
 	  (forward-line))
 (nreverse table)
 
+(defun org-table-collapse-header (table  glue 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 character."
+  (setq glue (or glue " "))
+  (setq max-header-lines (or max-header-lines 4))
+  (while (equal 'hline (car table))
+(setq table (cdr table)))
+  (let* ((trailer table)
+	 (header-lines (cl-loop for line in table
+until (equal line 'hline)
+collect line
+do (setq trailer (cdr trailer)
+(if (and trailer (<= (length header-lines) max-header-lines))
+	(cons (apply #'cl-mapcar
+		 #'(lambda ( x)
+			 (org-trim
+			  (mapconcat #'identity x glue)))
+		 header-lines)
+	  trailer)
+  table)))
+
 (defun orgtbl-send-table ( maybe)
   "Send a transformed version of table at point to the receiver position.
 With argument MAYBE, fail quietly if no transformation is defined
diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el
index 64a1b4b16..5d54f4999 100644
--- a/testing/lisp/test-org-table.el
+++ b/testing/lisp/test-org-table.el
@@ -1304,6 +1304,64 @@ See also `test-org-table/copy-field'."
   (should (string= got
 		   expect)
 
+;;; the initial to lisp converter
+
+(ert-deftest test-org-table/to-lisp ()
+  "Test `orgtbl-to-lisp' specifications."
+  ;; 2x2 no header
+  (should
+   (equal '(("a" "b") ("c" "d"))
+	  (org-table-to-lisp "|a|b|\n|c|d|")))
+  ;; 2x2 with 1-line header
+  (should
+   (equal '(("a" "b") hline ("c" "d"))
+	  (org-table-to-lisp "|a|b|\n|-\n|c|d|")))
+  ;; 2x4 with 2-line header
+  (should
+   (equal '(("a" "b") ("A" "B") hline ("c" "d") ("aa" "bb"))
+	  (org-table-to-lisp "|a|b|\n|A|B|\n|-\n|c|d|\n|aa|bb|")))
+  ;; leading hlines do not get stripped
+  (should
+   (equal '(hline ("a" "b") hline ("c" "d"))
+	  (org-table-to-lisp "|-\n|a|b|\n|-\n|c|d|")))
+  (should
+   (equal '(hline ("a" "b") ("c" "d"))
+	  (org-table-to-lisp "|-\n|a|b|\n|c|d|")))
+  (should
+   (equal '(hline hline hline hline ("a" "b") ("c" "d"))
+	  (org-table-to-lisp "|-\n|-\n|-\n|-\n|a|b|\n|c|d|"
+
+(ert-deftest test-org-table/collapse-header ()
+  "Test `orgtbl-to-lisp' specifications."
+  ;; 2x2 no header - no collapsing
+  (should
+   (equal '(("a" "b") ("c" "d"))
+	  (org-table-collapse-header (org-table-to-lisp "|a|b|\n|c|d|"
+  ;; 2x2 with 1-line header - no collapsing
+  (should
+   (equal '(("a" "b") hline ("c" "d"))
+	  (org-table-collapse-header (org-table-to-lisp "|a|b|\n|-\n|c|d|"
+  ;; 2x4 with 2-line header - collapsed
+  (should
+   (equal '(("a A" "b B") hline ("c" "d") ("aa" "bb"))
+	  

Re: [PATCH] allow for multiline headers

2020-06-13 Thread Mario Frasca

hi Nicolas,

is there an agreement on cl-lib usage within the project?  I was hinted 
at cl-loop in this mailing list, and I liked it, in particular the 
`collect' clause, the destructuring feature, and less parentheses.  I 
had no exposure to cl-loop before the hint received here.


I can leave existing loops in peace, or edit them keeping them 
cl-loop-free.  as for myself, I find it practical and readable. let's 
say I'll try to limit usage.


On 12/06/2020 17:44, Nicolas Goaziou wrote:

Also, the first hline is used to determine where to end the header.
A table starting with a hline has no header. Therefore, I suggest to
avoid removing hlines at the beginning of a table, we would lose
information.


this is not a correct description of the current status, at least not 
within org-plot.


(let ((table (org-table-to-lisp)) …

in org-plot we expect either the first or the second element of `table' 
to be a list;


any leading `hline' is removed;

if the second element of `table' is a hline, the first element of 
`table' is considered to be the header (in this case -and only in this 
case- any subsequent `hline' is then removed from `table');


the presence of hline elements in `table' will crash the routine.

--

a table looking like hline-header-hline-data is treated as having a 
header, while your description says it's all data, no header, because of 
the leading hline.


but in my opinion if there's any problem or misunderstanding here, it's 
because there's no unit tests that describe the correct behaviour.  can 
we work at that?


in fact, there's not even a org-table-headers function, that would 
return the table headers.


anyhow, what do you think of the multiple-lines-header option?

MF




[PATCH] allow for multiline headers

2020-06-12 Thread Mario Frasca
it misses unit tests, I need to make the collapse optional, and I need 
to hear from users what they think of it.  this patch allows me to write 
a table like the following, having a three-lines header:


|  n | data | prove, |  casi, | ratio |   prove, |    casi, |
|    |  | valore | valore |   |    media | media |
|    |  | diario | diario |   | corrente | corrente |
|+--+++---+--+--|

and this is seen as a single header line.

|  n | data | prove, valore diario | casi, valore diario | ratio | 
prove, media corrente | casi, media corrente |

|+--+--+-+---+---+--|

I find it helpful, because this way my columns stay narrower.

as it is, ¡it fails on headerless tables!

I have not yet clear what's the best approach to handling headerless 
tables, was thinking of a org-table-max-collapse-header variable, which 
you would set to the number of lines which you are maximally expecting 
to collapse into the leading header line.  Or maybe an extra option to 
org-plot, where you would state if headers need be collapsed.


or we already had ways to achieve this same thing, and I missed them all?

best regards,

MF

>From 649f46a591474afb6cef8b9d5151ff6b0bae38aa 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
that collapses multiple header lines into one list.
(org-table-to-lisp): simplify code, changing a `while' to a
`cl-loop', remove leading `hline' symbols from result, edit
documentation to reflect change.

* lisp/org-plot.el (org-plot/gnuplot): use
org-table-collapse-header and trust there's no leading `hline'
symbols in lisp table.
---
 lisp/org-plot.el  |  6 ++---
 lisp/org-table.el | 59 ---
 2 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..662d38e54 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -289,11 +289,9 @@ 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 (nth 0 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
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 6462b99c4..6549e178a 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -5433,30 +5433,53 @@ a radio table."
 (defun org-table-to-lisp ( txt)
   "Convert the table at point to a Lisp structure.
 
-The structure will be a list.  Each item is either the symbol `hline'
-for a horizontal separator line, or a list of field values as strings.
-The table is taken from the parameter TXT, or from the buffer at point."
+The returned structure is a list, where each item is either the
+symbol `hline', for a horizontal separator line, or a list of
+field values as strings.  The table is taken from the parameter
+TXT, or from the buffer at point.  Leading `hline' symbols are
+trimmed, so the first item in the result is a list"
   (if txt
   (with-temp-buffer
 (insert txt)
-(goto-char (point-min))
 (org-table-to-lisp))
 (save-excursion
   (goto-char (org-table-begin))
-  (let ((table nil))
-(while (re-search-forward "\\=[ \t]*|" nil t)
-	  (let ((row nil))
-	(if (looking-at "-")
-		(push 'hline table)
-	  (while (not (progn (skip-chars-forward " \t") (eolp)))
-		(push (buffer-substring
-		   (point)
-		   (progn (re-search-forward "[ \t]*\\(|\\|$\\)")
-			  (match-beginning 0)))
-		  row))
-	  (push (nreverse row) table)))
-	  (forward-line))
-(nreverse table)
+  (let ((table (cl-loop
+		until (not (re-search-forward "\\=[ \t]*|" nil t))
+		collect (if (looking-at "-")
+'hline
+			  (cl-loop
+   do (skip-chars-forward " \t")
+		   collect (buffer-substring
+	(point)
+	(progn (re-search-forward "[ \t]*\\(|\\|$\\)")
+			   (match-beginning 0)))
+   until (looking-at "$")))
+		do (forward-line
+	(while (equal 'hline (car table))
+  (setq table (cdr table)))
+	table
+
+(defun org-table-collapse-header (table  glue)
+  "Collapse the lines before 'hline into a single header.
+
+The given TABLE is a list of lists as returned by 

Re: issue tracker?

2020-06-07 Thread Mario Frasca

good day Bastien

On 07/06/2020 04:38, Bastien wrote:

anybody can
'vote-for' a bug, and you keep a counter on voted-for.

It would require people to register on updates.orgmode.org.
I'm not sure the expected benefit is really worth it for now.


why would it?  you already trust email senders on identity and integrity 
in all ways, you can also add this one.  a user is an email address.  
the benefit, in my eyes, is for you to have a measure of the opinion of 
(voiceful) users.



a maintainer can 'confirm' (that fixing that bug is
desirable).

I think it is important that anyone can confirm a bug.


I see differences among -confirming a behaviour, -confirming that a 
behaviour is a bug, -asserting that a maintainer would accept a 
"correction".  please drop the subject if you don't want me to argue in 
favour of something you have already discarded.



That said, I would love to organize a hackathon for Org-mode where
people would gather online for one day, exchange ideas, break and fix
things, propose new features, etc.  That is, IMHO, the way to recruit
new contributors, on top of simply formally asking "who would like to
be in charge of X, Y and Z?"


I like the `#emacs' irc chatroom on freenode, I discovered it recently.  
the more specific chatroom `#org-mode' is less active but not less 
welcoming.  it was there where I got the hint to write here, and where 
they told me "no need to subscribe".  or open a new temporary room, but 
I hope we stay with IRC, which we can use from within an emacs buffer.


ciao, Mario




Re: issue tracker?

2020-06-06 Thread Mario Frasca

Hi Bastien,


The tool is experimental: if it proves useful, let's try to keep it,
otherwise let's drop it: our main focus should be in recruiting new
developers to help with the codebase.


very interesting approach.

sounds like you don't want to manage the status changes a bit tighter.  
I know, I can check the code, but it's more practical if we mention it 
here explicitly.  anybody can send status change emails?  I mean, this 
is an open list, anybody who just knows how to put a header to an email 
can confirm a bug?  on the other hand, I never tried to add extra 
headers using thunderbird.


apart from the technical aspect, I would suggest: anybody can 'vote-for' 
a bug, and you keep a counter on voted-for.   but only a maintainer can 
'confirm' (that fixing that bug is desirable). then we new contributors 
can choose which confirmed bug is easy enough for us to make an 
attempt.  or which fits our interests and skills.  or which has 
accumulated most votes, hasn't been rejected, so we can remind the 
maintainer.


… if the "main focus" is recruiting, I would also suggest a category 
"good first issue".


On 06/06/2020 02:57, Bastien wrote:

Hi Mario,

Beware that this is not meant to be an issue tracker.


I understand, not a bug "tracking" tool, but it sounds like it's able to 
shed some light in the dark.


thank you and cheers,

Mario



Re: issue tracker?

2020-06-05 Thread Mario Frasca

On 02/06/2020 06:57, Bastien wrote:

Please go ahead.  Readhttps://orgmode.org/worg/org-contribute.html
and submit your first patch following the rules we have for the commit
messages (they are not easily understood for newcomers).  After a few
well-formatted useful patches, we can perhaps add you as a committer.


I sent the pdf for contributing, and I have a question on how to use 
this email-based issue tracker:


how do I get the list of open issues?  complete with the status 
accepted/wont-fix/whatever?


best regards




Re: tables, positioning of `#+Plot:' lines

2020-06-05 Thread Mario Frasca

On 05/06/2020 15:08, Nicolas Goaziou wrote:

Since TBLFM lines are the odd ones, the mistake was to allow them after
the table, while every other affiliated keyword in the Org universe goes
before the object it applies to.


ah, I did not know that.  that's good.  and we don't want to correct 
that, I guess.


point is: as far as I can see, org-plot currently only recognizes its 
`#+' lines if they are immediately before the table.  being new to this 
world, I a not aware of other `#+:' lines other than TBLFM and PLOT.


which is the name you give to these lines?  def lines? table-meta-data 
lines?  there isn't any global function for matching them, is there?


On 05/06/2020 15:08, Nicolas Goaziou wrote:

What kind of meta information?


I mean other lines matching `^#\+[A-Z]+:' … as said, I don't know how to 
call them, and I guessed "meta information".


best regards, MF




tables, positioning of `#+Plot:' lines

2020-06-05 Thread Mario Frasca
I was wondering about the position of the `#+plot:' lines.  we have a 
table, and if we want to have formulas, we put these in a `#+TBLFM:' 
line following the table.  the documentation of org-plot states that 
`#+PLOT:' lines are looked for: following, or preceding the table, but 
then only the "preceding" strategy is implemented.  I tried just out of 
curiosity, what happens if I put my `#+PLOT:' lines following the table 
but before the `#+TBLFM:' line.  in this case also the `#+TBLFM:' line 
is not found.


I see a couple of problems with this approach and in the current 
implementation:


- only one single `#+TBLFM:' line is recognized, it must follow the 
table, there cannot be any other meta information in between the table 
and the `#+TBLFM:' line.


- other programs can't add meta information to the table, or must choose 
to stay after the `#+TBLFM:' line or before the `#+PLOT:' lines.


- you have meta information at the two ends of the table, instead of all 
on the same side.


I would like to implement the 'plot meta lines after the table', and 
some way to comment meta lines.


any thoughts?

my main doubt is that if we acknowledge meta lines at both ends, we end 
up with an unmanageable mess, where similar information can be very 
distant in the document.  I think it was a mistake to let PLOT 
directives be placed elsewhere than formulas, but I don't know if it's 
still worth changing this.


best regards, MF




Re: a couple of items

2020-06-04 Thread Mario Frasca
hi.  thank you.  seeing hand written code in the target language is 
always useful, when writing a translator.  :+1:  :-)


On 04/06/2020 06:53, Eric S Fraga wrote:

On Wednesday,  3 Jun 2020 at 16:06, Mario Frasca wrote:

consider this table, partially from the Wikipedia:

If you are willing to invoke gnuplot directly, using a src block, the
following is a start towards what you might want.  Proper nice looking
colours etc. left as an exercise for the reader... ;-)

#+begin_src org
   ,#+name: table
   | Region |   Area | Production | Productivity |
   ||  (Mha) |  (Mtonnes) |  (tonnes/ha) |
   |+++--|
   | Western Europe |  2.490 |  5.730 |2.3012048 |
   | North America  |  2.960 |  5.756 |1.9445946 |
   | South America  |  0.102 |  0.196 |1.9215686 |
   | Middle East|  4.462 |  6.950 |1.5575975 |
   | North Africa   |  3.290 |  3.214 |0.9768997 |
   | Others |  3.756 |  3.540 |0.9424920 |
   |+++--|
   | World  | 17.060 | 25.360 |1.4865181 |
   ,#+TBLFM: $4=$3/$2

   ,#+begin_src gnuplot :var data=table[3:8,] :file plot.pdf
 reset
 set term pdfcairo color
 set xtics rotate 90
 set style fill solid border lt 1
 plot data using 2:xticlabels(1) with histogram linecolor "blue" title 
'Area', \
  '' using 3 with histogram lt 1 linecolor "red" title 'Production', \
  '' using 4 with points pt 5 linecolor black title 'Productivity'
   ,#+end_src
#+end_src





Re: `with` as a list.

2020-06-03 Thread Mario Frasca

On 03/06/2020 10:29, Bastien wrote:

The few lines above is what we called the "changelog".  It should be
the first part of the commit message -- after which you can add more
free-form context and explanations, if needed.


this "Changelog", and I'm sure I am the stiffy one, isn't clear from the 
description.  browsing through the other contributions, I recognize this 
structure:


the "Changelog" is the second block, (preferably) without any empty 
lines.  the next empty line will end the "Changelog" and start the less 
formal comments. (unsure about this).


changes are grouped by file, each changed file is introduced by a line 
starting with an asterisk '*', and the complete path of the file.  then 
follows the function affected, in single parentheses, a colon ':', and 
the description of the change.  if the change is relative to 
documentation, the parentheses include title of the affected paragraph.  
finally the description, formatted as per your html page.


if the next change is in the same file, you skip the leading '*' and 
file name and the line should start with the parenthesized affected object.




for example (two files, two different changes --- code and doc):

* lisp/org.el (org-read-date-analyze): Add support for HHhMM time
input, in similar way as for am/pm times.
* doc/org-manual.org (The date/time prompt): Add example to illustrate
the feature.



other example (two affected files, single description --- code):

* testing/lisp/test-ob-tangle.el (ob-tangle/jump-to-org):
* testing/lisp/test-org-attach.el (test-org-attach/dir): Rig
org-file-apps so that temporary files are visited inside Emacs.



(one file, two different changes --- doc):

* doc/org-manual.org (Capturing column view): Replace stale binding
with mention of org-dynamic-block-insert-dblock, and refer to
org-columns-insert-dblock rather than its obsolete variant.
(The clock table): Prune references to stale binding, rewrite
org-dynamic-block-insert-dblock key sequence in a clearer manner, and
add a dedicated entry for org-clock-report.



slightly sloppy example (two files, single description, not clear what's 
affected):


* lisp/org-clock.el:
* lisp/org-colview.el: Autoload call to org-dynamic-block-define.



etc/ORG-NEWS is an exception, and should be mentioned as first.
are empty lines acceptable?  or will your parser fail to understand?

* etc/ORG-NEWS: Announce the change.

* lisp/org-keys.el (org-mode-map): Rebind C-j to a command emulating
`electric-newline-and-maybe-indent'.

* lisp/org.el (org-cdlatex-environment-indent): Stop using the now
obsolete function.
(org--newline): New helper function.
(org-return): Use it to transparently handle `electric-indent-mode'.
(org-return-and-maybe-indent): New command to emulate
`electric-newline-and-maybe-indent' while taking care of Org special
cases (tables, links, timestamps).







a couple of items

2020-06-03 Thread Mario Frasca

consider this table, partially from the Wikipedia:

#+PLOT: with:histogram ind:1
| Region |   Area | Production |Productivity |
|    |  (Mha) |  (Mtonnes) |  (tonnes/ha) |
|+++--|
| Western Europe |  2.490 |  5.730 |    2.3012048 |
| North America  |  2.960 |  5.756 |    1.9445946 |
| South America  |  0.102 |  0.196 |    1.9215686 |
| Middle East    |  4.462 |  6.950 |    1.5575975 |
| North Africa   |  3.290 |  3.214 |    0.9768997 |
| Others |  3.756 |  3.540 |    0.9424920 |
|+++--|
| World  | 17.060 | 25.360 |    1.4865181 |
#+TBLFM: $4=$3/$2

here I have a couple things which I would like to do straight from 
org-plot, and don't work.


1) keep the header on two lines.

2) only plot the middle section, that's excluding the "world" summary.

3) manually indicate the desired colour for each bar.

4) plot one of the columns as points, not as bars.

something unrelated, but still about org-plot:

*) it's very practical that you can split #+PLOT lines, and it would be 
more useful if you could mark any of them as non active, "comment out", 
but so that this doesn't break the search for options.  something like 
#--+PLOT, whatever.  I would use it for alternative settings and it 
would spare me shuffling lines around.






Re: `with` as a list.

2020-06-03 Thread Mario Frasca
 col-labels)
-(format "%d" (1+ col
-			plot-lines)
-	(`3d
-	 (setq plot-lines (list (format "'%s' matrix with %s title ''"
-	data-file with
-	(`grid
-	 (setq plot-lines (list (format "'%s' with %s title ''"
-	data-file with)
+  (setq plot-lines
+	(pcase type			; plot command
+	  (`2d (cl-loop
+		for (col . with)
+		in (org-plot/zip-deps-with num-cols ind deps with)
+		collect (format plot-str data-file
+(or (and ind (> ind 0)
+	 (not text-ind)
+	 (format "%d:" ind)) "")
+col
+(if text-ind (format ":xticlabel(%d)" ind) "")
+with
+(or (nth (1- col) col-labels)
+	(format "%d" col)
+	  (`3d (list (format "'%s' matrix with %s title ''"
+ data-file with)))
+	  (`grid (list (format "'%s' with %s title ''"
+   data-file with)
   (funcall ats
 	   (concat plot-cmd " " (mapconcat #'identity
-	   (reverse plot-lines)
+	   plot-lines
 	   ",\\\n"
 script))
 
@@ -310,7 +323,8 @@ line directly before or after the table."
 table data-file params)))
 		 (when y-labels (plist-put params :ylabels y-labels)
   ;; Check for timestamp ind column.
-  (let ((ind (1- (plist-get params :ind
+  (let ((ind (1- (plist-get params :ind)))
+	(with (plist-get params :with)))
 	(when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))
 	  (if (= (length
 		  (delq 0 (mapcar
@@ -320,7 +334,7 @@ line directly before or after the table."
 		 0)
 	  (plist-put params :timeind t)
 	;; Check for text ind column.
-	(if (or (string= (plist-get params :with) "hist")
+	    (if (or (equal with "hist")
 		(> (length
 			(delq 0 (mapcar
  (lambda (el)
diff --git a/testing/lisp/test-org-plot.el b/testing/lisp/test-org-plot.el
new file mode 100644
index 0..2bf153400
--- /dev/null
+++ b/testing/lisp/test-org-plot.el
@@ -0,0 +1,64 @@
+;;; test-org-plot.el --- Tests for Org Plot library-*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020  Mario Frasca
+
+;; Author: Mario Frasca 
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'org-test)
+(require 'org-plot)
+
+
+;; General auxiliaries
+
+(ert-deftest test-org-plot/zip-deps-with ()
+  "Test `org-plot/zip-deps-with' specifications."
+  ;; no deps, no with. defaults to all except ind, and "lines"
+  (should
+   (equal (org-plot/zip-deps-with 3 1 nil nil)
+	  '((2 . "lines") (3 . "lines"
+  ;; no deps, single with. defaults to all except ind, and repeated with
+  (should
+   (equal (org-plot/zip-deps-with 3 1 nil "hist")
+	  '((2 . "hist") (3 . "hist"
+  ;; no deps, explicit with
+  (should
+   (equal (org-plot/zip-deps-with 3 1 nil '("points" "hist"))
+	  '((2 . "points") (3 . "hist"
+  ;; explicit with, same length as deps
+  (should
+   (equal (org-plot/zip-deps-with 5 1 '(2 4) '("points" "hist"))
+	  '((2 . "points") (4 . "hist"
+  ;; same as above, but different order
+  (should
+   (equal (org-plot/zip-deps-with 5 1 '(4 2) '("points" "hist"))
+	  '((4 . "points") (2 . "hist"
+  ;; if with exceeds deps, trailing elements are discarded
+  (should
+   (equal (org-plot/zip-deps-with 5 1 '(4 2) '("points" "hist" "lines"))
+	  '((4 . "points") (2 . "hist"
+  ;; fills in with "lines"
+  (should
+   (equal (org-plot/zip-deps-with 5 1 '(4 2 3) '("points"))
+	  '((4 . "points") (2 . "lines") (3 . "lines")
+
+
+
+(provide 'test-org-plot)
+;;; test-org-plot.el end here
-- 
2.20.1



Re: `with` as a list.

2020-06-03 Thread Mario Frasca

On 03/06/2020 10:13, Bastien wrote:

Also you need to sign the FSF copyright assignment if you want to make
big changes like this one.
yes, I received the ASSIGNMENT –GNU EMACS pdf last night, I'm now seeing 
how I print & sign it.  it might take some time.




Re: `with` as a list.

2020-06-03 Thread Mario Frasca
I'm very so much sorry Bastien, but I do not know what you mean, by "not 
correctly formatted".  if it were a bug report, you do agree it would be 
a useless one?  like "it doesn't work".


I'm sure you do understand what I mean, and I guess you know what would 
be the correctly formatted version.  can you show me?  next time I'll do 
better, but as of now, I obviously do not understand what you want, and 
why.  I was busy amending my other patches, and preparing a few more, 
but let's save time on both sides, and I'll give up for the time being.


ciao,

Mario


On 03/06/2020 10:13, Bastien wrote:

Mario Frasca  writes:


see attachment

Thanks for the effort -- the commit message is not correctly formatted
though.  See https://orgmode.org/worg/org-contribute.html#commit-messages
and perhaps also read previous commit messages.

Also you need to sign the FSF copyright assignment if you want to make
big changes like this one.

See https://orgmode.org/request-assign-future.txt

Thanks,





Re: [PATCH] some minimal refactoring for the sake of unit-testing, and a, couple of tests.

2020-06-03 Thread Mario Frasca

see attachment
>From 065ee9e35e71b0b7c0c0c2a8842909830225d962 Mon Sep 17 00:00:00 2001
From: mfrasca 
Date: Tue, 2 Jun 2020 15:48:46 -0500
Subject: [PATCH] org-plot.el: adding unit tests

this patch contains some minimal refactoring for the sake of
unit-testing, and a couple of tests in the (new) file
`testing/lisp/test-org-plot.el'.
---
 lisp/org-plot.el  |  18 ++-
 testing/lisp/test-org-plot.el | 207 ++
 2 files changed, 220 insertions(+), 5 deletions(-)
 create mode 100644 testing/lisp/test-org-plot.el

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..f4526db13 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -91,8 +91,8 @@ Return value is the point at the beginning of the table."
   (while (not (or (org-at-table-p) (< 0 (forward-line 1)
   (goto-char (org-table-begin)))
 
-(defun org-plot/collect-options ( params)
-  "Collect options from an org-plot `#+Plot:' line.
+(defun org-plot/collect-line-options ( params)
+  "Collect options from the org-plot `#+Plot:' line at point.
 Accepts an optional property list PARAMS, to which the options
 will be added.  Returns the resulting property list."
   (interactive)
@@ -101,6 +101,16 @@ will be added.  Returns the resulting property list."
 	(org-plot/add-options-to-plist params (match-string 1 line))
   params)))
 
+(defun org-plot/collect-table-options ( params)
+  "Collect options from the `#+Plot:' lines preceding the current table.
+Point must immediately after last `#+Plot:' line.
+Accepts an optional property list PARAMS, to which the options will be added.
+Returns the accumulated property list."
+  (save-excursion (while (and (equal 0 (forward-line -1))
+			  (looking-at "[[:space:]]*#\\+"))
+		(setq params (org-plot/collect-line-options params
+  params)
+
 (defun org-plot-quote-timestamp-field (s)
   "Convert field S from timestamp to Unix time and export to gnuplot."
   (format-time-string org-plot-timestamp-fmt (org-time-string-to-time s)))
@@ -299,9 +309,7 @@ line directly before or after the table."
 	  (plist-put params :labels (nth 0 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))
-  (looking-at "[[:space:]]*#\\+"))
-			(setf params (org-plot/collect-options params
+  (setq params (org-plot/collect-table-options params))
   ;; Dump table to datafile (very different for grid).
   (pcase (plist-get params :plot-type)
 	(`2d   (org-plot/gnuplot-to-data table data-file params))
diff --git a/testing/lisp/test-org-plot.el b/testing/lisp/test-org-plot.el
new file mode 100644
index 0..b23075050
--- /dev/null
+++ b/testing/lisp/test-org-plot.el
@@ -0,0 +1,207 @@
+;;; test-org-plot.el --- Tests for Org Plot library-*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020  Mario Frasca
+
+;; Author: Mario Frasca 
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'org-test)
+(require 'org-plot)
+
+
+;; General auxiliaries
+
+
+(ert-deftest test-org-plot/collect-line-options ()
+  "Test `org-plot/collect-line-options' specifications."
+  ;; no options specified in table, no defaults
+  (should
+   (equal nil
+  (org-test-with-temp-text
+  "| 1 |"
+(org-plot/collect-line-options
+  ;; no options specified in table, keeps all defaults
+  (should
+   (equal '(:ind 1 :deps 2 3)
+  (org-test-with-temp-text
+  "| 1 |"
+(org-plot/collect-line-options '(:ind 1 :deps 2 3)
+  ;; the independent column
+  (should
+   (equal '(:ind 1)
+  (org-test-with-temp-text
+  "#+PLOT: ind:1\n| 1 |"
+(org-plot/collect-line-options
+  ;; overruling default
+  (should
+   (equal '(:ind 2)
+  (org-test-with-temp-text
+  "#+PLOT: ind:2\n| 1 | 2 |"
+(org-plot/collect-line-options '(:ind 1)
+  ;; appends to already collected
+  (should
+   (equal '(:deps (1 3) :ind 2 )
+  (org-test-with-temp-text
+  "#+PLOT: ind:2\n| 1 | 2 | 3 |"
+(org-plot/collect-line-

Re: `with` as a list.

2020-06-03 Thread Mario Frasca
+(if text-ind (format ":xticlabel(%d)" ind) "")
+with
+(or (nth (1- col) col-labels)
+	(format "%d" col)
+	  (`3d (list (format "'%s' matrix with %s title ''"
+ data-file with)))
+	  (`grid (list (format "'%s' with %s title ''"
+   data-file with)
   (funcall ats
 	   (concat plot-cmd " " (mapconcat #'identity
-	   (reverse plot-lines)
+	   plot-lines
 	   ",\\\n"
 script))
 
@@ -310,7 +323,8 @@ line directly before or after the table."
 table data-file params)))
 		 (when y-labels (plist-put params :ylabels y-labels)
   ;; Check for timestamp ind column.
-  (let ((ind (1- (plist-get params :ind
+  (let ((ind (1- (plist-get params :ind)))
+	(with (plist-get params :with)))
 	(when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))
 	  (if (= (length
 		  (delq 0 (mapcar
@@ -320,7 +334,7 @@ line directly before or after the table."
 		 0)
 	  (plist-put params :timeind t)
 	;; Check for text ind column.
-	(if (or (string= (plist-get params :with) "hist")
+	(if (or (equal with "hist")
 		    (> (length
 			(delq 0 (mapcar
  (lambda (el)
diff --git a/testing/lisp/test-org-plot.el b/testing/lisp/test-org-plot.el
new file mode 100644
index 0..2bf153400
--- /dev/null
+++ b/testing/lisp/test-org-plot.el
@@ -0,0 +1,64 @@
+;;; test-org-plot.el --- Tests for Org Plot library-*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020  Mario Frasca
+
+;; Author: Mario Frasca 
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'org-test)
+(require 'org-plot)
+
+
+;; General auxiliaries
+
+(ert-deftest test-org-plot/zip-deps-with ()
+  "Test `org-plot/zip-deps-with' specifications."
+  ;; no deps, no with. defaults to all except ind, and "lines"
+  (should
+   (equal (org-plot/zip-deps-with 3 1 nil nil)
+	  '((2 . "lines") (3 . "lines"
+  ;; no deps, single with. defaults to all except ind, and repeated with
+  (should
+   (equal (org-plot/zip-deps-with 3 1 nil "hist")
+	  '((2 . "hist") (3 . "hist"
+  ;; no deps, explicit with
+  (should
+   (equal (org-plot/zip-deps-with 3 1 nil '("points" "hist"))
+	  '((2 . "points") (3 . "hist"
+  ;; explicit with, same length as deps
+  (should
+   (equal (org-plot/zip-deps-with 5 1 '(2 4) '("points" "hist"))
+	  '((2 . "points") (4 . "hist"
+  ;; same as above, but different order
+  (should
+   (equal (org-plot/zip-deps-with 5 1 '(4 2) '("points" "hist"))
+	  '((4 . "points") (2 . "hist"
+  ;; if with exceeds deps, trailing elements are discarded
+  (should
+   (equal (org-plot/zip-deps-with 5 1 '(4 2) '("points" "hist" "lines"))
+	  '((4 . "points") (2 . "hist"
+  ;; fills in with "lines"
+  (should
+   (equal (org-plot/zip-deps-with 5 1 '(4 2 3) '("points"))
+	  '((4 . "points") (2 . "lines") (3 . "lines")
+
+
+
+(provide 'test-org-plot)
+;;; test-org-plot.el end here
-- 
2.20.1



Re: [PATCH] implementing `with' as a list, and respecting `deps' order.

2020-06-03 Thread Mario Frasca

comments on the html page org-contribute.html:

is there any mention of git-send-mail in the org-contribute guide?  I 
don't see it.  nor do I find hints on what to do once you have produced 
files by git-format-patch.  your "send as attachment" would be useful 
there.  or a mention of a (unix) command-line sequence, including how to 
follow-up to previous messages.


the procedure mentioned there guides me in creating several patch files, 
one per commit.  it does not describe the "squashing" you suggested me.  
I'm following your guide, but you might want to review the page yourself.


the `#commit-messages' section is very clear, I had totally missed it.  
sorry.


I'm reviewing the commit message accordingly, and will reply to my 
initial message, attaching the new patch.


ciao, MF

On 02/06/2020 22:38, Kyle Meyer wrote:

Mario Frasca writes:


  From 436bfd0b9fd656f52ea9d7e6a6a665a32564ae93 Mon Sep 17 00:00:00 2001
From: Mario Frasca 
Date: Tue, 2 Jun 2020 15:46:20 +
Subject: [PATCH] implementing `with' as a list, and respecting `deps' order.

Thank you for sending an updated patch.  Unfortunately it looks like it
got mangled by your email client and can't be understood by `git am'.
This list is okay with patches being sent as attachments, and going that
route gets around needing to re-configure your email client or use
git-send-email.

Before sending the updated patch, please revise the commit message to
more closely match the conventions described at
<https://orgmode.org/worg/org-contribute.html>.  Looking over some
recent commits in the repo should give you a good sense for the expected
changelog-like entries as well other style aspects (e.g., it is common
to start the subject with ": " like "org-plot: ..."), which
gives log readers a sense for the general topic affected by the commit.

Please send the next patch as a follow-up to the original thread to keep
the discussion in one place.

Thanks again.




[PATCH] some minimal refactoring for the sake of unit-testing, and a, couple of tests.

2020-06-02 Thread Mario Frasca

From 0ee824cccf793734fa18d42b67d44dae2a2e136e Mon Sep 17 00:00:00 2001
From: mfrasca 
Date: Tue, 2 Jun 2020 15:48:46 -0500
Subject: [PATCH] some minimal refactoring for the sake of unit-testing, 
and a

 couple of tests.

---
 lisp/org-plot.el  |  18 ++-
 testing/lisp/test-org-plot.el | 207 ++
 2 files changed, 220 insertions(+), 5 deletions(-)
 create mode 100644 testing/lisp/test-org-plot.el

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..f4526db13 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -91,8 +91,8 @@ Return value is the point at the beginning of the table."
   (while (not (or (org-at-table-p) (< 0 (forward-line 1)
   (goto-char (org-table-begin)))

-(defun org-plot/collect-options ( params)
-  "Collect options from an org-plot `#+Plot:' line.
+(defun org-plot/collect-line-options ( params)
+  "Collect options from the org-plot `#+Plot:' line at point.
 Accepts an optional property list PARAMS, to which the options
 will be added.  Returns the resulting property list."
   (interactive)
@@ -101,6 +101,16 @@ will be added.  Returns the resulting property list."
 (org-plot/add-options-to-plist params (match-string 1 line))
   params)))

+(defun org-plot/collect-table-options ( params)
+  "Collect options from the `#+Plot:' lines preceding the current table.
+Point must immediately after last `#+Plot:' line.
+Accepts an optional property list PARAMS, to which the options will be 
added.

+Returns the accumulated property list."
+  (save-excursion (while (and (equal 0 (forward-line -1))
+              (looking-at "[[:space:]]*#\\+"))
+            (setq params (org-plot/collect-line-options params
+  params)
+
 (defun org-plot-quote-timestamp-field (s)
   "Convert field S from timestamp to Unix time and export to gnuplot."
   (format-time-string org-plot-timestamp-fmt (org-time-string-to-time s)))
@@ -299,9 +309,7 @@ line directly before or after the table."
   (plist-put params :labels (nth 0 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))
-                  (looking-at "[[:space:]]*#\\+"))
-            (setf params (org-plot/collect-options params
+  (setq params (org-plot/collect-table-options params))
   ;; Dump table to datafile (very different for grid).
   (pcase (plist-get params :plot-type)
 (`2d   (org-plot/gnuplot-to-data table data-file params))
diff --git a/testing/lisp/test-org-plot.el b/testing/lisp/test-org-plot.el
new file mode 100644
index 0..b23075050
--- /dev/null
+++ b/testing/lisp/test-org-plot.el
@@ -0,0 +1,207 @@
+;;; test-org-plot.el --- Tests for Org Plot library -*- 
lexical-binding: t; -*-

+
+;; Copyright (C) 2020  Mario Frasca
+
+;; Author: Mario Frasca 
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'org-test)
+(require 'org-plot)
+
+
+;; General auxiliaries
+
+
+(ert-deftest test-org-plot/collect-line-options ()
+  "Test `org-plot/collect-line-options' specifications."
+  ;; no options specified in table, no defaults
+  (should
+   (equal nil
+  (org-test-with-temp-text
+  "| 1 |"
+    (org-plot/collect-line-options
+  ;; no options specified in table, keeps all defaults
+  (should
+   (equal '(:ind 1 :deps 2 3)
+  (org-test-with-temp-text
+  "| 1 |"
+    (org-plot/collect-line-options '(:ind 1 :deps 2 3)
+  ;; the independent column
+  (should
+   (equal '(:ind 1)
+  (org-test-with-temp-text
+  "#+PLOT: ind:1\n| 1 |"
+    (org-plot/collect-line-options
+  ;; overruling default
+  (should
+   (equal '(:ind 2)
+  (org-test-with-temp-text
+  "#+PLOT: ind:2\n| 1 | 2 |"
+    (org-plot/collect-line-options '(:ind 1)
+  ;; appends to already collected
+  (should
+   (equal '(:deps (1 3) :ind 2 )
+  (org-test-with-temp-text
+  "#+PLOT: ind:2\n| 1 | 2 | 3 |"
+    (org-plot/collect-line-options '(:deps (1 3))
+  ;; appends to already collected
+  (should

[PATCH] docstrings to match the code, and minor cosmetics.

2020-06-02 Thread Mario Frasca

From 43cc6264deb89fcc665d123b06c7c2aebb35ab3a Mon Sep 17 00:00:00 2001
From: Mario Frasca 
Date: Tue, 2 Jun 2020 16:22:07 +
Subject: [PATCH] docstrings to match the code, and minor cosmetics.

---
 lisp/org-plot.el | 21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..3a95c72d6 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -85,14 +85,18 @@ Returns the resulting property list."
   p)

 (defun org-plot/goto-nearest-table ()
-  "Move the point forward to the beginning of nearest table.
-Return value is the point at the beginning of the table."
-  (interactive) (move-beginning-of-line 1)
+  "Move the point to the beginning of table.
+Moves back if the point is inside a table, otherwise looks for next table.
+If there is no table to be found, moves to end of buffer.
+Return value is the point."
+  (interactive)
+  (move-beginning-of-line 1)
   (while (not (or (org-at-table-p) (< 0 (forward-line 1)
   (goto-char (org-table-begin)))

 (defun org-plot/collect-options ( params)
   "Collect options from an org-plot `#+Plot:' line.
+Examines the line at point.
 Accepts an optional property list PARAMS, to which the options
 will be added.  Returns the resulting property list."
   (interactive)
@@ -143,7 +147,8 @@ and dependent variables."
  (counter 0)
  row-vals)
 (when (>= ind 0) ;; collect values of ind col
-  (setf row-vals (mapcar (lambda (row) (setf counter (+ 1 counter))
+  (setf row-vals (mapcar (lambda (row)
+               (setf counter (+ 1 counter))
            (cons counter (nth ind row)))
          table)))
 (when (or deps (>= ind 0)) ;; remove non-plotting columns
@@ -156,7 +161,8 @@ and dependent variables."
           table)))
 ;; write table to gnuplot grid datafile format
 (with-temp-file data-file
-  (let ((num-rows (length table)) (num-cols (length (nth 0 table)))
+  (let ((num-rows (length table))
+        (num-cols (length (nth 0 table)))
     (gnuplot-row (lambda (col row value)
            (setf col (+ 1 col)) (setf row (+ 1 row))
            (format "%f  %f  %f\n%f  %f  %f\n"
@@ -180,7 +186,8 @@ and dependent variables."
 row-vals))

 (defun org-plot/gnuplot-script (data-file num-cols params  
preface)
-  "Write a gnuplot script to DATA-FILE respecting the options set in 
PARAMS.

+  "Return gnuplot script respecting the options set in PARAMS.
+DATA-FILE is the name of the data containing file.
 NUM-COLS controls the number of columns plotted in a 2-d plot.
 Optional argument PREFACE returns only option parameters in a
 manner suitable for prepending to a user-specified script."
@@ -274,7 +281,7 @@ manner suitable for prepending to a user-specified 
script."

 (defun org-plot/gnuplot ( params)
   "Plot table using gnuplot.  Gnuplot options can be specified with 
PARAMS.

 If not given options will be taken from the +PLOT
-line directly before or after the table."
+line(s) directly before the table."
   (interactive)
   (require 'gnuplot)
   (save-window-excursion
--
2.20.1





[PATCH] implementing `with' as a list, and respecting `deps' order.

2020-06-02 Thread Mario Frasca

From 436bfd0b9fd656f52ea9d7e6a6a665a32564ae93 Mon Sep 17 00:00:00 2001
From: Mario Frasca 
Date: Tue, 2 Jun 2020 15:46:20 +
Subject: [PATCH] implementing `with' as a list, and respecting `deps' order.

---
 doc/org-manual.org    |  7 ++--
 lisp/org-plot.el  | 66 +--
 testing/lisp/test-org-plot.el | 64 +
 3 files changed, 108 insertions(+), 29 deletions(-)
 create mode 100644 testing/lisp/test-org-plot.el

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 92252179b..40cb3c2f2 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -2845,9 +2845,10 @@ For more information and examples see the 
[[https://orgmode.org/worg/org-tutoria


 - =with= ::

-  Specify a =with= option to be inserted for every column being
-  plotted, e.g., =lines=, =points=, =boxes=, =impulses=. Defaults to
-  =lines=.
+  Specify a =with= option to be inserted for the columns being
+  plotted, e.g., =lines=, =points=, =boxes=, =impulses=. You can specify
+  a single value, to be applied to all columns, or a list of different
+  values, one for each column in the =deps= property. Defaults to =lines=.

 - =file= ::

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..073075037 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -179,6 +179,24 @@ and dependent variables."
   (setf back-edge "") (setf front-edge ""
 row-vals))

+(defun org-plot/zip-deps-with (num-cols ind deps with)
+  "Describe each column to be plotted as (col . with).
+Loops over DEPS and WITH in order to cons their elements.
+If the DEPS list of columns is not given, use all columns from 1
+to NUM-COLS, excluding IND.
+If WITH is given as a string, use the given value for all columns.
+If WITH is given as a list, and it's shorter than DEPS, expand it
+with the global default value."
+  (unless deps
+    (setq deps (remove ind (number-sequence 1 num-cols
+  (setq with
+    (if (listp with)
+        (append with
+            (make-list (max 0 (- (length deps) (length with)))
+               "lines"))
+      (make-list (length deps) with)))
+  (cl-mapcar #'cons deps with))
+
 (defun org-plot/gnuplot-script (data-file num-cols params  
preface)
   "Write a gnuplot script to DATA-FILE respecting the options set in 
PARAMS.

 NUM-COLS controls the number of columns plotted in a 2-d plot.
@@ -239,32 +257,27 @@ manner suitable for prepending to a user-specified 
script."

            (or timefmt    ; timefmt passed to gnuplot
            "%Y-%m-%d-%H:%M:%S") "\"")))
 (unless preface
-  (pcase type            ; plot command
-    (`2d (dotimes (col num-cols)
-       (unless (and (eq type '2d)
-                (or (and ind (equal (1+ col) ind))
-                (and deps (not (member (1+ col) deps)
-         (setf plot-lines
-           (cons
-            (format plot-str data-file
-                (or (and ind (> ind 0)
-                     (not text-ind)
-                     (format "%d:" ind)) "")
-                (1+ col)
-                (if text-ind (format ":xticlabel(%d)" ind) "")
-                with
-                (or (nth col col-labels)
-                    (format "%d" (1+ col
-            plot-lines)
-    (`3d
-     (setq plot-lines (list (format "'%s' matrix with %s title ''"
-                    data-file with
-    (`grid
-     (setq plot-lines (list (format "'%s' with %s title ''"
-                    data-file with)
+  (setq plot-lines
+        (pcase type            ; plot command
+      (`2d (cl-loop
+            for (col . with)
+            in (org-plot/zip-deps-with num-cols ind deps with)
+            collect (format plot-str data-file
+                    (or (and ind (> ind 0)
+                     (not text-ind)
+                     (format "%d:" ind)) "")
+                    col
+                    (if text-ind (format ":xticlabel(%d)" ind) "")
+                    with
+                    (or (nth (1- col) col-labels)
+                    (format "%d" col)
+      (`3d (list (format "'%s' matrix with %s title ''"
+                 data-file with)))
+      (`grid (list (format "'%s' with %s title ''"
+                   data-file with)
   (funcall ats
    (concat plot-cmd " " (mapconcat #'identity
-                       (reverse plot-lines)
+                       plot-lines
                    ",\\\n    "
 script))

@@ -310,7 +323,8 @@ line directly before or after the table."
             table data-file params)))
      (when y-labels (plist-put params :ylabels y-labels)
   ;; Check for timestamp ind column.
-  (let (

Re: issue tracker?

2020-06-01 Thread Mario Frasca

On 01/06/2020 10:53, Bastien wrote:

Let us know what would help you contribute more.


as mentioned, I would like to correct docstrings, refactor the code in a 
few points, and add unit tests.


---

(defun org-plot/gnuplot-script (data-file num-cols params  preface)
  "Write a gnuplot script to DATA-FILE respecting the options set in 
PARAMS.


this is not what the function does: DATA-FILE is purely a string, the 
name of the file containing the data, and the function returns the 
script as a string, which refers to DATA-FILE.


in practice, the author could have left the DATA-FILE parameter 
altogether, used a placeholder, say %DATAFILE%, and replaced it in the 
returned string.  but it works, and I would not fix it, except for the 
docstring, which is misleading.


---

(defun org-plot/goto-nearest-table ()
  "Move the point to the beginning of nearest table.
Moves back if the point is currently inside of table, otherwise
forward to next table.  Return value is the point."

this is what the function does, but the current docstring says

(defun org-plot/goto-nearest-table ()
  "Move the point forward to the beginning of nearest table.
Return value is the point at the beginning of the table."

where "nearest" is not defined.

---

collecting options is a candidate for refactoring:

  (save-excursion (while (and (equal 0 (forward-line -1))
                  (looking-at "[[:space:]]*#\\+"))
            (setf params (org-plot/collect-options params

this is how it is used, inside of the exposed command org-plot/gnuplot.

---

If I understood my other reviewer Kyle Meyer correctly, he was 
suggesting that usage of setf instead of setq in this source was not 
exactly appropriate, and I think it is only necessary in one case, the 
others can be replaced with setq.


but then again, fixing something that works and has no unit tests, may 
be a recipe for future failure.


---

there are other minor mistakes in the code and in the documentation, 
which are quite unrelated, like formatting …


  (let ((num-rows (length table)) (num-cols (length (nth 0 table)))
        (gnuplot-row (lambda (col row value)

notice how this let has three clauses, but they fit on two lines.

or simply typing =dep= instead of =deps=.

---

I've not been collecting them, this is just the few that I can recall, 
and would like to correct them, but in order to make my contribution 
only touch the code I want to add, I refrain from doing so.


best regards, MF




Re: issue tracker?

2020-06-01 Thread Mario Frasca

Hi Bastien,

in the meanwhile someone found the patch, and we are working on it.

thank you for the feedback!

but it stays confusing, and sure I get the point, people here are 
volunteers, working on their free time, but precisely for this reason it 
would be better if we could rely on some more focused / focusing tool 
for working on patches.


while working on my contribution, I'm also reading the code I'm adding 
to, and I am tempted to perform unrelated edits, like correcting a 
docstring to a function that does something, just not quite what the 
docstring says, or refactoring stuff in order to add missing unit tests, 
but that way my patch would not focus on the task of adding this small 
piece of functionality.


it's several unrelated edits, and if we were to do this via email, it 
would cost all of us so much time, that I think I'll better leave it.


ciao, best regards, MF

On 01/06/2020 09:45, Bastien wrote:

Hi Mario,

Mario Frasca  writes:


myself, I recently posted a patch, received zero reaction, and have
the impression it's now lost in the logs of this mailing list.  indeed
pretty inefficient!

Sorry for that.

As others have mentioned, Org developers are working on their free
time to help others, fix bugs and keep Org alive.

If you think your patch got lost and should be considered, please
revive the thread.

Thanks,





Re: `with` as a list.

2020-05-31 Thread Mario Frasca

On 31/05/2020 19:19, Kyle Meyer wrote:

You've been sending a diff,
presumably from the point you branched off of to the tip of your branch.
In that case, you're already presenting each iteration you've sent as
one change; it just lacks a commit message.


right, that's indeed what I did, and this is also what I thought, so no 
need to rebase, squash or whatever, as long as I make sure that the diff 
I'm sending you is about this single issue, and let's agree on the 
commit message, because after all I'm adding a function to a software I 
don't really know.


I hope to send an updated patch soon, that will also include the docs.

I have no strong opinion on workflows, just trying to understand the one 
used here.


btw: if I had write permissions to the repositories, I would be adding 
test cases, and reviewing the docstrings, some of which I find 
misleading.  your remark on setf/setq could also be addressed in the 
code.  and some of the code ought to be refactored, as to allow for unit 
tests.


ciao, MF




Re: `with` as a list.

2020-05-31 Thread Mario Frasca

On 30/05/2020 16:29, Mario Frasca wrote:
I hope to be back soon with a single commit... 


one doubt.  what's the point of having me squash all in a single commit, 
when I do not have write access to the repository?  if we were on 
github, I would be working on a pull request, which would have a 
description and a title, and contain several commits.  I don't 
understand the workflow apparently.






Re: `with` as a list.

2020-05-30 Thread Mario Frasca

On 30/05/2020 15:25, Kyle Meyer wrote:

Could you update this header to match the style used by other tests
(see, e.g., test-org-num.el)?


apparently, I managed to pick precisely the wrong example!

;;; test-org-clock.el --- Tests for org-clock.el





Re: `with` as a list.

2020-05-30 Thread Mario Frasca
oops .. you mentioned `cl-loop' and I found it interesting, in 
particular the de-structuring part.


so I rewrote the (dolist (col-with …) …) as (cl-loop for (col . with) in 
… do …).


so I could simplify `(car col-with)' and `(cdr col-with)', then I 
replaced the `do' with a `collect', so I could squash other `setq' into 
one, and finally removed the need to do a `reverse' on the result.  less 
parentheses, and 4 lines less.


I added one regression test which is still respected, as is the rest of 
the test suite.


so maybe all is fine.

putting order in the commits is now the challenge.  thank you for your 
hints on git commit amend etc.


I hope to be back soon with a single commit...

ciao, Mario




Re: `with` as a list.

2020-05-30 Thread Mario Frasca

what's new …

edited the documentation string to `org-plot/zip-deps-with',

removed some redundancies there,

removed my ›zip‹ function, in favour of ›cl-mapcar 'cons‹,

simplified the double test `stringp', `string=' with `equal'.

simplified the unit tests correspondingly.

make test: no unexpected failing tests.

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..c44cca991 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -156,7 +156,8 @@ and dependent variables."
 			  table)))
 ;; write table to gnuplot grid datafile format
 (with-temp-file data-file
-  (let ((num-rows (length table)) (num-cols (length (nth 0 table)))
+  (let ((num-rows (length table))
+	(num-cols (length (nth 0 table)))
 	(gnuplot-row (lambda (col row value)
 			   (setf col (+ 1 col)) (setf row (+ 1 row))
 			   (format "%f  %f  %f\n%f  %f  %f\n"
@@ -179,6 +180,22 @@ and dependent variables."
 	  (setf back-edge "") (setf front-edge ""
 row-vals))
 
+(defun org-plot/zip-deps-with (num-cols ind deps with)
+  "Describe each column to be plotted as (col . with).
+Loops over DEPS and WITH in order to cons their elements.
+If the DEPS list of columns is not given, use all columns from 1
+to NUM-COLS, excluding IND.
+If WITH is given as a string, use the given value for all
+columns.
+If WITH is given as a list, and it's shorter than DEPS, expand it
+with the global default value."
+  (unless deps
+(setq deps (remove ind (number-sequence 1 num-cols
+  (unless (listp with)
+(setq with (make-list (length deps) with)))
+  (setq with (append with (make-list (- (length deps) (length with)) "lines")))
+  (cl-mapcar 'cons deps with))
+
 (defun org-plot/gnuplot-script (data-file num-cols params  preface)
   "Write a gnuplot script to DATA-FILE respecting the options set in PARAMS.
 NUM-COLS controls the number of columns plotted in a 2-d plot.
@@ -240,22 +257,24 @@ manner suitable for prepending to a user-specified script."
 			   "%Y-%m-%d-%H:%M:%S") "\"")))
 (unless preface
   (pcase type			; plot command
-	(`2d (dotimes (col num-cols)
-	   (unless (and (eq type '2d)
-			(or (and ind (equal (1+ col) ind))
-(and deps (not (member (1+ col) deps)
-		 (setf plot-lines
-		   (cons
-			(format plot-str data-file
-(or (and ind (> ind 0)
-	 (not text-ind)
-	 (format "%d:" ind)) "")
-(1+ col)
-(if text-ind (format ":xticlabel(%d)" ind) "")
-with
-(or (nth col col-labels)
-(format "%d" (1+ col
-			plot-lines)
+	(`2d (dolist
+		 (col-with
+		  (org-plot/zip-deps-with num-cols ind deps with))
+	   (setf plot-lines
+		 (cons
+		  (format plot-str data-file
+			  (or (and ind (> ind 0)
+   (not text-ind)
+   (format "%d:" ind)) "")
+			  (car col-with)
+			  (if text-ind (format ":xticlabel(%d)" ind) "")
+			  (cdr col-with)
+			  (apply (lambda (x)
+   (if (= 0 (length x))
+	   (format "%d" (car col-with))
+	 x))
+ (list (nth (1- (car col-with)) col-labels
+		  plot-lines
 	(`3d
 	 (setq plot-lines (list (format "'%s' matrix with %s title ''"
 	data-file with
@@ -310,7 +329,8 @@ line directly before or after the table."
 table data-file params)))
 		 (when y-labels (plist-put params :ylabels y-labels)
   ;; Check for timestamp ind column.
-  (let ((ind (1- (plist-get params :ind
+  (let ((ind (1- (plist-get params :ind)))
+	(with (plist-get params :with)))
 	(when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))
 	  (if (= (length
 		  (delq 0 (mapcar
@@ -320,7 +340,7 @@ line directly before or after the table."
 		 0)
 	  (plist-put params :timeind t)
 	;; Check for text ind column.
-	(if (or (string= (plist-get params :with) "hist")
+	(if (or (equal with "hist")
 		(> (length
 			(delq 0 (mapcar
  (lambda (el)
diff --git a/testing/lisp/test-org-plot.el b/testing/lisp/test-org-plot.el
new file mode 100644
index 0..2bbd09b5f
--- /dev/null
+++ b/testing/lisp/test-org-plot.el
@@ -0,0 +1,50 @@
+;;; test-org-plot.el --- Tests for org-plot.el
+
+;; Copyright (C) 2020  Mario Frasca
+
+;; Author: Mario Frasca 
+
+;; Released under the GNU General Public License version 3
+;; see: http://www.gnu.org/licenses/gpl-3.0.html
+
+ Comments
+
+
+
+;;; Code:
+
+(require 'org-test)
+(require 'org-plot)
+
+
+;; General auxiliaries
+
+(ert-deftest test-org-plot/zip-deps-with ()
+  "Test `org-plot/zip-deps-with' specifications."
+  ;; no deps, no with. defaults to all except ind, and "lines"
+  (should
+   (equal (org-plot/zip-deps-with 3 1 nil nil)
+	  '((2 . "lines") (3 . "lines"
+  ;;

Re: `with` as a list.

2020-05-30 Thread Mario Frasca

On 30/05/2020 09:23, Mario Frasca wrote:

The code above looks fine to me.  Another option would be to use
number-sequence and then filter out the ind value.


no, that would break functionality: I need to keep the given order.
ah, no, sorry, you are totally right here.  I'll see if using 
number-sequence makes the code shorter.


Re: `with` as a list.

2020-05-30 Thread Mario Frasca

Hi Kyle,

thank you for writing back, I have a couple of questions in reply.

btw. are you on irc.freenode.net?  I'm `mariotomo' there.  and I just 
joined `#org-mode'.  I don't think that my terminal will ring a bell if 
I'm mentioned there.


On 30/05/2020 01:22, Kyle Meyer wrote:

Mario Frasca writes:


[…]

Thanks for the patch and for clearly describing the motivation.  I'm not
an org-plot user, but the change sounds useful.  (It'd be great if
org-plot users could chime in.)


thank you for taking the time to review!



Two meta-comments:

   * Please provide a patch with a commit message.  See
 <https://orgmode.org/worg/org-contribute.html> for more information.

   * The link above also explains the copyright assignment requirement
 for contributions.  Please consider assigning copyright to the FSF.


I'm editing in my cloned repository, and committing often, so I do not 
have a single commit, consequently also not a single commit message.


I just sent my form request to ass...@gnu.org.



diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..87a415137 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -179,6 +179,28 @@ and dependent variables."
  (setf back-edge "") (setf front-edge ""
  row-vals))
  
+(defun org-plot/zip-deps-with (num-cols ind deps with)

+  "describe each column to be plotted as (col . with)"

This doesn't match the convention used in this code base for docstrings.
Taking a look around should give you a good sense, but (1) the first
word should be capitalized, (2) sentences should end with a period, and
(3) ideally all parameters should be described in the docstring.


ok, 1 and 2 are just consequence of my usual way of typing, however 
wrong, I will fix them.  3 I didn't consider.  useful point.






+  ;; make 'deps explicit

I think this and the other comments in this function could safely be
dropped.


:+1:



+  (unless deps
+(setf deps (let (r)
+(dotimes (i num-cols r)
+  (unless (eq num-cols (+ ind i))
+(setq r (cons (- num-cols i) r)))

[…] using setq unless setf is needed would be more
consistent with this code base.


the "unless needed" makes me suspect I should read what's the difference.



The code above looks fine to me.  Another option would be to use
number-sequence and then filter out the ind value.


no, that would break functionality: I need to keep the given order.

btw my patch allows you to use the same column more than once.





+  ;; invoke zipping function on converted data
+  (org-plot/zip deps with))
+
+(defun org-plot/zip (xs ys)
+  (unless
+  (null xs)
+(cons (cons (car xs) (or (car ys) "lines"))

Is the "lines" fall back ever reached?  It looks like you're extending
`with' above to be the same length as `deps`.


it is needed: I'm not extending any `with' given as a non-empty list.

but I should be using some settings, some global default `with' value, 
which I don't know where to find.  hard coding "lines" can't be the 
right thing to do.



+ (org-plot/zip (cdr xs) (cdr ys)

In Elisp, it's not very common to use recursive functions (and there's
no TCO).  In the case of zipping two lists, I think it'd probably be
easiest to just use cl-loop.  And in my view having a separate function
here is probably an overkill.


I'm not sure about the TCO (in other words: I haven't the faintest idea 
what you mean by that), and I would not know how to write this using 
`cl-loop'.  I'll have a look though.




  (defun org-plot/gnuplot-script (data-file num-cols params  preface)
"Write a gnuplot script to DATA-FILE respecting the options set in PARAMS.
  NUM-COLS controls the number of columns plotted in a 2-d plot.
@@ -240,22 +262,22 @@ manner suitable for prepending to a user-specified 
script."
   "%Y-%m-%d-%H:%M:%S") "\"")))
  (unless preface
(pcase type ; plot command
-   (`2d (dotimes (col num-cols)
-  (unless (and (eq type '2d)
-   (or (and ind (equal (1+ col) ind))
-   (and deps (not (member (1+ col) deps)
-(setf plot-lines
-  (cons
-   (format plot-str data-file
-   (or (and ind (> ind 0)
-(not text-ind)
-(format "%d:" ind)) "")
-   (1+ col)
-   (if text-ind (format ":xticlabel(%d)" ind) "")
-   with
-   (or (nth col col-labels)
-   (format "%d" (1+ col
-   plot-lines)
+   

[PATCH] [FEATURE] Re: `with` as a list.

2020-05-28 Thread Mario Frasca
I have added a couple of unit tests to the suite, describing the two 
functions I added.  I have no unexpectedly failing tests now.


I'm explicitly cc-ing Eric Schulte because he's in the header for 
org-plot.el, and —missing the unit tests for that source— I hope he can 
assist me not breaking what he wrote.  … I guess I can write also test 
cases for what already exists, but I will very likely need assistance.


best regards,
Mario Frasca

On 22/05/2020 11:07, Mario Frasca wrote:

good day to you all

now and then I use emacs to make graphs.  now recently I was plotting 
point data, and a running average "fit", so I wanted to have points, 
and lines, which I know it's possible in `gnuplot` but now how do I do 
that from org-plot …


I wrote a small patch for org-plot.el, I'm not a Lisp programmer so 
I'm sure the patch looks terrible, but it does allow me to do this:


#+PLOT: ind:1 deps:(3 6 4 7) with:(points lines points lines)

it's two additions:

1. it lets me specify the order in which the dependent columns should 
be considered.


2. it lets me specify a different `with` for each column, in the same 
order.


if you leave the `with` away, you get "lines" for all columns.

if you specify only one `with` value, that value is used for all columns.

if you specify more `deps` than `with`, the ones not specified will 
get "lines".


if you specify more `with` than `deps`, they are ignored.

I ran the tests, and I get two failing ones, quite unrelated according 
to me:


2 unexpected results:
   FAILED  ob-exp/evaluate-all-executables-in-order
   FAILED  ob-exp/export-call-line-information

I have not defined test cases for the new behaviour, I'm willing to do 
that (learning the way this test environment works), but I don't find 
the location of the other tests related to the area of the program, 
which I'm tweaking.


best regards all,

Mario Frasca

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..524615d98 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -179,6 +179,28 @@ and dependent variables."
 	  (setf back-edge "") (setf front-edge ""
 row-vals))
 
+(defun org-plot/zip-deps-with (num-cols ind deps with)
+  "describe each column to be plotted as (col . with)"
+  ;; make 'deps explicit
+  (unless deps
+(setf deps (let (r)
+		 (dotimes (i num-cols r)
+		   (unless (eq num-cols (+ ind i))
+		 (setq r (cons (- num-cols i) r)))
+  ;; make sure 'with matches 'deps
+  (unless with
+(setf with "lines"))
+  (unless (listp with)
+(setf with (make-list (length deps) with)))
+  ;; invoke zipping function on converted data
+  (org-plot/zip deps with))
+
+(defun org-plot/zip (xs ys)
+  (unless
+  (null xs)
+(cons (cons (car xs) (or (car ys) "lines"))
+	  (org-plot/zip (cdr xs) (cdr ys)
+
 (defun org-plot/gnuplot-script (data-file num-cols params  preface)
   "Write a gnuplot script to DATA-FILE respecting the options set in PARAMS.
 NUM-COLS controls the number of columns plotted in a 2-d plot.
@@ -240,22 +262,24 @@ manner suitable for prepending to a user-specified script."
 			   "%Y-%m-%d-%H:%M:%S") "\"")))
 (unless preface
   (pcase type			; plot command
-	(`2d (dotimes (col num-cols)
-	   (unless (and (eq type '2d)
-			(or (and ind (equal (1+ col) ind))
-(and deps (not (member (1+ col) deps)
-		 (setf plot-lines
-		   (cons
-			(format plot-str data-file
-(or (and ind (> ind 0)
-	 (not text-ind)
-	 (format "%d:" ind)) "")
-(1+ col)
-(if text-ind (format ":xticlabel(%d)" ind) "")
-with
-(or (nth col col-labels)
-(format "%d" (1+ col
-			plot-lines)
+	(`2d (dolist
+		 (col-with
+		  (org-plot/zip-deps-with num-cols ind deps with))
+	   (setf plot-lines
+		 (cons
+		  (format plot-str data-file
+			  (or (and ind (> ind 0)
+   (not text-ind)
+   (format "%d:" ind)) "")
+			  (car col-with)
+			  (if text-ind (format ":xticlabel(%d)" ind) "")
+			  (cdr col-with)
+			  (apply (lambda (x)
+   (if (= 0 (length x))
+	   (format "%d" (car col-with))
+	 x))
+ (list (nth (1- (car col-with)) col-labels
+		  plot-lines
 	(`3d
 	 (setq plot-lines (list (format "'%s' matrix with %s title ''"
 	data-file with
@@ -310,7 +334,8 @@ line directly before or after the table."
 table data-file params)))
 		 (when y-labels (plist-put params :ylabels y-labels)
   ;; Check for timestamp ind column.
-  (let ((ind (1- (plist-get params :ind
+  (let ((ind (1- (plist-get params :ind)))
+	(with (plist-get params :with)))
 	(when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))
 	  (if (= (length
 		  (delq 0 (mapcar
@@ -320,

Re: issue tracker?

2020-05-27 Thread Mario Frasca
myself, I recently posted a patch, received zero reaction, and have the 
impression it's now lost in the logs of this mailing list.  indeed 
pretty inefficient!


something which flashed to my mind while writing this email: we're 
dealing with an emacs software, part of emacs, can we just use M-x 
report-emacs-bug?


cheers, MF

On 19/05/2020 09:58, Bruce D'Arcus wrote:
Regardless, doing issue tracking, discussion, and patch submission on 
a ML in 2020 is pretty odd and inefficient.


I would have submitted feedback here 6-12 months earlier than I did if 
org had a proper issue tracker.




`with` as a list.

2020-05-22 Thread Mario Frasca

good day to you all

now and then I use emacs to make graphs.  now recently I was plotting 
point data, and a running average "fit", so I wanted to have points, and 
lines, which I know it's possible in `gnuplot` but now how do I do that 
from org-plot …


I wrote a small patch for org-plot.el, I'm not a Lisp programmer so I'm 
sure the patch looks terrible, but it does allow me to do this:


#+PLOT: ind:1 deps:(3 6 4 7) with:(points lines points lines)

it's two additions:

1. it lets me specify the order in which the dependent columns should be 
considered.


2. it lets me specify a different `with` for each column, in the same order.

if you leave the `with` away, you get "lines" for all columns.

if you specify only one `with` value, that value is used for all columns.

if you specify more `deps` than `with`, the ones not specified will get 
"lines".


if you specify more `with` than `deps`, they are ignored.

I ran the tests, and I get two failing ones, quite unrelated according 
to me:


2 unexpected results:
   FAILED  ob-exp/evaluate-all-executables-in-order
   FAILED  ob-exp/export-call-line-information

I have not defined test cases for the new behaviour, I'm willing to do 
that (learning the way this test environment works), but I don't find 
the location of the other tests related to the area of the program, 
which I'm tweaking.


best regards all,

Mario Frasca

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index a23195d2a..87a415137 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -179,6 +179,28 @@ and dependent variables."
 	  (setf back-edge "") (setf front-edge ""
 row-vals))
 
+(defun org-plot/zip-deps-with (num-cols ind deps with)
+  "describe each column to be plotted as (col . with)"
+  ;; make 'deps explicit
+  (unless deps
+(setf deps (let (r)
+		 (dotimes (i num-cols r)
+		   (unless (eq num-cols (+ ind i))
+		 (setq r (cons (- num-cols i) r)))
+  ;; make sure 'with matches 'deps
+  (unless with
+(setf with "lines"))
+  (unless (listp with)
+(setf with (mapcar (lambda (x) with) deps)))
+  ;; invoke zipping function on converted data
+  (org-plot/zip deps with))
+
+(defun org-plot/zip (xs ys)
+  (unless
+  (null xs)
+(cons (cons (car xs) (or (car ys) "lines"))
+	  (org-plot/zip (cdr xs) (cdr ys)
+
 (defun org-plot/gnuplot-script (data-file num-cols params  preface)
   "Write a gnuplot script to DATA-FILE respecting the options set in PARAMS.
 NUM-COLS controls the number of columns plotted in a 2-d plot.
@@ -240,22 +262,22 @@ manner suitable for prepending to a user-specified script."
 			   "%Y-%m-%d-%H:%M:%S") "\"")))
 (unless preface
   (pcase type			; plot command
-	(`2d (dotimes (col num-cols)
-	   (unless (and (eq type '2d)
-			(or (and ind (equal (1+ col) ind))
-(and deps (not (member (1+ col) deps)
-		 (setf plot-lines
-		   (cons
-			(format plot-str data-file
-(or (and ind (> ind 0)
-	 (not text-ind)
-	 (format "%d:" ind)) "")
-(1+ col)
-(if text-ind (format ":xticlabel(%d)" ind) "")
-with
-(or (nth col col-labels)
-(format "%d" (1+ col
-			plot-lines)
+	(`2d (dolist
+		 (col-with
+		  (org-plot/zip-deps-with num-cols ind deps with))
+	   (setf plot-lines
+		 (cons
+		  (format plot-str data-file
+			  (or (and ind (> ind 0)
+   (not text-ind)
+   (format "%d:" ind)) "")
+			  (car col-with)
+			  (if text-ind (format ":xticlabel(%d)" ind) "")
+			  (cdr col-with)
+			  (or (nth (1- (car col-with))
+   col-labels)
+  (format "%d" (car col-with
+		  plot-lines
 	(`3d
 	 (setq plot-lines (list (format "'%s' matrix with %s title ''"
 	data-file with
@@ -310,7 +332,8 @@ line directly before or after the table."
 table data-file params)))
 		 (when y-labels (plist-put params :ylabels y-labels)
   ;; Check for timestamp ind column.
-  (let ((ind (1- (plist-get params :ind
+  (let ((ind (1- (plist-get params :ind)))
+	(with (plist-get params :with)))
 	(when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))
 	  (if (= (length
 		  (delq 0 (mapcar
@@ -320,7 +343,7 @@ line directly before or after the table."
 		 0)
 	  (plist-put params :timeind t)
 	;; Check for text ind column.
-	(if (or (string= (plist-get params :with) "hist")
+	(if (or (and (stringp with) (string= with "hist"))
 		(> (length
 			(delq 0 (mapcar
  (lambda (el)


Re: [O] better interaction with gnuplot-mode

2014-11-08 Thread Mario Frasca
On 11/04/2014 10:33 AM, Nicolas Goaziou wrote:
 Mario Frasca mariot...@gmail.com writes:
 
 being the comment in the subject field of an email, it can't be a
 multiline comment, can it?
 
 First line is a summary and cannot exceed 72 (or is it 68? I cannot
 remember) characters. You need to start with a capital but do not end
 with a period.

the output of the script I used to produce the patch was an email, the
ones I included. and my comment went into the subject of the email. I'm
afraid I still don't see how to specify a multi-line comment in the
subject of an email.

but we are circumventing it here, so let's see if I manage to respect
the orgmode rules...

-
Reset gnuplot process instead of killing it

TINYCHANGE. org-plot.el (org-plot/gnuplot): Without this patch, the
gnuplot process associated to the gnuplot buffer is killed before each
batch of instructions from orgmode to gnuplot. With or without this
patch, orgmode sends a reset instruction to the gnuplot process as first
instruction.

-
Correction in callback registration

TINYCHANGE org-plot.el (org-plot/gnuplot): The data-file variable is not
in the scope of the callback, one needs to grab its value while
registering the callback. With this patch the timer is set as soon as
the file is created. Without this patch the timer is set at the end of a
let-block, if anything goes wrong in the let-block before the timer is
set, the file will not be removed.
-




signature.asc
Description: OpenPGP digital signature


[O] better interaction with gnuplot-mode

2014-11-02 Thread Mario Frasca
a couple of weeks ago I decided I would use emacs for my spreadsheets. I
first tried with `ses`, then I was pointed at the spreadsheet
capabilities of org-mode. but I also needed to see a graph
representation of the data.

http://stackoverflow.com/questions/26614536/

tables in org-mode work really nice, but I wanted the resulting graph in
an emacs buffer, and in svg format. so I first ask the developer of
gnuplot-mode about it and we (well, actually _he_) came with a couple of
small edits that permit this.

https://github.com/bruceravel/gnuplot-mode/issues/20

during the process we found two spots in org-plot/gnuplot that we think
are in need of editing.

one is relative to the cleaning up of the temporary files.
the other is relative to killing (or not) the gnuplot process.

the patches are attached.

the discussion is in the issue:20 of
https://github.com/bruceravel/gnuplot-mode/

MF

From be72bf875a9abd64869f1c0bd1c6ad50fa93e514 Mon Sep 17 00:00:00 2001
From: Mario Frasca mrgsfra...@gmail.com
Date: Sun, 2 Nov 2014 08:53:27 -0500
Subject: [PATCH 2/2] correct the callback for the  and register it as soon as
 possible.

---
 lisp/org-plot.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 69d9250..faa34fc 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -294,6 +294,7 @@ line directly before or after the table.
 	   (table (org-table-to-lisp))
 	   (num-cols (length (if (eq (first table) 'hline) (second table)
 			   (first table)
+  (run-with-idle-timer 0.1 nil #'delete-file data-file)
   (while (equal 'hline (first table)) (setf table (cdr table)))
   (when (equal (second table) 'hline)
 	(setf params (plist-put params :labels (first table))) ;; headers to labels
@@ -344,8 +345,7 @@ line directly before or after the table.
 	(gnuplot-mode)
 	(gnuplot-send-buffer-to-gnuplot))
   ;; cleanup
-  (bury-buffer (get-buffer *gnuplot*))
-  (run-with-idle-timer 0.1 nil (lambda () (delete-file data-file))
+  (bury-buffer (get-buffer *gnuplot*)
 
 (provide 'org-plot)
 
-- 
1.9.1


From ebd2cd9b23138a39ad9ea4b517934c93757c2b4d Mon Sep 17 00:00:00 2001
From: Mario Frasca mrgsfra...@gmail.com
Date: Sun, 2 Nov 2014 08:50:47 -0500
Subject: [PATCH 1/2] do not kill the gnuplot process. just jump to end of
 buffer and rely on  command to do the resetting job.

---
 lisp/org-plot.el | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 556b9ef..69d9250 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -281,8 +281,7 @@ line directly before or after the table.
 (delete-other-windows)
 (when (get-buffer *gnuplot*) ;; reset *gnuplot* if it already running
   (with-current-buffer *gnuplot*
-	(goto-char (point-max))
-	(gnuplot-delchar-or-maybe-eof nil)))
+	(goto-char (point-max
 (org-plot/goto-nearest-table)
 ;; set default options
 (mapc
-- 
1.9.1




signature.asc
Description: OpenPGP digital signature


[O] better interaction with gnuplot-mode

2014-11-02 Thread Mario Frasca
a couple of weeks ago I decided I would use emacs for my spreadsheets. I
first tried with `ses`, then I was pointed at the spreadsheet
capabilities of org-mode. but I also needed to see a graph
representation of the data.

http://stackoverflow.com/questions/26614536/

tables in org-mode work really nice, but I wanted the resulting graph in
an emacs buffer, and in svg format. so I first ask the developer of
gnuplot-mode about it and we (well, actually _he_) came with a couple of
small edits that permit this.

https://github.com/bruceravel/gnuplot-mode/issues/20

during the process we found two spots in org-plot/gnuplot that we think
are in need of editing.

one is relative to the cleaning up of the temporary files.
the other is relative to killing (or not) the gnuplot process.

the patches are attached.

the discussion is in the issue:20 of
https://github.com/bruceravel/gnuplot-mode/

MF
From be72bf875a9abd64869f1c0bd1c6ad50fa93e514 Mon Sep 17 00:00:00 2001
From: Mario Frasca mrgsfra...@gmail.com
Date: Sun, 2 Nov 2014 08:53:27 -0500
Subject: [PATCH 2/2] correct the callback for the  and register it as soon as
 possible.

---
 lisp/org-plot.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 69d9250..faa34fc 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -294,6 +294,7 @@ line directly before or after the table.
 	   (table (org-table-to-lisp))
 	   (num-cols (length (if (eq (first table) 'hline) (second table)
 			   (first table)
+  (run-with-idle-timer 0.1 nil #'delete-file data-file)
   (while (equal 'hline (first table)) (setf table (cdr table)))
   (when (equal (second table) 'hline)
 	(setf params (plist-put params :labels (first table))) ;; headers to labels
@@ -344,8 +345,7 @@ line directly before or after the table.
 	(gnuplot-mode)
 	(gnuplot-send-buffer-to-gnuplot))
   ;; cleanup
-  (bury-buffer (get-buffer *gnuplot*))
-  (run-with-idle-timer 0.1 nil (lambda () (delete-file data-file))
+  (bury-buffer (get-buffer *gnuplot*)
 
 (provide 'org-plot)
 
-- 
1.9.1

From ebd2cd9b23138a39ad9ea4b517934c93757c2b4d Mon Sep 17 00:00:00 2001
From: Mario Frasca mrgsfra...@gmail.com
Date: Sun, 2 Nov 2014 08:50:47 -0500
Subject: [PATCH 1/2] do not kill the gnuplot process. just jump to end of
 buffer and rely on  command to do the resetting job.

---
 lisp/org-plot.el | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 556b9ef..69d9250 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -281,8 +281,7 @@ line directly before or after the table.
 (delete-other-windows)
 (when (get-buffer *gnuplot*) ;; reset *gnuplot* if it already running
   (with-current-buffer *gnuplot*
-	(goto-char (point-max))
-	(gnuplot-delchar-or-maybe-eof nil)))
+	(goto-char (point-max
 (org-plot/goto-nearest-table)
 ;; set default options
 (mapc
-- 
1.9.1



signature.asc
Description: OpenPGP digital signature