From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id zkEUE/GD0l4IZgAA0tVLHw (envelope-from ) for ; Sat, 30 May 2020 16:04:01 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id AAeQDvGD0l57OQAAbx9fmQ (envelope-from ) for ; Sat, 30 May 2020 16:04:01 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 30A9C9404DF for ; Sat, 30 May 2020 16:04:00 +0000 (UTC) Received: from localhost ([::1]:46186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jf3xl-0004ie-JR for larch@yhetil.org; Sat, 30 May 2020 12:03:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jf3vx-0003z4-LG for emacs-orgmode@gnu.org; Sat, 30 May 2020 12:02:05 -0400 Received: from confino.investici.org ([2a00:c38:11e:ffff::a020]:30747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jf3vu-0005sH-P7 for emacs-orgmode@gnu.org; Sat, 30 May 2020 12:02:05 -0400 Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 8BD3421226; Sat, 30 May 2020 16:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anche.no; s=stigmate; t=1590854518; bh=llaBPVJiYMpg3+mPe0Kn2rMgBHGoEgWbdFytfpdYGmU=; h=Subject:To:References:From:Date:In-Reply-To:From; b=Er/bpx8ZVdZlVFKd5olrgSG/OrFjv1TXrogmXU4lM6KOmYTleL7/tPWvqP7EO2w5g IbQht3abvgYPtcQuqUWSB9iXI4hnkv9cJDzhsK17hVDRW/rFpulUFF+0KTwTOqhoCh amEZ5sPqXFwcwr0Tg8WvzPZSBoQn2jaxGkpu7ghE= Received: from [212.103.72.250] (mx1.investici.org [212.103.72.250]) (Authenticated sender: mariotomo@inventati.org) by localhost (Postfix) with ESMTPSA id 30A4321225; Sat, 30 May 2020 16:01:56 +0000 (UTC) Subject: Re: `with` as a list. To: Kyle Meyer , emacs-orgmode@gnu.org References: <656b815f-9e38-e68c-b7a3-091f6f3d36bf@anche.no> <87tuzyueli.fsf@kyleam.com> From: Mario Frasca Message-ID: Date: Sat, 30 May 2020 11:01:51 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <87tuzyueli.fsf@kyleam.com> Content-Type: multipart/mixed; boundary="------------12530657DD33EC9D9F21DE0B" Content-Language: en-US Received-SPF: pass client-ip=2a00:c38:11e:ffff::a020; envelope-from=mario@anche.no; helo=confino.investici.org X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=anche.no header.s=stigmate header.b=Er/bpx8Z; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: hTzpqwxTCMPy This is a multi-part message in MIME format. --------------12530657DD33EC9D9F21DE0B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. --------------12530657DD33EC9D9F21DE0B Content-Type: text/x-patch; charset=UTF-8; name="org-plot.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="org-plot.diff" 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 &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. @@ -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 000000000..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")))) + ;; 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")))) + ;; 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 --------------12530657DD33EC9D9F21DE0B--