From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id mPecAM44O2P7NQAAbAwnHQ (envelope-from ) for ; Mon, 03 Oct 2022 21:32:30 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 8C1vO804O2O2KwAAG6o9tA (envelope-from ) for ; Mon, 03 Oct 2022 21:32:29 +0200 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 897F0276B3 for ; Mon, 3 Oct 2022 21:32:29 +0200 (CEST) Received: from localhost ([::1]:46532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofRAy-0008UZ-Jw for larch@yhetil.org; Mon, 03 Oct 2022 15:32:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofR8M-0008Ih-Uo for emacs-orgmode@gnu.org; Mon, 03 Oct 2022 15:29:46 -0400 Received: from mail.hostpark.net ([212.243.197.30]:47074) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofR8K-0003I5-Rg for emacs-orgmode@gnu.org; Mon, 03 Oct 2022 15:29:46 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 6E3EE16550 for ; Mon, 3 Oct 2022 21:29:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bernoul.li; h= content-type:content-type:mime-version:message-id:date:date :subject:subject:from:from:received:received; s=sel2011a; t= 1664825380; bh=o5pNn7iNB3g0h/cRrAuXEDgY0N5lXOJ1HDFKxNCN964=; b=F POMW8c6ROte23oy6PvcnALj8Dzr+yOkqZRG3vCV6xo8HnIRemNeqDfmcTVz99epQ 900ktAaclCbK+Cu73E+rhENTH+LNEwSBTy2gXJWFZojXsU1RydLwZlYAt6ZrOww6 Mm8kwCkUh8b1YLA0eVFsXJd8ChTbz9cyI+ASCq1ack= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail1.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id V9GBs22mlrIu for ; Mon, 3 Oct 2022 21:29:40 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id 42BFD162BF for ; Mon, 3 Oct 2022 21:29:40 +0200 (CEST) From: Jonas Bernoulli To: emacs-orgmode@gnu.org Subject: Post-process table without changing result for empty table(/list) Date: Mon, 03 Oct 2022 21:29:39 +0200 Message-ID: <871qrovh7g.fsf@bernoul.li> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: none client-ip=212.243.197.30; envelope-from=jonas@bernoul.li; helo=mail.hostpark.net 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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 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-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664825549; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=APwQjK+Da6cCDsvYx7mCz0dy0ls9jtPw93T8NZhY+ks=; b=qJCNxGvVtKJTZUl0AkUTAbz5OsNY7DfF18bPzy6YSauA6161RO3JIs2wm0QpTOEMziH3NZ 3sGYidONgI1gvwgqj3fBQkQphtL3PZ0B3th7QXzb5zdNGkjwUT4UbHF1ajdRBypxbImMO1 yIILDKlnD4YMV4NGzhEhN27+QKgvddq5Cc0DwePZQlJwBixFv1aCJaBLfdCTRPmoreu3gy 0nym+sFjXj/EeRQXo0sO5Zp4LoTjCSXyRui4Ah0y5wOe+/qirh5AUSRJ8kpeMU1nYBiS5r U8r/Cuw/ZYt+U03iROWbDy1H2yuCpqZCOwvxyscCUCzGT3bHVFum0vtZjGWfrg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664825549; a=rsa-sha256; cv=none; b=bv8vFjRa09unHg+ccO/IgkcRIwOHS3M6X+u4nVVGALPWsfdvzq7NL2xowfEEijEWV7uxh1 nng+Hp6lvCJ5kkJ5H0O36WSf5UHkBC4bYXjzqyj6/8dxzjBRE7o50Tql65Sy7be13nTD5M 2IywODYIhjcvQ3W8hSPkoTeYqZSftIVNz/WSCPlCYz/ZfLsYWLZ59lRrNr/zkjM31XdEkN DO4AsBO4l8iodLLhyF5ydsWPIros4+5nkRxxbwQ4M3LbH7GJIVd1NK3cfkeLFkbbpYSEL/ x/dIXkTnUs7zSiL2yn7zZcRZ5jnlW0s34MJZmlLL3MFjwye5LbJb3XHhQehnWQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=bernoul.li header.s=sel2011a header.b="F POMW8c"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.46 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=bernoul.li header.s=sel2011a header.b="F POMW8c"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 897F0276B3 X-Spam-Score: -3.46 X-Migadu-Scanner: scn1.migadu.com X-TUID: QS+JDCGw7plI Hello, If a code-block that is supposed to produce a table returns an empty list, then nothing at all is inserted, as demonstrated by the second example below: #+begin_src emacs-lisp :results table ;; Some sql query that returns one or more rows: '(("foo" "bar")) #+end_src #+RESULTS: | foo | bar | #+begin_src emacs-lisp :results table ;; Another sql query that returns zero rows: '() #+end_src #+RESULTS: I would like to keep it that way, but also use post-processing to add a header to all non-empty tables (and only those). Unfortunately post-processing changes how nil aka empty list aka empty table is handled: #+name: addheader #+header: :var rows="" :var header="" #+begin_src elisp :hlines yes (and rows `(("Key" "Value") hline ,@rows)) #+end_src #+header: :post addheader(*this*,'("Key" "Value")) #+begin_src emacs-lisp :results table ;; Some sql query that returns one or more rows: '(("foo" "bar")) #+end_src #+RESULTS: | Key | Value | |-----+-------| | foo | bar | #+header: :post addheader(*this*,'("Key" "Value")) #+begin_src emacs-lisp :results table ;; Another sql query that returns zero rows: '() #+end_src #+RESULTS: : nil I would like it to result in just #+RESULTS: like when no post-processing is involved. It used to behave like that before 51a628bc5efc from 2009, which started turning all symbols, including nil, into strings, but without giving any reason why that should be done. It has worked like this for a long time now, so reverting that is probably not feasible in the short run. However, I feel it would make sense to change now how nil/'() is treated. Currently it is being treated as the symbol nil, but IMO it would make more sense to treat it as the empty list. That could be achieved with diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index b79e47900..2b4a16aea 100644 --- a/lisp/ob-ref.el +++ b/lisp/ob-ref.el @@ -199,7 +199,7 @@ (defun org-babel-ref-resolve (ref) (org-babel-execute-src-block nil info params)))) (error "Reference `%s' not found in this buffer" ref)))) (cond - ((symbolp result) (format "%S" result)) + ((and result (symbolp result)) (format "%S" result)) ((and index (listp result)) (org-babel-ref-index-list index result)) (t result))))))))) In the long run you might want to consider not turning any symbols into strings, at least not when the "regular" block as well as the post-processing block both use elisp. Thanks for considering my suggestions! Jonas