From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qGuAGyo9fWAbHgAAgWs5BA (envelope-from ) for ; Mon, 19 Apr 2021 10:19:54 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id eBdgFSo9fWDoRAAAB5/wlQ (envelope-from ) for ; Mon, 19 Apr 2021 08:19:54 +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 EB1DF2DAAD for ; Mon, 19 Apr 2021 10:19:53 +0200 (CEST) Received: from localhost ([::1]:36290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYP8L-0006hw-54 for larch@yhetil.org; Mon, 19 Apr 2021 04:19:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYP7e-0006hm-Ph; Mon, 19 Apr 2021 04:19:10 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:31161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYP7c-0004Dm-Gw; Mon, 19 Apr 2021 04:19:10 -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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 7E96624000C; Mon, 19 Apr 2021 08:19:04 +0000 (UTC) From: Nicolas Goaziou To: Utkarsh Singh Subject: Re: [PATCH] org-table-import: Make it more smarter for interactive use References: <87czuq9958.fsf@gmail.com> Mail-Followup-To: Utkarsh Singh , emacs-orgmode@gnu.org, bug-gnu-emacs@gnu.org Date: Mon, 19 Apr 2021 10:19:03 +0200 In-Reply-To: <87czuq9958.fsf@gmail.com> (Utkarsh Singh's message of "Mon, 19 Apr 2021 10:13:31 +0530") Message-ID: <8735vmelfs.fsf@nicolasgoaziou.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=217.70.183.193; envelope-from=mail@nicolasgoaziou.fr; helo=relay1-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Cc: bug-gnu-emacs@gnu.org, emacs-orgmode@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=1618820394; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=TiqZzCq2o4y24imuO7MLl8qxdtsUcQ2IBSrDMU3pjM0=; b=iblzZJxCY1c/Weo8VlC6FfHL5B9I75s0xS+o3hMoPSr0jQV8zfPg42mvnPa94+SPxwyspi z6rg2bWKoDXDfh1m1WK0yGLWOcmVIOg32Qgp5dvbhNWdT9GyFRjVUAUhiGykENjtjduLwL tZeWIL/4bv//6MkiEnwxhbmpcBLCyYTpdBe6UrXVrgiLYwhBKRFU9DpUW5/xOayukFiEp9 tk7HZqKu/6GDRmX8BLCPCvjwZxKS4RLmRBeJFCKjokEVL9UwXvPwydveVQpq0+ttblcWDb BbtIHma2vjL4E59QKW2cyI7XLj4QA/AXZAPfhjQlwRVglETJuNPTlHlc//cDMw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1618820394; a=rsa-sha256; cv=none; b=tPxskh8n819TcF6Tdj3VRa0/xy7h/QBxnaQjWakt/vUGgijEU3jY0tS7+x2mBgsNafQbb8 jLVq9feqPucCosxdKsp0762v+3EWkC8A6+NlsS3PyMZU0hHjFOZLm9Pe0n0mRgrDWaq34z rS8Ofu51AevyAaemMDRwD4NlsyWeLkDSiHFmcL/QYPUlQ1owmAktTTWhGH8dafapl6p5P5 nc/YnfBjTts2PrL5qnnTBaxp8tHnXgptD7RU5X6wSkhIL1T6Oa5d6fUGNxqmNzvqtwUynd AohgaO4ky70C8lDaDgLf5Ptviu8+mEJSQu/tDbZZa2Rte2XId/u4FZAeD46efg== 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.44 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: EB1DF2DAAD X-Spam-Score: -2.44 X-Migadu-Scanner: scn0.migadu.com X-TUID: I0Gogj5XlFB3 Hello, Utkarsh Singh writes: > My previous patch proposed to add support for importing file with > arbitrary name and building upon that this patch tries to make use of it > by making org-table-import smarter by simply adding more separators > (delimiters). Good idea, thank you. Some comments follow. > +(defun org-table-guess-separator (beg0 end0) > + "Guess separator for `org-table-convert-region' for region BEG0 to END0. > + > +List of preferred separator: > +comma, TAB, ';', ':' or SPACE I suggest to use full names everywhere: comma, TAB, semicolon, colon, or SPACE. > +If region contains a line which doesn't contain the required > +separator then discard the separator and search again using next > +separator." > + (let ((beg (save-excursion > + (goto-char (min beg0 end0)) > + (beginning-of-line 1) > + (point))) (beginning-of-line 1) + (point) -> (line-beginning-position) since you don't intent to move point. > + (end (save-excursion > + (goto-char (max beg0 end0)) > + (end-of-line 1) > + (if (bolp) (backward-char 1) (end-of-line 1)) I'm not sure about what you mean above. First, the second call to end-of-line is useless, since you're already at the end of the line. Second, what is wrong if point is at an empty line? Why do you want to move it back? > + (point)))) You may want to use `line-end-position'. > + (save-excursion > + (goto-char beg) > + (cond > + ((not (re-search-forward "^[^\n,]+$" end t)) '(4)) > + ((not (re-search-forward "^[^\n\t]+$" end t)) '(16)) > + ((not (re-search-forward "^[^\n;]+$" end t)) ";") > + ((not (re-search-forward "^[^\n:]+$" end t)) ":") > + ((not (re-search-forward "^\\([^'\"][^\n\s][^'\"]\\)+$" end t)) " ") > + (t nil))))) I think you need to wrap `save-excursion' around each `re-search-forward' call. Otherwise each test starts at the first line containing the separator previously tested. > + > ;;;###autoload > (defun org-table-convert-region (beg0 end0 &optional separator) > "Convert region to a table. > @@ -862,10 +891,7 @@ org-table-convert-region > 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 > nil When nil, the command tries to be smart and figure out the > - separator in the following way: > - - when each line contains a TAB, assume TAB-separated material > - - when each line contains a comma, assume CSV material > - - else, assume one or more SPACE characters as separator." > + separator using `org-table-guess-seperator'." I wonder if creating a new function is warranted here. You could add the news checks after those already present in the code, couldn't you? Regards, -- Nicolas Goaziou