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 ms0.migadu.com with LMTPS id EPAiFAVxu2CcIAEAgWs5BA (envelope-from ) for ; Sat, 05 Jun 2021 14:41:41 +0200 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 MD1WDwVxu2CgZQAAbx9fmQ (envelope-from ) for ; Sat, 05 Jun 2021 12:41:41 +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 71B5F25A8A for ; Sat, 5 Jun 2021 14:41:40 +0200 (CEST) Received: from localhost ([::1]:39264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpVcQ-0006Jq-5C for larch@yhetil.org; Sat, 05 Jun 2021 08:41:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpVbj-0006Jb-Be for emacs-orgmode@gnu.org; Sat, 05 Jun 2021 08:40:55 -0400 Received: from ciao.gmane.io ([116.202.254.214]:39142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpVbe-00032A-TE for emacs-orgmode@gnu.org; Sat, 05 Jun 2021 08:40:55 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lpVbZ-0004zw-3o for emacs-orgmode@gnu.org; Sat, 05 Jun 2021 14:40:45 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Maxim Nikulin Subject: Re: bug#47885: [PATCH] org-table-import: Make it more smarter for interactive use Date: Sat, 5 Jun 2021 19:40:36 +0700 Message-ID: References: <87o8cmi8bn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 In-Reply-To: <87o8cmi8bn.fsf@gmail.com> Content-Language: en-US Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 22 X-Spam_score: 2.2 X-Spam_bar: ++ X-Spam_report: (2.2 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.59, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no 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-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1622896900; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1jfYzorvx076VE43VVUnNFiAH5zm06oFJjLSlEoH0L4=; b=I3f2iKmTIV1q0jTSYYlsHYA8MEaogmtApdhm39GloR1fwAG0v99x3w9j0CdP2R96N9Ai9M ybBerD5jxfrVlyeIUaJTJ4BAWRAygxwjdyXYN8hKvcW3mwnVusEqcv9VetYBlrkSWOuovb EUBhFI3QYUR6z+2u0GZ/NQCp12QwHf2OXCe9BJoIu5tJ7+nRSbskq6VgxpbjHzi9vKwEP2 2XHj3mgWejPLbNErzM3v1X15lrffUEO7a4kLwPuQ35H7EcjRdwio5YdstR0nJZmNFK2gK3 w1n82ZjAJ+rgbgF15WM4hst7ICQ1STGtF/fN6oALYF3HT2/uXWNYdD/e2FQ8+g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1622896900; a=rsa-sha256; cv=none; b=DVL38F+TLqI2bgxN8HWmkZcfNP4vb8dQsVpEVLqlxxsGwRq6ehKNNZojm2KJ7j4qjyzDrD ojkbPl7TaCpVD6HoYVjFofVPYxAyARbqav3BhMPDjLPx84gYRLbIxIMwsWYlLaRRblHk4f m6dBlcozV2wNG5h/no4pu+FOgz2z7m7qhnO+sQVN4tYZ0I0SDlOYy+ysODBRLrOPpLH2za PkoUP8MNQkkA5dCTSG8X0IzotIqi+b1Psknu5laeFamqaDjmnXxtp45OFaBGNfhAxWfaxn bVV/R7mCTzGG1ubnCe6b4E3ItNa7iORX7ArCo3pfai3zVCW33qOdVpk8GZg2/A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=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-Migadu-Spam-Score: -1.83 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=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-Migadu-Queue-Id: 71B5F25A8A X-Spam-Score: -1.83 X-Migadu-Scanner: scn0.migadu.com X-TUID: 0YsBj3LPSleA On 04/06/2021 11:04, Utkarsh Singh wrote: > On 2021-06-02, 23:44 +0700, Maxim Nikulin wrote: > >> On 02/06/2021 22:08, Utkarsh Singh wrote: >>> ;;;###autoload >>> (defun org-table-import (file separator) >>> @@ -955,12 +971,13 @@ lines. It can have the following values: >>> - integer When a number, use that many spaces, or a TAB, as field separator. >>> - regexp When a regular expression, use it to match the separator." >>> (interactive (list (read-file-name "Import file: ") >>> - (prefix-numeric-value current-prefix-arg))) >>> + current-prefix-arg)) >> >> It seems, prefix argument works now. Let me remind that file name >> completion was working better before your change. If you are still going to update this patch, I recommend you to check if `list' form of `interactive' declaration is supported by Emacs 24.3. Recently Kyle had to almost revert one my patch. Fortunately a simpler alternative supported by old Emacs versions were already discussed. >> I have noticed a couple of error messages. Unsure what is going wrong, I >> hope, command to launch emacs is correct (-Q -L ~/src/org-mode/lisp >> test.org). >> >> At startup: >> Eager macro-expansion failure: (error "rx ‘not’ syntax error: (or 10 44)") >> >> In response to M-x org-table-import: >> rx-check-not: rx ‘not’ syntax error: (or 10 44) > > Is `rx' library loading correctly? If no then you can try: > > +(require 'rx) This line should be added to org-table.el, but notice "rx ‘not’ syntax error: (or ". This logical operators have a bit different meaning for regular expression. Nicolas suggested you to use `list' to avoid `eval'. Certainly `eval' should be avoided whenever possible, but there is alternative with "`" and "," instead of "'". Though I often prefer `list'. > > Can you also share test.org so that I can test locally? I can reproduce it with an empty org file. Emacs-26.3. So I am curious if your tested your patch at all. > Now on the topic of CSV parser, I have succesfully implemented a CSV > parser in less than 65 LOC which also preserves newline character but I > am facing a dilemma on how should I represent it as a Org table. For > ex: ... > 6,"Cell with new > Line",6.28 Due to https://orgmode.org/worg/org-faq.html#Tables "Will there ever be support for multiple lines in a table field? No." (there are may be some tricks in Org manual) any variant is acceptable, even current one. Since during export split cell is considered as different rows, it is responsibility of the user to preprocess original file and import it in a form suitable for Org. However independently of chosen variant, it would be great to get list of warnings with ambiguous lines similar to compiler errors. Such feature is not implemented in Org yet, the most close is `org-lint' result (its behavior differs from compiler errors). > 2. Represent every newline as distinct cell. I was trying to implement > this method but the algorithm that I came up with requires time > complexity of O(n^2) to just print each row which is too much for large > CSV files. > > (defun org-table--print-row (row) > (let ((maxlines 1) > list1 list2 tmp) > ;; get maxlines > (dolist (i row) I expect complexity O(number of lines in result). I do not like excessive usage of `dolist'. I would try slicing subrows using `mapcar' while there is at least one non-nil element. P.S. Have you read "Structure and Interpretation of Computer Programs" by Abelson, Sussman, and Sussman? https://sarabander.github.io/sicp/html/index.xhtml or https://mitpress.mit.edu/sites/default/files/sicp/index.html While reading, it is necessary to realize that elisp is not scheme, tail recursion should be avoided in elisp and there are over differences.