]> code.delx.au - gnu-emacs-elpa/commitdiff
* csv-mode.el (csv-kill-one-field): Check for presence before deleting trailing
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 24 Apr 2013 19:28:41 +0000 (15:28 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 24 Apr 2013 19:28:41 +0000 (15:28 -0400)
separator.  Remove last arg and turn into a function.
(csv-kill-one-column, csv-kill-many-columns): Adjust callers.

packages/csv-mode/csv-mode.el

index fb6a6391e63cb189169773b31d58a5e712f715b5..dbc6182b42eb4e691b120034cf4349fa0c2557f6 100644 (file)
@@ -1,11 +1,11 @@
 ;;; csv-mode.el --- Major mode for editing comma/char separated values  -*- lexical-binding: t -*-
 
-;; Copyright (C) 2003, 2004, 2012  Free Software Foundation, Inc
+;; Copyright (C) 2003, 2004, 2012, 2013  Free Software Foundation, Inc
 
 ;; Author: Francis J. Wright <F.J.Wright at qmul.ac.uk>
 ;; Time-stamp: <23 August 2004>
 ;; URL: http://centaur.maths.qmul.ac.uk/Emacs/
-;; Version: 1.1
+;; Version: 1.2
 ;; Keywords: convenience
 
 ;; This package is free software; you can redistribute it and/or modify
@@ -844,21 +844,18 @@ and END specify the region to process."
        (csv-kill-one-column (car fields)))))
   (setq csv-killed-fields (nreverse csv-killed-fields)))
 
-(defmacro csv-kill-one-field (field killed-fields)
+(defun csv-kill-one-field (field)
   "Kill field with index FIELD in current line.
-Save killed field by `push'ing onto KILLED-FIELDS.
-Assumes point is at beginning of line.
-Called by `csv-kill-one-column' and `csv-kill-many-columns'."
-  `(progn
-     ;; Move to start of field to kill:
-     (csv-sort-skip-fields ,field)
-     ;; Kill to end of field (cf. `kill-region'):
-     (push (delete-and-extract-region
-           (point)
-           (progn (csv-end-of-field) (point)))
-          ,killed-fields)
-     (if (eolp) (delete-char -1)    ; delete trailing separator at eol
-       (delete-char 1))))          ; or following separator otherwise
+Return killed text.  Assumes point is at beginning of line."
+  ;; Move to start of field to kill:
+  (csv-sort-skip-fields field)
+  ;; Kill to end of field (cf. `kill-region'):
+  (prog1 (delete-and-extract-region
+          (point)
+          (progn (csv-end-of-field) (point)))
+    (if (eolp)
+        (unless (bolp) (delete-char -1)) ; Delete trailing separator at eol
+      (delete-char 1))))                 ; or following separator otherwise.
 
 (defun csv-kill-one-column (field)
   "Kill field with index FIELD in all lines in (narrowed) buffer.
@@ -867,7 +864,7 @@ Assumes point is at `point-min'.  Called by `csv-kill-fields'.
 Ignore blank and comment lines."
   (while (not (eobp))
     (or (csv-not-looking-at-record)
-       (csv-kill-one-field field csv-killed-fields))
+       (push (csv-kill-one-field field) csv-killed-fields))
     (forward-line)))
 
 (defun csv-kill-many-columns (fields)
@@ -912,7 +909,7 @@ Ignore blank and comment lines."
            (setq field (car fields)
                  fields (cdr fields))
            (beginning-of-line)
-           (csv-kill-one-field field killed-fields))
+           (push (csv-kill-one-field field) killed-fields))
          (push (mapconcat 'identity killed-fields (car csv-separators))
                csv-killed-fields)))
     (forward-line)))