Function: csv-kill-many-columns
csv-kill-many-columns is a natively compiled function defined in
csv-mode.el.
Signature
(csv-kill-many-columns FIELDS)
Documentation
Kill several fields in all lines in (narrowed) buffer.
FIELDS is an unordered list of field indices.
Save killed fields in increasing index order in csv-killed-fields.
Assumes point is at point-min. Called by csv-kill-fields.
Ignore blank and comment lines.
Source Code
;; Defined in /nix/store/3gmjnyw9n226b7k7jamikx980vf8267p-emacs-packages-deps/share/emacs/site-lisp/elpa/csv-mode-1.27/csv-mode.el
(defun csv-kill-many-columns (fields)
"Kill several fields in all lines in (narrowed) buffer.
FIELDS is an unordered list of field indices.
Save killed fields in increasing index order in `csv-killed-fields'.
Assumes point is at `point-min'. Called by `csv-kill-fields'.
Ignore blank and comment lines."
(if (eolp) (error "First record is empty"))
;; Convert non-positive to positive field numbers:
(let ((last 1) (f fields))
(csv-end-of-field)
(while (not (eolp))
(forward-char) ; skip separator
(csv-end-of-field)
(setq last (1+ last))) ; last = # fields in first record
(while f
(cond ((consp (car f))
;; Expand a field range: (m.n) -> m m+1 ... n-1 n.
;; If n is nil then it defaults to the number of fields.
(let* ((range (car f)) (cdrf (cdr f))
(m (car range)) (n (cdr range)))
(if (< m 0) (setq m (+ m last 1)))
(if n
(if (< n 0) (setq n (+ n last 1)))
(setq n last))
(setq range (list n))
(while (> n m) (push (setq n (1- n)) range))
(setcar f (car range))
(setcdr f (cdr range))
(setcdr (setq f (last range)) cdrf)))
((zerop (car f)) (setcar f 1))
((< (car f) 0) (setcar f (+ f last 1))))
(setq f (cdr f))))
(goto-char (point-min))
;; Kill from right to avoid miscounting:
(setq fields (sort fields #'>))
(while (not (eobp))
(or (csv-not-looking-at-record)
(let ((fields fields) killed-fields field)
(while fields
(setq field (car fields)
fields (cdr fields))
(beginning-of-line)
(push (csv-kill-one-field field) killed-fields))
(push (mapconcat #'identity killed-fields (car csv-separators))
csv-killed-fields)))
(forward-line)))