]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/csv-mode/csv-mode.el
Fix some quoting problems in doc strings
[gnu-emacs-elpa] / packages / csv-mode / csv-mode.el
index effc72e31bbe0b88c94a8de9c0cc4c3834e8d4e3..5a789951cdb629bffeba1157df91ff887688be83 100644 (file)
@@ -1,11 +1,10 @@
 ;;; csv-mode.el --- Major mode for editing comma/char separated values  -*- lexical-binding: t -*-
 
-;; Copyright (C) 2003, 2004, 2012, 2013, 2014, 2015  Free Software Foundation, Inc
+;; Copyright (C) 2003, 2004, 2012-2016  Free Software Foundation, Inc
 
-;; Author: Francis J. Wright <F.J.Wright at qmul.ac.uk>
+;; Author: "Francis J. Wright" <F.J.Wright@qmul.ac.uk>
 ;; Time-stamp: <23 August 2004>
-;; URL: http://centaur.maths.qmul.ac.uk/Emacs/
-;; Version: 1.3
+;; Version: 1.6
 ;; Keywords: convenience
 
 ;; This package is free software; you can redistribute it and/or modify
@@ -162,7 +161,7 @@ All must be different from the field quote characters, `csv-field-quotes'."
 
 (defcustom csv-field-quotes '("\"")
   "Field quotes: a list of *single-character* strings.
-For example: (\"\\\"\"), the default, or (\"\\\"\" \"'\" \"`\").
+For example: (\"\\\"\"), the default, or (\"\\\"\" \"\\='\" \"\\=`\").
 A field can be delimited by a pair of any of these characters.
 All must be different from the field separators, `csv-separators'."
   :type '(repeat string)
@@ -220,7 +219,7 @@ Changing this variable does not affect any existing CSV mode buffer."
         (set-default 'csv-comment-start value)))
 
 (defcustom csv-align-style 'left
-  "Aligned field style: one of 'left, 'centre, 'right or 'auto.
+  "Aligned field style: one of `left', `centre', `right' or `auto'.
 Alignment style used by `csv-align-fields'.
 Auto-alignment means left align text and right align numbers."
   :type '(choice (const left) (const centre)
@@ -332,24 +331,25 @@ It must be either a string or nil."
    (list (edit-and-eval-command
          "Comment start (string or nil): " csv-comment-start)))
   ;; Paragraph means a group of contiguous records:
-  (setq csv-comment-start string)
   (set (make-local-variable 'paragraph-separate) "[:space:]*$") ; White space.
   (set (make-local-variable 'paragraph-start) "\n");Must include \n explicitly!
-  (if string
-      (progn
-       (setq paragraph-separate (concat paragraph-separate "\\|" string)
-             paragraph-start (concat paragraph-start "\\|" string))
-        (set (make-local-variable 'comment-start) string)
-       (modify-syntax-entry
-        (string-to-char string) "<" csv-mode-syntax-table)
-       (modify-syntax-entry ?\n ">" csv-mode-syntax-table))
-    (with-syntax-table text-mode-syntax-table
-      (modify-syntax-entry (string-to-char string)
-                          (string (char-syntax (string-to-char string)))
-                          csv-mode-syntax-table)
-      (modify-syntax-entry ?\n
-                          (string (char-syntax ?\n))
-                          csv-mode-syntax-table))))
+  ;; Remove old comment-start/end if available
+  (with-syntax-table text-mode-syntax-table
+    (when comment-start
+      (modify-syntax-entry (string-to-char comment-start)
+                          (string (char-syntax (string-to-char comment-start)))
+                          csv-mode-syntax-table))
+    (modify-syntax-entry ?\n
+                        (string (char-syntax ?\n))
+                        csv-mode-syntax-table))
+  (when string
+    (setq paragraph-separate (concat paragraph-separate "\\|" string)
+         paragraph-start (concat paragraph-start "\\|" string))
+    (set (make-local-variable 'comment-start) string)
+    (modify-syntax-entry
+     (string-to-char string) "<" csv-mode-syntax-table)
+    (modify-syntax-entry ?\n ">" csv-mode-syntax-table))
+  (setq csv-comment-start string))
 
 ;;;###autoload
 (add-to-list 'auto-mode-alist '("\\.[Cc][Ss][Vv]\\'" . csv-mode))
@@ -447,8 +447,8 @@ Assumes point is at beginning of line."
 (defun csv-interactive-args (&optional type)
   "Get arg or field(s) and region interactively, offering sensible defaults.
 Signal an error if the buffer is read-only.
-If TYPE is noarg then return a list `(beg end)'.
-Otherwise, return a list `(arg beg end)', where arg is:
+If TYPE is noarg then return a list (beg end).
+Otherwise, return a list (arg beg end), where arg is:
   the raw prefix argument by default\;
   a single field index if TYPE is single\;
   a list of field indices or index ranges if TYPE is multiple.
@@ -957,24 +957,33 @@ The fields yanked are those last killed by `csv-kill-fields'."
 ;;;  Aligning fields
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defun csv--make-overlay (beg end &optional buffer front-advance rear-advance props)
+  (let ((o (make-overlay beg end buffer front-advance rear-advance)))
+    (overlay-put o 'csv t)
+    (while props
+      (overlay-put o (pop props) (pop props)))
+    o))
+
+(defun csv--delete-overlay (o)
+  (and (overlay-get o 'csv) (delete-overlay o)))
+
 (defun csv--column-widths ()
   (let ((widths '()))
     ;; Construct list of column widths:
     (while (not (eobp))                   ; for each record...
       (or (csv-not-looking-at-record)
           (let ((w widths)
-                (beg (point))            ; Beginning of current field.
+                (col (current-column))
                 x)
             (while (not (eolp))
               (csv-end-of-field)
-              (setq x (- (point) beg))    ; Field width.
+              (setq x (- (current-column) col)) ; Field width.
               (if w
                   (if (> x (car w)) (setcar w x))
                 (setq w (list x)
                       widths (nconc widths w)))
               (or (eolp) (forward-char))  ; Skip separator.
-              (setq w (cdr w)
-                    beg (point)))))
+              (setq w (cdr w) col (current-column)))))
       (forward-line))
     widths))
 
@@ -1020,8 +1029,8 @@ If there is no selected region, default to the whole buffer."
                        (align-padding (if (bolp) 0 csv-align-padding))
                        (left-padding 0) (right-padding 0)
                        (field-width
-                        ;; FIXME: Don't assume length=string-width!
-                        (progn (csv-end-of-field) (- (point) beg)))
+                        (- (- (current-column)
+                              (progn (csv-end-of-field) (current-column)))))
                        (column-width (pop w))
                        (x (- column-width field-width))) ; Required padding.
                   (set-marker end (point)) ; End of current field.
@@ -1069,9 +1078,8 @@ If there is no selected region, default to the whole buffer."
                       ;; in Emacs 21.3, neighbouring overlays
                       ;; conflict, so use the following only
                       ;; with hard alignment:
-                      (let ((ol (make-overlay (point) (1+ (point)) nil t)))
-                        (overlay-put ol 'invisible t)
-                        (overlay-put ol 'evaporate t))
+                     (csv--make-overlay (point) (1+ (point)) nil t nil
+                                        '(invisible t evaporate t))
                       (forward-char)))  ; skip separator
 
                    ;; Soft alignment...
@@ -1084,10 +1092,9 @@ If there is no selected region, default to the whole buffer."
                         (when (> left-padding 0)
                           ;; Display spaces before first field
                           ;; by overlaying first character:
-                          (overlay-put
-                           (make-overlay beg (1+ beg))
-                           'before-string
-                           (make-string left-padding ?\ )))
+                         (csv--make-overlay
+                          beg (1+ beg) nil nil nil
+                          `(before-string ,(make-string left-padding ?\ ))))
                       ;; Display separator as spaces:
                       (with-silent-modifications
                         (put-text-property
@@ -1098,7 +1105,7 @@ If there is no selected region, default to the whole buffer."
                     (setq column (+ column column-width align-padding)))
 
                    (t ;; Do not hide separators...
-                    (let ((overlay (make-overlay beg (point) nil nil t)))
+                    (let ((overlay (csv--make-overlay beg (point) nil nil t)))
                       (when (> left-padding 0) ; Pad on the left.
                         ;; Display spaces before field:
                         (overlay-put overlay 'before-string
@@ -1128,7 +1135,7 @@ If there is no selected region, default to the whole buffer."
                          (list (region-beginning) (region-end))
                        (list (point-min) (point-max)))))
   ;; Remove any soft alignment:
-  (mapc 'delete-overlay        (overlays-in beg end))
+  (mapc #'csv--delete-overlay (overlays-in beg end))
   (with-silent-modifications
     (remove-list-of-text-properties beg end '(display)))
   (when hard
@@ -1179,7 +1186,7 @@ When called non-interactively, BEG and END specify region to process."
            rows columns)
        ;; Remove soft alignment if necessary:
        (when align
-         (mapc 'delete-overlay align)
+         (mapc 'csv--delete-overlay align)
          (setq align t))
        (while (not (eobp))
          (if (csv-not-looking-at-record)