Subject: bug#55315: [elpa/csv-mode] [PATCH] CSV separator guessing

From: Mattias Engdegård <[email-masked]>
Date: Sun, 8 May 2022 19:56:00 +0200

> +         (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.