From 8d2d5de5dd14ba7d200f6bf3bcb5da943c3aac59 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sat, 21 Dec 2024 17:37:31 +0100 Subject: [PATCH] updaet csv-mode Signed-off-by: Andreas Gerler --- elpa/csv-mode-1.22.signed | 1 - elpa/csv-mode-1.22/csv-mode-pkg.el | 2 - elpa/csv-mode-1.27.signed | 1 + .../csv-mode-autoloads.el | 37 +++++------ elpa/csv-mode-1.27/csv-mode-pkg.el | 2 + .../csv-mode-tests.el | 51 +++++++++++++++ .../csv-mode.el | 62 +++++++++++++++++-- elpa/csv-mode-readme.txt | 61 ------------------ 8 files changed, 126 insertions(+), 91 deletions(-) delete mode 100644 elpa/csv-mode-1.22.signed delete mode 100644 elpa/csv-mode-1.22/csv-mode-pkg.el create mode 100644 elpa/csv-mode-1.27.signed rename elpa/{csv-mode-1.22 => csv-mode-1.27}/csv-mode-autoloads.el (83%) create mode 100644 elpa/csv-mode-1.27/csv-mode-pkg.el rename elpa/{csv-mode-1.22 => csv-mode-1.27}/csv-mode-tests.el (73%) rename elpa/{csv-mode-1.22 => csv-mode-1.27}/csv-mode.el (97%) delete mode 100644 elpa/csv-mode-readme.txt diff --git a/elpa/csv-mode-1.22.signed b/elpa/csv-mode-1.22.signed deleted file mode 100644 index 1c32bfb9..00000000 --- a/elpa/csv-mode-1.22.signed +++ /dev/null @@ -1 +0,0 @@ -Good signature from 066DAFCB81E42C40 GNU ELPA Signing Agent (2019) (trust undefined) created at 2023-02-08T23:05:02+0100 using RSA \ No newline at end of file diff --git a/elpa/csv-mode-1.22/csv-mode-pkg.el b/elpa/csv-mode-1.22/csv-mode-pkg.el deleted file mode 100644 index e17c1a72..00000000 --- a/elpa/csv-mode-1.22/csv-mode-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;; Generated package description from csv-mode.el -*- no-byte-compile: t -*- -(define-package "csv-mode" "1.22" "Major mode for editing comma/char separated values" '((emacs "27.1") (cl-lib "0.5")) :commit "db8a3e3aef31d35ce5bd1fd09127a3bbfdd0c340" :url "https://elpa.gnu.org/packages/csv-mode.html" :authors '(("\"Francis J. Wright\"" . "F.J.Wright@qmul.ac.uk")) :maintainer '(nil . "emacs-devel@gnu.org") :keywords '("convenience")) diff --git a/elpa/csv-mode-1.27.signed b/elpa/csv-mode-1.27.signed new file mode 100644 index 00000000..8d4174a2 --- /dev/null +++ b/elpa/csv-mode-1.27.signed @@ -0,0 +1 @@ +Good signature from 645357D2883A0966 GNU ELPA Signing Agent (2023) (trust undefined) created at 2024-08-09T11:05:02+0200 using EDDSA \ No newline at end of file diff --git a/elpa/csv-mode-1.22/csv-mode-autoloads.el b/elpa/csv-mode-1.27/csv-mode-autoloads.el similarity index 83% rename from elpa/csv-mode-1.22/csv-mode-autoloads.el rename to elpa/csv-mode-1.27/csv-mode-autoloads.el index 2efe984a..de8cc7c8 100644 --- a/elpa/csv-mode-1.22/csv-mode-autoloads.el +++ b/elpa/csv-mode-1.27/csv-mode-autoloads.el @@ -1,12 +1,14 @@ -;;; csv-mode-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- -;; +;;; csv-mode-autoloads.el --- automatically extracted autoloads (do not edit) -*- lexical-binding: t -*- +;; Generated by the `loaddefs-generate' function. + +;; This file is part of GNU Emacs. + ;;; Code: -(add-to-list 'load-path (directory-file-name - (or (file-name-directory #$) (car load-path)))) +(add-to-list 'load-path (or (and load-file-name (directory-file-name (file-name-directory load-file-name))) (car load-path))) + -;;;### (autoloads nil "csv-mode" "csv-mode.el" (0 0 0 0)) ;;; Generated autoloads from csv-mode.el (autoload 'csv-mode "csv-mode" "\ @@ -20,7 +22,7 @@ group. The separators are specified by the value of `csv-separators'. CSV mode commands ignore blank lines and comment lines beginning with the value of `csv-comment-start', which delimit \"paragraphs\". \"Sexp\" is re-interpreted to mean \"field\", so that `forward-sexp' -\(\\[forward-sexp]), `kill-sexp' (\\[kill-sexp]), etc. all apply to fields. +(\\[forward-sexp]), `kill-sexp' (\\[kill-sexp]), etc. all apply to fields. Standard comment commands apply, such as `comment-dwim' (\\[comment-dwim]). If `font-lock-mode' is enabled then separators, quoted values and @@ -45,37 +47,30 @@ CSV mode provides the following specific keyboard key bindings: \\{csv-mode-map} -\(fn)" t nil) - +(fn)" t) (add-to-list 'auto-mode-alist '("\\.[Cc][Ss][Vv]\\'" . csv-mode)) - (add-to-list 'auto-mode-alist '("\\.tsv\\'" . tsv-mode)) - (autoload 'tsv-mode "csv-mode" "\ Major mode for editing files of tab-separated value type. -\(fn)" t nil) - +(fn)" t) (register-definition-prefixes "csv-mode" '("csv-" "tsv-")) -;;;*** -;;;### (autoloads nil "csv-mode-tests" "csv-mode-tests.el" (0 0 0 -;;;;;; 0)) ;;; Generated autoloads from csv-mode-tests.el (register-definition-prefixes "csv-mode-tests" '("csv-tests--")) - -;;;*** -;;;### (autoloads nil nil ("csv-mode-pkg.el") (0 0 0 0)) +;;; End of scraped data + +(provide 'csv-mode-autoloads) -;;;*** - ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t -;; coding: utf-8 +;; no-native-compile: t +;; coding: utf-8-emacs-unix ;; End: + ;;; csv-mode-autoloads.el ends here diff --git a/elpa/csv-mode-1.27/csv-mode-pkg.el b/elpa/csv-mode-1.27/csv-mode-pkg.el new file mode 100644 index 00000000..9f6ddfff --- /dev/null +++ b/elpa/csv-mode-1.27/csv-mode-pkg.el @@ -0,0 +1,2 @@ +;; Generated package description from csv-mode.el -*- no-byte-compile: t -*- +(define-package "csv-mode" "1.27" "Major mode for editing comma/char separated values" '((emacs "27.1") (cl-lib "0.5")) :commit "a16e9d8b0952de1badf6da8e652b178a7f6c4498" :url "https://elpa.gnu.org/packages/csv-mode.html" :authors '(("Francis J. Wright" . "F.J.Wright@qmul.ac.uk")) :maintainer '(nil . "emacs-devel@gnu.org") :keywords '("convenience")) diff --git a/elpa/csv-mode-1.22/csv-mode-tests.el b/elpa/csv-mode-1.27/csv-mode-tests.el similarity index 73% rename from elpa/csv-mode-1.22/csv-mode-tests.el rename to elpa/csv-mode-1.27/csv-mode-tests.el index 0caeab7d..6aae7369 100644 --- a/elpa/csv-mode-1.22/csv-mode-tests.el +++ b/elpa/csv-mode-1.27/csv-mode-tests.el @@ -52,6 +52,21 @@ (should (equal (buffer-substring (point-min) (point)) "aaa,\"b,b\"")))) +(ert-deftest csv-tests-end-of-field-unclosed-quotes () + (with-temp-buffer + (csv-mode) + (insert "a,b,c +1,2,3 +1,2,\" +\"1, +\"") + (goto-char (point-min)) + (while (not (eobp)) + ;; Should not error + (csv-end-of-field) + (unless (eobp) + (forward-char))))) + (ert-deftest csv-tests-beginning-of-field () (with-temp-buffer (csv-mode) @@ -144,5 +159,41 @@ (csv--separator-score ?\; csv-tests--data (length csv-tests--data))))) +(ert-deftest csv-tests-unquote-value () + (should (equal (csv--unquote-value "Hello, World") + "Hello, World")) + (should (equal (csv--unquote-value "\"Hello, World\"") + "Hello, World")) + (should (equal (csv--unquote-value "Hello, \"\"World") + "Hello, \"\"World")) + (should (equal (csv--unquote-value "\"Hello, \"\"World\"\"\"") + "Hello, \"World\"")) + (should (equal (csv--unquote-value "'Hello, World'") + "'Hello, World'")) + (should (equal (let ((csv-field-quotes '("\"" "'"))) + (csv--unquote-value "\"Hello, World'")) + "\"Hello, World'")) + (should (equal (let ((csv-field-quotes '("\"" "'"))) + (csv--unquote-value "'Hello, World'")) + "Hello, World")) + (should (equal (let ((csv-field-quotes '("\"" "'"))) + (csv--unquote-value "'Hello, ''World'''")) + "Hello, 'World'")) + (should (equal (let ((csv-field-quotes '("\"" "'"))) + (csv--unquote-value "'Hello, \"World\"'")) + "Hello, \"World\"")) + (should (equal (csv--unquote-value "|Hello, World|") + "|Hello, World|"))) + +(ert-deftest csv-tests-guess-separator-avoid-comment () + ;; bug#71042 + (let ((testdata "### +### +Foo;Bar;Quux +123;456;blah, blah +")) + (message "Guessed separator: %c" (csv-guess-separator testdata)) + (should-not (equal (csv-guess-separator testdata) ?#)))) + (provide 'csv-mode-tests) ;;; csv-mode-tests.el ends here diff --git a/elpa/csv-mode-1.22/csv-mode.el b/elpa/csv-mode-1.27/csv-mode.el similarity index 97% rename from elpa/csv-mode-1.22/csv-mode.el rename to elpa/csv-mode-1.27/csv-mode.el index 574050aa..b29019f6 100644 --- a/elpa/csv-mode-1.22/csv-mode.el +++ b/elpa/csv-mode-1.27/csv-mode.el @@ -1,10 +1,10 @@ ;;; csv-mode.el --- Major mode for editing comma/char separated values -*- lexical-binding: t -*- -;; Copyright (C) 2003-2023 Free Software Foundation, Inc +;; Copyright (C) 2003-2024 Free Software Foundation, Inc ;; Author: "Francis J. Wright" ;; Maintainer: emacs-devel@gnu.org -;; Version: 1.22 +;; Version: 1.27 ;; Package-Requires: ((emacs "27.1") (cl-lib "0.5")) ;; Keywords: convenience @@ -107,9 +107,32 @@ ;;; News: +;; Since 1.27: +;; - `csv-end-of-field' no longer errors out in the presence of +;; unclosed quotes. + +;; Since 1.26: +;; - `csv-guess-separator' will no longer guess the comment-start +;; character as a potential separator character. + +;; Since 1.25: +;; - The ASCII control character 31 Unit Separator can now be +;; recognized as a CSV separator by `csv-guess-separator'. + +;; Since 1.24: +;; - New function `csv--unquote-value'. +;; - New function `csv-parse-current-row'. + ;; Since 1.21: ;; - New command `csv-insert-column'. ;; - New config var `csv-align-min-width' for `csv-align-mode'. +;; - New option `csv-confirm-region'. + +;; Since 1.20: +;; - New command `csv-guess-set-separator' that automatically guesses +;; and sets the CSV separator of the current buffer. +;; - New command `csv-set-separator' for setting the CSV separator +;; manually. ;; Since 1.9: ;; - `csv-align-mode' auto-aligns columns dynamically (on screen). @@ -271,6 +294,10 @@ after separators." "If non-nil, make separators in aligned records invisible." :type 'boolean) +(defcustom csv-confirm-region t + "If non-nil, confirm that region is OK in interactive commands." + :type 'boolean) + (defface csv-separator-face '((t :inherit escape-glyph)) "CSV mode face used to highlight separators.") @@ -557,9 +584,10 @@ The default field when read interactively is the current field." (exchange-point-and-mark) (sit-for 1) (exchange-point-and-mark)) - (or (y-or-n-p "Region OK? ") - (error "Action aborted by user")) - (message nil) ; clear y-or-n-p message + (when csv-confirm-region + (or (y-or-n-p "Region OK? ") + (error "Action aborted by user")) + (message nil)) ; clear y-or-n-p message (list (region-beginning) (region-end)))) ;; Use region set by user: (list (region-beginning) (region-end))))) @@ -709,7 +737,7 @@ point or marker arguments, BEG and END, delimiting the region." (when (eq (char-syntax (following-char)) ?\") (forward-char) (let ((ended nil)) - (while (not ended) + (while (and (not ended) (not (eolp))) (cond ((not (eq (char-syntax (following-char)) ?\")) (forward-char 1)) ;; According to RFC-4180 (sec 2.7), quotes inside quoted strings @@ -1394,6 +1422,26 @@ point is assumed to be at the beginning of the line." (forward-char))) (nreverse fields))))) +(defun csv--unquote-value (value) + "Remove quotes around VALUE. +If VALUE contains escaped quote characters, un-escape them. If +VALUE is not quoted, return it unchanged." + (save-match-data + (let ((quote-regexp (apply #'concat `("[" ,@csv-field-quotes "]")))) + (if-let (((string-match (concat "^\\(" quote-regexp "\\)\\(.*\\)\\(" quote-regexp "\\)$") value)) + (quote-char (match-string 1 value)) + ((equal quote-char (match-string 3 value))) + (unquoted (match-string 2 value))) + (replace-regexp-in-string (concat quote-char quote-char) quote-char unquoted) + value)))) + +(defun csv-parse-current-row () + "Parse the current CSV line. +Return the field values as a list." + (save-mark-and-excursion + (goto-char (line-beginning-position)) + (mapcar #'csv--unquote-value (csv--collect-fields (line-end-position))))) + (defvar-local csv--header-line nil) (defvar-local csv--header-hscroll nil) (defvar-local csv--header-string nil) @@ -1860,7 +1908,9 @@ When CUTOFF is passed, look only at the first CUTOFF number of characters." text))) (when (and (not (gethash c chars)) (or (= c ?\t) + (= c ?\C-_) (and (not (member c '(?. ?/ ?\" ?'))) + (not (= c (string-to-char csv-comment-start))) (not (member (get-char-code-property c 'general-category) '(Lu Ll Lt Lm Lo Nd Nl No Ps Pe Cc Co)))))) (puthash c t chars))) diff --git a/elpa/csv-mode-readme.txt b/elpa/csv-mode-readme.txt deleted file mode 100644 index 372cc4d8..00000000 --- a/elpa/csv-mode-readme.txt +++ /dev/null @@ -1,61 +0,0 @@ -This package implements CSV mode, a major mode for editing records -in a generalized CSV (character-separated values) format. It binds -files with prefix ".csv" to `csv-mode' (and ".tsv" to `tsv-mode') in -`auto-mode-alist'. - -In CSV mode, the following commands are available: - -- C-c C-s (`csv-sort-fields') and C-c C-n (`csv-sort-numeric-fields') - respectively sort lexicographically and numerically on a - specified field or column. - -- C-c C-r (`csv-reverse-region') reverses the order. (These - commands are based closely on, and use, code in `sort.el'.) - -- C-c C-k (`csv-kill-fields') and C-c C-y (`csv-yank-fields') kill - and yank fields or columns, although they do not use the normal - kill ring. C-c C-k can kill more than one field at once, but - multiple killed fields can be yanked only as a fixed group - equivalent to a single field. - -- `csv-align-mode' keeps fields visually aligned, on-the-fly. - It truncates fields to a maximum width that can be changed per-column - with `csv-align-set-column-width'. - Alternatively, C-c C-a (`csv-align-fields') aligns fields into columns - and C-c C-u (`csv-unalign-fields') undoes such alignment; - separators can be hidden within aligned records (controlled by - `csv-invisibility-default' and `csv-toggle-invisibility'). - -- C-c C-t (`csv-transpose') interchanges rows and columns. For - details, see the documentation for the individual commands. - -CSV mode can recognize fields separated by any of several single -characters, specified by the value of the customizable user option -`csv-separators'. CSV data fields can be delimited by quote -characters (and must if they contain separator characters). This -implementation supports quoted fields, where the quote characters -allowed are specified by the value of the customizable user option -`csv-field-quotes'. By default, the both commas and tabs are considered -as separators and the only field quote is a double quote. -These user options can be changed ONLY by customizing them, e.g. via M-x -customize-variable. - -CSV mode commands ignore blank lines and comment lines beginning -with the value of the buffer local variable `csv-comment-start', -which by default is #. The user interface is similar to that of -the standard commands `sort-fields' and `sort-numeric-fields', but -see the major mode documentation below. - -The global minor mode `csv-field-index-mode' provides display of -the current field index in the mode line, cf. `line-number-mode' -and `column-number-mode'. It is on by default. - -Installation: - -Put this file somewhere that Emacs can find it (i.e. in one of the -directories in your `load-path' such as `site-lisp'), optionally -byte-compile it (recommended), and put this in your .emacs file: - -(add-to-list 'auto-mode-alist '("\\.[Cc][Ss][Vv]\\'" . csv-mode)) -(autoload 'csv-mode "csv-mode" - "Major mode for editing comma-separated value files." t) -- 2.47.3