[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#55315: [elpa/csv-mode] [PATCH] CSV separator guessing
From: |
Simen Heggestøyl |
Subject: |
bug#55315: [elpa/csv-mode] [PATCH] CSV separator guessing |
Date: |
Sun, 08 May 2022 21:31:12 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) |
Mattias Engdegård <mattiase@acm.org> writes:
>> + (setq csv-separator-chars (mapcar #'string-to-char value))
>> + (let ((quoted-value (mapcar #'regexp-quote value)))
>> + (setq csv--skip-chars (apply #'concat "^\n" quoted-value))
>> + (setq csv-separator-regexp
>> + (apply #'concat `("[" ,@quoted-value "]"))))
>
> `regexp-quote` produces a regexp from a string literal, but what goes
> inside the square brackets is not a regexp -- the syntax rules are
> different. More specifically, other characters are special, and
> backslash does not quote anything.
>
> To produce a regexp that matches one in a set of characters, try rx-to-string
> or regexp-opt. For example,
>
> (setq csv-separator-regexp (rx-to-string `(or ,@csv-separator-chars) t))
>
> The same applies to csv--skip-chars: this isn't a regexp either, but
> uses yet another syntax so regexp-quote is inappropriate here
> too. Easiest is to precede each char with a backslash since that
> always yields a correctly quoted character: "ABC" -> "\\A\\B\\C".
>
> This is not a judgement on the rest of the patch which may be fine for all I
> know.
Thanks Mattias.
Does it look better in the updated patch attached?
Note that `csv--skip-chars' and `csv-separator-regexp' are set in two
different places in the patch, the first time from a list of strings in
`csv-separators', and the second time from a single character in
`csv-set-separator'. Am I right in thinking that the use of
`regexp-quote' in the `csv-set-separator' case gives the right result?
-- Simen
0001-Add-CSV-separator-guessing-functionality.patch
Description: Text Data