Function: csv-sort-fields-1
csv-sort-fields-1 is a natively compiled function defined in
csv-mode.el.
Signature
(csv-sort-fields-1 FIELD BEG END STARTKEYFUN ENDKEYFUN)
Documentation
Modified version of sort-fields-1 that skips blank or comment lines.
FIELD is a single field index, and BEG and END specify the region to sort.
STARTKEYFUN moves from the start of the record to the start of the key. It may return either a non-nil value to be used as the key, or else the key is the substring between the values of point after STARTKEYFUN and ENDKEYFUN are called. If STARTKEYFUN is nil, the key starts at the beginning of the record.
ENDKEYFUN moves from the start of the sort key to the end of the sort key. ENDKEYFUN may be nil if STARTKEYFUN returns a value or if it would be the same as ENDRECFUN.
Source Code
;; Defined in /nix/store/3gmjnyw9n226b7k7jamikx980vf8267p-emacs-packages-deps/share/emacs/site-lisp/elpa/csv-mode-1.27/csv-mode.el
(defun csv-sort-fields-1 (field beg end startkeyfun endkeyfun)
"Modified version of `sort-fields-1' that skips blank or comment lines.
FIELD is a single field index, and BEG and END specify the region to
sort.
STARTKEYFUN moves from the start of the record to the start of the key.
It may return either a non-nil value to be used as the key, or
else the key is the substring between the values of point after
STARTKEYFUN and ENDKEYFUN are called. If STARTKEYFUN is nil, the key
starts at the beginning of the record.
ENDKEYFUN moves from the start of the sort key to the end of the sort key.
ENDKEYFUN may be nil if STARTKEYFUN returns a value or if it would be the
same as ENDRECFUN."
(let ((tbl (syntax-table)))
(if (zerop field) (setq field 1))
(unwind-protect
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
(set-syntax-table sort-fields-syntax-table)
(sort-subr csv-descending
'csv-nextrecfun 'end-of-line
startkeyfun endkeyfun)))
(set-syntax-table tbl))))