From 6229d19438d641d3ec81dec962984b3a9f5f72e7 Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Fri, 8 Jul 2016 00:46:20 +0200 Subject: [PATCH] Make sort-lines accept a predicate --- lisp/sort.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lisp/sort.el b/lisp/sort.el index 4d7311f..266b916 100644 --- a/lisp/sort.el +++ b/lisp/sort.el @@ -1,4 +1,4 @@ -;;; sort.el --- commands to sort text in an Emacs buffer +;;; sort.el --- commands to sort text in an Emacs buffer -*- lexical-binding : t -*- ;; Copyright (C) 1986-1987, 1994-1995, 2001-2016 Free Software ;; Foundation, Inc. @@ -99,7 +99,7 @@ sort-subr (setq sort-lists (sort sort-lists (cond (predicate - `(lambda (a b) (,predicate (car a) (car b)))) + (lambda (a b) (funcall predicate (car a) (car b)))) ((numberp (car (car sort-lists))) 'car-less-than-car) ((consp (car (car sort-lists))) @@ -197,7 +197,7 @@ sort-reorder-buffer (delete-region max (1+ max)))))) ;;;###autoload -(defun sort-lines (reverse beg end) +(defun sort-lines (reverse beg end &optional predicate) "Sort lines in region alphabetically; argument means descending order. Called from a program, there are three arguments: REVERSE (non-nil means reverse order), BEG and END (region to sort). @@ -210,7 +210,13 @@ sort-lines (goto-char (point-min)) (let ;; To make `end-of-line' and etc. to ignore fields. ((inhibit-field-text-motion t)) - (sort-subr reverse 'forward-line 'end-of-line))))) + (sort-subr + reverse #'forward-line #'end-of-line nil nil + (and predicate + (lambda (a b) + (funcall predicate + (buffer-substring (car a) (cdr a)) + (buffer-substring (car b) (cdr b)))))))))) ;;;###autoload (defun sort-paragraphs (reverse beg end) -- 2.8.1