From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 7S5UO3WmuWDU6gAAgWs5BA (envelope-from ) for ; Fri, 04 Jun 2021 06:05:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id EFw/NnWmuWA3UAAA1q6Kng (envelope-from ) for ; Fri, 04 Jun 2021 04:05:09 +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 025D714BC5 for ; Fri, 4 Jun 2021 06:05:09 +0200 (CEST) Received: from localhost ([::1]:51912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lp151-0004gF-9N for larch@yhetil.org; Fri, 04 Jun 2021 00:05:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lp14U-0004fq-8S for emacs-orgmode@gnu.org; Fri, 04 Jun 2021 00:04:34 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:45629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lp14S-0003wR-Cj for emacs-orgmode@gnu.org; Fri, 04 Jun 2021 00:04:33 -0400 Received: by mail-pj1-x1034.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso1713005pjb.4 for ; Thu, 03 Jun 2021 21:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:date:message-id:mime-version :content-transfer-encoding; bh=vMfDqP3ExBgT6G7n9jgVQKDQjqG8/bygBgBo+kR2RM4=; b=ZWn8l7ej6ormAxUl60x8mbEnmrmKUsrzu9AVxPogvDsVu0wA5/GX/WTGzvr3inXUjV JXO3IF97yruMUWGv4MbkB42g6dEnd6YkByPeFmsVbWkKAOXHd3nbCIRRKZf+thwrb9GJ 8gXZPBs7asgApnHGWCNLmPP5Lz54vgdQKhjcug4kbDRnLCVeLQm07hlKKmZtFjKanMPR Ect2xJGGfwDkgo+LUNbQyFfqCrYTm/9ZPERMfJhiFbaxUqPLRx+fo/ffxaAuh7QXwMna 6tgV+mbVdd56rD4sL7lGsxL8C0abOuijnwOPLwArLdT8RgNP/RmsLBfBn8n3bLTL0nlZ uVkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:date:message-id :mime-version:content-transfer-encoding; bh=vMfDqP3ExBgT6G7n9jgVQKDQjqG8/bygBgBo+kR2RM4=; b=XNovwkeHhh1SvA1AyXGforDMKdUArAnKefgAypnk/RKVPxgk8ilTn7XJbOgCGRG85i FmdAiIWubczSEhOvJY/kNPlB84zA/jR6huETqen6vEWr3URSsvOf6TPEt15u4FSQyDPt Gl4i91nRyVgpoKTC9p57W0GYSyuBDACf+CwfX1qFEL987Cggnh7fpIfaYjGV6q3Bimd2 rbNHiOBIXMxlwgY1KTbrKltEI2vkShubt9hus0GOaRLAUzkqd2/HmI4VSp5Qe18seOPp afJ9093DXcAPAWo11Su7oHUv83bVO9jBK1dqwbybckwd0Hp0gwm1APrm+o01fTsGKxcW bhmw== X-Gm-Message-State: AOAM531IBUVwRgsJamp25HFP24WqhOkhKHAkwTxJ1aFNPu7gCTYwAEsC l14uKwl9iXt1bHROMhWJ8UA= X-Google-Smtp-Source: ABdhPJyEi3k6b5lx7ExRt7FeM2qezgeNjMqNMcq4fxCDoqyC208ivHqp2D8FKuUAFXOb/Rv4WjG9WA== X-Received: by 2002:a17:90a:9bc4:: with SMTP id b4mr14538634pjw.42.1622779470403; Thu, 03 Jun 2021 21:04:30 -0700 (PDT) Received: from localhost ([103.77.0.95]) by smtp.gmail.com with ESMTPSA id q3sm482142pff.142.2021.06.03.21.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 21:04:30 -0700 (PDT) From: Utkarsh Singh To: Maxim Nikulin , emacs-orgmode@gnu.org Subject: Re: bug#47885: [PATCH] org-table-import: Make it more smarter for interactive use In-Reply-To: Date: Fri, 04 Jun 2021 09:34:44 +0530 Message-ID: <87o8cmi8bn.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=utkarsh190601@gmail.com; helo=mail-pj1-x1034.google.com X-Spam_score_int: 1 X-Spam_score: 0.1 X-Spam_bar: / X-Spam_report: (0.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_OTHER_BAD_TLD=1.997, RCVD_IN_DNSWL_NONE=-0.0001, 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=1622779509; 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:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=vMfDqP3ExBgT6G7n9jgVQKDQjqG8/bygBgBo+kR2RM4=; b=T5LlhQ6tabUxK18LT4Fe7Rf6J5Sto0ZTG4Rk+fMrqotKv3tIkZUAOCfI2Mrm29NP2lRwZJ TUxHvN+d3q7cv1mQt80izeYhWS09l2ZZdsyY2ujbnbWmXCiAmFV6GwZhjf0liBm6WRC18W A/QHOqcjNQvZFneeDd4R6An/MBzUx3KhGOsMomoX7fPVNKyxlE3l61FzlQTpteajMM0VbQ VW4TnUAslI4Axp0pftiXm570lyxt0wlLJkrbumPrnWq8lG1f+0Wu+QqeyzznRES+PmXxjh prDWX3xn8uHZ5cBct8t3iIvKgXidxUSrvKNTrHU1eanA3S8TpciRPhJrFfsB5A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1622779509; a=rsa-sha256; cv=none; b=ELx+84Sg3yjuSISYCLOY3zzg8+KWKykCMbDmvoTKuHzNVtDNkwn9orZIdIC8B04o0rCqnO 4a9EAnmm5anKYt6dfvHflTMEB75fsSPEK99zNj6iSCraCH+Ap7f4fkVC5vXmPfQ6uMKuCF ywjs2iu0dfXON+grMKzayg636U9stop0Ug3dygz1FOIJmq70/CAdI9udTZKoF7Zy0JkaIQ 5qZb+b9JIWXoHf4iwABx0hyKt7mNRdrlQTPKeh1Q0M9udGJLmSYV+OCAXg5w23+51zSkDK VStBHvwjdM7+ku+TXYd+KVoMhirFy4EYTu32yQQkfUDz/w+d5UsCsteDJ/sD3g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ZWn8l7ej; dmarc=pass (policy=none) header.from=gmail.com; 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: -3.13 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ZWn8l7ej; dmarc=pass (policy=none) header.from=gmail.com; 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: 025D714BC5 X-Spam-Score: -3.13 X-Migadu-Scanner: scn0.migadu.com X-TUID: ceToHsYMHQnr 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 sepa= rator. >> - 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=20 > completion was working better before your change. > > I have noticed a couple of error messages. Unsure what is going wrong, I= =20 > hope, command to launch emacs is correct (-Q -L ~/src/org-mode/lisp=20 > test.org). > > At startup: > Eager macro-expansion failure: (error "rx =E2=80=98not=E2=80=99 syntax er= ror: (or 10 44)") > > In response to M-x org-table-import: > rx-check-not: rx =E2=80=98not=E2=80=99 syntax error: (or 10 44) > Is `rx' library loading correctly? If no then you can try: diff --git a/lisp/org-table.el b/lisp/org-table.el index 20144c91b..9278f91bb 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -38,6 +38,7 @@ (require 'org-macs) (require 'org-compat) (require 'org-keys) +(require 'rx) Can you also share test.org so that I can test locally? >> Currently I am trying to refactor CSV parsing by applying techniques >> used in pcsv library (MELPA package) which I think you will also enjoy >> to play with! > > I do not know opinion of Org maintainers. Personally I believe that org=20 > can take advantage of Emacs core features or of other packages if they=20 > are available and fallback to minimal implementation otherwise. Unsure=20 > whether borrowing code from pcsv can cause license issues. Current CSV=20 > parser is not perfect but it works reasonably well. Yes, I think you are right about how Org should make use of existing feature rather than including everyting with itself but for now I am considering this as an opportunity to learn how Org and Emacs work and will leave it upto the maintainers if they find anything useful to be including into Org itself. 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: Row with newline as CSV data: 6,"Cell with new Line",6.28 Row with newline as Lisp data: ("6" "Cell with new\nLine" "6.28") Row with newline a Org table: | 6 | Cell with new | 6.28 | | | Line | | Rows in Org mode are separated using a newline-character which makes "Cell with new" and "Line" as different cells which is different from how Libreoffice Calc represents it. Libreoffice Calc has a much powerfull representation of a cell which is out of scope for any plain text tables. Possible solutions for this problem are: 1. Replace newline with a space character. What will happen when imported line as a really long line? 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) (if (not (stringp i)) (push (list i) list1) (push (string-lines i) list1) (setq tmp (length (car list1))) (when (< maxlines tmp) (setq maxlines tmp)))) ;; normalize row (dolist (i list1) (setq tmp (length i)) (when (< tmp maxlines) (setq i (append i (make-list (- maxlines tmp) "")))) (push i list2)) ;; print row (dolist (i list2) (setq tmp (point)) (dolist (j i))))) <-- Printing is still not complete Thank you, Utkarsh Singh --=20 Utkarsh Singh http://utkarshsingh.xyz