Function: sort-fields
sort-fields is an autoloaded, interactive and byte-compiled function
defined in sort.el.gz.
Signature
(sort-fields FIELD BEG END)
Documentation
Sort lines in region lexicographically by the ARGth field of each line.
Fields are separated by whitespace and numbered from 1 up.
With a negative arg, sorts by the ARGth field counted from the right.
Called from a program, there are three arguments:
FIELD, BEG and END. BEG and END specify region to sort.
The variable sort-fold-case determines whether alphabetic case affects
the sort order.
Probably introduced at or before Emacs version 18.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/sort.el.gz
;;;;;###autoload
;;(defun sort-float-fields (field beg end)
;; "Sort lines in region numerically by the ARGth field of each line.
;;Fields are separated by whitespace and numbered from 1 up. Specified field
;;must contain a floating point number in each line of the region. With a
;;negative arg, sorts by the ARGth field counted from the right. Called from a
;;program, there are three arguments: FIELD, BEG and END. BEG and END specify
;;region to sort."
;; (interactive "p\nr")
;; (sort-fields-1 field beg end
;; (lambda ()
;; (sort-skip-fields field)
;; (string-to-number
;; (buffer-substring
;; (point)
;; (save-excursion
;; (re-search-forward
;; "[+-]?[0-9]*\\.?[0-9]*\\([eE][+-]?[0-9]+\\)?")
;; (point)))))
;; nil))
;;;###autoload
(defun sort-fields (field beg end)
"Sort lines in region lexicographically by the ARGth field of each line.
Fields are separated by whitespace and numbered from 1 up.
With a negative arg, sorts by the ARGth field counted from the right.
Called from a program, there are three arguments:
FIELD, BEG and END. BEG and END specify region to sort.
The variable `sort-fold-case' determines whether alphabetic case affects
the sort order."
(interactive "p\nr")
(let ;; To make `end-of-line' and etc. to ignore fields.
((inhibit-field-text-motion t))
(sort-fields-1 field beg end
(lambda ()
(sort-skip-fields field)
nil)
(lambda () (skip-chars-forward "^ \t\n")))))