GNU bug report logs -
#55315
[elpa/csv-mode] [PATCH] CSV separator guessing
Previous Next
Reported by: Simen Heggestøyl <simenheg <at> runbox.com>
Date: Sun, 8 May 2022 14:13:02 UTC
Severity: normal
Tags: patch
Done: Simen Heggestøyl <simenheg <at> runbox.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Mattias Engdegård <mattiase <at> 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 (text/x-diff, attachment)]
This bug report was last modified 3 years and 14 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.