From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SLJbMWrB0l44WgAA0tVLHw (envelope-from ) for ; Sat, 30 May 2020 20:26:18 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id aONjLWrB0l4GbAAA1q6Kng (envelope-from ) for ; Sat, 30 May 2020 20:26:18 +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 4390894038F for ; Sat, 30 May 2020 20:26:18 +0000 (UTC) Received: from localhost ([::1]:40336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jf83d-0000KG-7j for larch@yhetil.org; Sat, 30 May 2020 16:26:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jf834-0000Ji-Sg for emacs-orgmode@gnu.org; Sat, 30 May 2020 16:25:43 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:65020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jf832-0004mo-Gc for emacs-orgmode@gnu.org; Sat, 30 May 2020 16:25:42 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 106C1C8FCB; Sat, 30 May 2020 16:25:39 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:in-reply-to:date:message-id:mime-version:content-type; s=sasl; bh=854K4+gVmAoU1dtRBUBSMl0IB4w=; b=SbnTl9pfHZ09MLzh4pPE ojqql6KXLsmS6LDsOtautShhGDz18CyxNTjm8eAYkWE/9/isCOi0tjRZqjUfYAA5 vClohONEyx4VAghk+201MbgJ+9YFgpLwMzXMepuYqyIkc8FZbbSj93A789gkw5uV arLl9Esv/aO3SqbIBHHt5Rw= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 0825DC8FCA; Sat, 30 May 2020 16:25:39 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:in-reply-to:date:message-id:mime-version:content-type; s=mesmtp; bh=4RQZE4CLu8Jw2xmIhxnXsBROqZav0yz4ucvYzOFiBdI=; b=LZ+xWa+a6JLn5S0CrUEq/pDH/WKQ0P9gDM0vsku55pc6EO5GaLN3viqa/DOk9IlyXmt2254huFEl6sFuwf1X3vxm2AMl99CrEruIShibhk2QUfr2JaBEWFdkzEr/vN7mMUlt0q5nFiWaK6DGtDlHKkpvaO3LzdqFvnQLClwNS/g= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 6FCFBC8FC0; Sat, 30 May 2020 16:25:36 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Mario Frasca Subject: Re: `with` as a list. In-Reply-To: Date: Sat, 30 May 2020 20:25:34 +0000 Message-ID: <87ftbhuq4h.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: B86568C8-A2B3-11EA-8320-8D86F504CC47-24757444!pb-smtp21.pobox.com Received-SPF: pass client-ip=173.228.157.53; envelope-from=kyle@kyleam.com; helo=pb-smtp21.pobox.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/30 16:25:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=SbnTl9pf; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=LZ+xWa+a; 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: -1.21 X-TUID: gghnrcp2ZvDh Mario Frasca writes: > 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))) I don't disagree with the style preference here, but it's easier on reviewers if the patch doesn't contain unrelated changes. > (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." Thanks for updating the docstring. > + (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"))) The caller can crash this with something like make-list(-1 "lines") (append with (make-list (- (length deps) (length with)) "lines")) (setq with (append with (make-list (- (length deps) (length with)) "lines"))) org-plot/zip-deps-with(3 1 (2 3) (lines points lines)) [...] if they accidentally give more `with` values than `deps`. Also, if the `(unless (listp with) ...` condition is entered, I think the second make-list call is unnecessary. So, combining those two points, perhaps something like this: (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)) Nit-pick: s/'/#'/ The latter is short for `function' and, unlike the former, lets the byte-compiler know that cons is a function (enabling a warning if, say, you accidentally typed `conss`). > (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)))) If I'm reading it correctly, (apply ...) could be simplified to (or (nth (1- (car col-with)) col-labels) (format "%d" (car col-with))) > 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 Could you update this header to match the style used by other tests (see, e.g., test-org-num.el)? Tests themselves look good to me. Thanks for adding them. I think it'd also be good to add a test for the with-longer-than-deps case I mentioned above. The manual should also be updated to mention this new feature, and it'd be good to have an ORG-NEWS entry. Thanks for working on this.