From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uHUXFZxyiGA0LwEAgWs5BA (envelope-from ) for ; Tue, 27 Apr 2021 22:22:52 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id GKKoEJxyiGCxEwAAbx9fmQ (envelope-from ) for ; Tue, 27 Apr 2021 20:22:52 +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 9E4F813F0B for ; Tue, 27 Apr 2021 22:22:51 +0200 (CEST) Received: from localhost ([::1]:42220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbUEM-0006c5-QT for larch@yhetil.org; Tue, 27 Apr 2021 16:22:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbUDa-0006bm-Ae for emacs-orgmode@gnu.org; Tue, 27 Apr 2021 16:22:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39467) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lbUDa-0006k2-37 for emacs-orgmode@gnu.org; Tue, 27 Apr 2021 16:22:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lbUDZ-0006yt-VY for emacs-orgmode@gnu.org; Tue, 27 Apr 2021 16:22:01 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#47885: [PATCH] org-table-import: Make it more smarter for interactive use Resent-From: Nicolas Goaziou Original-Sender: "Debbugs-submit" Resent-CC: emacs-orgmode@gnu.org Resent-Date: Tue, 27 Apr 2021 20:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47885 X-GNU-PR-Package: org-mode X-GNU-PR-Keywords: patch To: Utkarsh Singh Received: via spool by 47885-submit@debbugs.gnu.org id=B47885.161955489226789 (code B ref 47885); Tue, 27 Apr 2021 20:22:01 +0000 Received: (at 47885) by debbugs.gnu.org; 27 Apr 2021 20:21:32 +0000 Received: from localhost ([127.0.0.1]:51011 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lbUD5-0006y1-Lb for submit@debbugs.gnu.org; Tue, 27 Apr 2021 16:21:32 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:60909) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lbUD2-0006xh-TQ for 47885@debbugs.gnu.org; Tue, 27 Apr 2021 16:21:30 -0400 X-Originating-IP: 185.131.40.67 Received: from localhost (40-67.ipv4.commingeshautdebit.fr [185.131.40.67]) (Authenticated sender: admin@nicolasgoaziou.fr) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id CDAC51BF208; Tue, 27 Apr 2021 20:21:21 +0000 (UTC) From: Nicolas Goaziou References: <87czuq9958.fsf@gmail.com> <8735vmelfs.fsf@nicolasgoaziou.fr> <87k0oyfj4y.fsf@gmail.com> <87im4h9irn.fsf@nicolasgoaziou.fr> <87zgxpwqa7.fsf@gmail.com> Date: Tue, 27 Apr 2021 22:21:20 +0200 In-Reply-To: <87zgxpwqa7.fsf@gmail.com> (Utkarsh Singh's message of "Fri, 23 Apr 2021 10:28:24 +0530") Message-ID: <875z07jx6n.fsf@nicolasgoaziou.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: emacs-orgmode@gnu.org List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 47885@debbugs.gnu.org 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=1619554971; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post; bh=6lqUgEI5RGSgjs/yQ7St3x/LgAoIVkjH2mpQ4FJdX9U=; b=sL3Dko89HfvsfPQ6rO5aLPObb+lUMdr3rObssWrv9zc8h4xeut+/zkLwUr6Y6tN3jSd3NU 3/e2y6zeLERKV+9RzKI7UoenrGn9Camc6uJtvYoMLiaw73yQCKONWbas2RMOfxqFMSTF9D dh0ofhO3kDeB9A7X4R2wjWeR83z6QLbsRBWULAUuBs1v9gcTPs15XDnglcLmoIryFZ4NEz hBcaPjxgF0r+ZfE+K0x81YqTzAygNvKAYwCI35lZaNcnNsOHH20y8FWsMoHT+GA5et2PAW ZEXDp/UFWmCMfTC0EzRrIKE/eHG7rgbr9B4BtaPPvEDrzsWsBPPP/MWdKlG2kg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619554971; a=rsa-sha256; cv=none; b=u8ZAWx5PBXRqdptpn9FsLOPaqTK6UM72J/hT9gPEBt4mtMe0EJCAlYfOhi3YdzZKimxkpv DNky6jMzrA+Iss7wxFDMNn/pwBwcDRAJZTqOCDSJ5J5XWc0BYukkE3gAohGKnEiomqE6Xn r85bPfqrJbbbbNMTCj3dg6aOf53Np50g/jUO0OpDKuFIKLM6PgwBAywuI2b1LJmAO30QkI 2/aVR9XVrYFujN6wuMm1UfDTpzcunlESWtk4MQJlYmbmNveWUUvJKd1E9WeDevPHYL9OSf 2aYHl4OdAzZesQI3//mKTEnDFrAV7/5QJgyxa82L8nVPjHTpbwVKNZQi280dSQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=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: -2.45 Authentication-Results: aspmx1.migadu.com; dkim=none; 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-Migadu-Queue-Id: 9E4F813F0B X-Spam-Score: -2.45 X-Migadu-Scanner: scn0.migadu.com X-TUID: zUOA1v8N2Ct3 Hello, Utkarsh Singh writes: > I am attaching my patch which also include my previous suggestion of > including yes-or-no prompt to org-table-import to allow file which don't > have csv, tsv or txt as extension. I suggest to make several patches. Do not try to stuff as many changes as possible in a single one, please. > + When using org-table-import interactively if we failed to guess > separator then we will be left with a user-error message and an > 'unconverted table'. We can make use of 'temp-buffer' to import our > file after successfully conversion. I'm not sure to understand what you mean. > + Conversion part of org-table-convert-region make a distinction between > '(4) (comma separator) and rest of the separator we should either string > version of comma as AND condition or rewrite to simplify it. Ditto. But it can be the object of another patch. Let's concentrate on `org-table-guess-separator' first. > I am willing to do these possible changes but currently waiting for your > review for org-table-guess-separator as there can be more serious bugs > lurking around on my code which I am considering base for these > changes. You should definitely write tests for this function. Here's a start: (ert-deftest test-org-table/guess-separator () "Test `test-org-table/guess-separator'." ;; Test space separator. (should (equal " " (org-test-with-temp-text "a b\nc d" (org-table-guess-separator (point-min) (point-max))))) (should (equal " " (org-test-with-temp-text "a b\nc d" (org-table-guess-separator (point-min) (point-max))))) ;; Test "inverted" region. (should (equal " " (org-test-with-temp-text "a b\nc d" (org-table-guess-separator (point-max) (point-min))))) ;; Do not error on empty region. (should-not (org-test-with-temp-text "" (org-table-guess-separator (point-max) (point-min)))) (should-not (org-test-with-temp-text " \n" (org-table-guess-separator (point-max) (point-min))))) > + (end (save-excursion > + (goto-char (max beg end0)) This should be beg0 instead of beg above. > + (sep-regexp '(("," (rx bol (1+ (not (or ?\n ?,))) eol)) > + ("\t" (rx bol (1+ (not (or ?\n ?\t))) eol)) > + (";" (rx bol (1+ (not (or ?\n ?\;))) eol)) > + (":" (rx bol (1+ (not (or ?\n ?:))) eol)) > + (" " (rx bol (1+ (not (or ?' ?\" )) > + (not (or ?\s ?\;)) > + (not (or ?' ?\"))) eol)))) Use (sep-regexp (list (list "," (rx bol (1+ (not (or ?\n ?,))) eol)) (list "\t" (rx bol (1+ (not (or ?\n ?\t))) eol)) (list ";" (rx bol (1+ (not (or ?\n ?\;))) eol)) (list ":" (rx bol (1+ (not (or ?\n ?:))) eol)) (list " " (rx bol (1+ (not (or ?' ?\" )) (not (or ?\s ?\;)) (not (or ?' ?\"))) eol)))) so you don't need eval below, and rx forms become constants when compiled. > + sep) This `sep' binding can be removed. > + (unless (= beg end) > + (save-excursion > + (goto-char beg) > + (catch :found > + (pcase-dolist (`(,sep ,regexp) sep-regexp) > + (save-excursion > + (unless (re-search-forward (eval regexp) end t) You can drop the `eval'. > (when (and (called-interactively-p 'any) > - (not (string-match-p (rx "." (or "txt" "tsv" "csv") eos) file))) > + (not (string-match-p (rx "." (or "txt" "tsv" "csv") eos) file)) > + (not (yes-or-no-p "File does not havs .txt .txt .csv as extension. Do you still want to continue? "))) "does not have" and ".txt" -> ".tsv" I guess. Also please provide a patch with a commit message, possibly using `git format-patch'. Thanks! Regards, -- Nicolas Goaziou