emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] implementing `with' as a list, and respecting `deps' order.
@ 2020-06-02 15:57 Mario Frasca
  2020-06-03  3:38 ` Kyle Meyer
  0 siblings, 1 reply; 5+ messages in thread
From: Mario Frasca @ 2020-06-02 15:57 UTC (permalink / raw)
  To: emacs-orgmode

 From 436bfd0b9fd656f52ea9d7e6a6a665a32564ae93 Mon Sep 17 00:00:00 2001
From: Mario Frasca <mario@anche.no>
Date: Tue, 2 Jun 2020 15:46:20 +0000
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 &optional 
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 ((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 000000000..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 <mario at anche dot no>
+
+;; 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)
+
+\f
+;; 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")))))
+
+
+\f
+(provide 'test-org-plot)
+;;; test-org-plot.el end here
-- 
2.20.1




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] implementing `with' as a list, and respecting `deps' order.
  2020-06-02 15:57 [PATCH] implementing `with' as a list, and respecting `deps' order Mario Frasca
@ 2020-06-03  3:38 ` Kyle Meyer
  2020-06-03 14:46   ` Mario Frasca
  0 siblings, 1 reply; 5+ messages in thread
From: Kyle Meyer @ 2020-06-03  3:38 UTC (permalink / raw)
  To: Mario Frasca, emacs-orgmode

Mario Frasca writes:

>  From 436bfd0b9fd656f52ea9d7e6a6a665a32564ae93 Mon Sep 17 00:00:00 2001
> From: Mario Frasca <mario@anche.no>
> Date: Tue, 2 Jun 2020 15:46:20 +0000
> 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 "<file|area>: " 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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] implementing `with' as a list, and respecting `deps' order.
  2020-06-03  3:38 ` Kyle Meyer
@ 2020-06-03 14:46   ` Mario Frasca
  2020-06-03 15:03     ` Bastien
  2020-06-03 23:50     ` Kyle Meyer
  0 siblings, 2 replies; 5+ messages in thread
From: Mario Frasca @ 2020-06-03 14:46 UTC (permalink / raw)
  To: Kyle Meyer, emacs-orgmode

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 <mario@anche.no>
>> Date: Tue, 2 Jun 2020 15:46:20 +0000
>> 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 "<file|area>: " 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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] implementing `with' as a list, and respecting `deps' order.
  2020-06-03 14:46   ` Mario Frasca
@ 2020-06-03 15:03     ` Bastien
  2020-06-03 23:50     ` Kyle Meyer
  1 sibling, 0 replies; 5+ messages in thread
From: Bastien @ 2020-06-03 15:03 UTC (permalink / raw)
  To: Mario Frasca; +Cc: emacs-orgmode

Dear Mario,

Mario Frasca <mario@anche.no> writes:

> 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.  

I added this line to org-contribute.html:

  "To finally send the patches, you can either add them as attachments
  to your email, or use git send-email, if it's properly configured."

> the procedure mentioned there guides me in creating several patch
> files, one per commit.  

Yes, you can do that.

> 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.

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] implementing `with' as a list, and respecting `deps' order.
  2020-06-03 14:46   ` Mario Frasca
  2020-06-03 15:03     ` Bastien
@ 2020-06-03 23:50     ` Kyle Meyer
  1 sibling, 0 replies; 5+ messages in thread
From: Kyle Meyer @ 2020-06-03 23:50 UTC (permalink / raw)
  To: Mario Frasca; +Cc: emacs-orgmode

Mario Frasca writes:

> comments on the html page org-contribute.html:
[...]
> 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.

My suggestion to you in the original thread [*] was in the context of
updating a patch you sent based on reviewer feedback.  The instructions
on the org-contribute page are in the context of sending an initial
series to the list, providing a two-patch series as an example.  These
are distinct things.

If the change you're proposing conceptually fits into several commits
(of course, how to divide things up is a subjective art), then please do
so.  As I said in the original thread:

  Just for clarity: In this case, I think the change proposed so far makes
  sense to present as a single commit.  I'm not claiming that in general a
  patch series should be reduced to _one_ commit.

I don't doubt that my descriptions or org-contribute's could be clearer.
Suggestions on how to improve the org-contribute page are of course
welcome, though I think it'd be a mistake to turn it into a Git
tutorial.


[*] https://yhetil.org/orgmode/874krvvdr3.fsf@kyleam.com/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-03 23:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 15:57 [PATCH] implementing `with' as a list, and respecting `deps' order Mario Frasca
2020-06-03  3:38 ` Kyle Meyer
2020-06-03 14:46   ` Mario Frasca
2020-06-03 15:03     ` Bastien
2020-06-03 23:50     ` Kyle Meyer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).