emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/csv-mode 08ee1af 09/34: * csv-mode.el (csv-kill-one-fie


From: Stefan Monnier
Subject: [elpa] externals/csv-mode 08ee1af 09/34: * csv-mode.el (csv-kill-one-field): Check for presence before deleting trailing
Date: Sun, 29 Nov 2020 18:46:13 -0500 (EST)

branch: externals/csv-mode
commit 08ee1afbd91cf17d1541673c371e355d97131264
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * csv-mode.el (csv-kill-one-field): Check for presence before deleting 
trailing
    separator.  Remove last arg and turn into a function.
    (csv-kill-one-column, csv-kill-many-columns): Adjust callers.
---
 csv-mode.el | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/csv-mode.el b/csv-mode.el
index fb6a639..dbc6182 100644
--- a/csv-mode.el
+++ b/csv-mode.el
@@ -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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]