GNU bug report logs - #55315
[elpa/csv-mode] [PATCH] CSV separator guessing

Previous Next

Package: emacs;

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

From: Mattias Engdegård <mattiase <at> acm.org>
To: Simen Heggestøyl <simenheg <at> runbox.com>
Cc: 55315 <at> debbugs.gnu.org
Subject: bug#55315: [elpa/csv-mode] [PATCH] CSV separator guessing
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.





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.