[Top][All Lists]

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

sort buffer [random] and sort whole lines

From: Emanuel Berg
Subject: sort buffer [random] and sort whole lines
Date: Mon, 18 Mar 2019 17:04:18 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

I don't know if this is good or bad (well,
enough with the false modesty already, it seems
to work alright after >zero testing) but I know
for sure stuff like this should be available at
the fingertips for every Emacs user.

The buffer as the building block, and
automations as the bloodstream, have *always*
been our moneymakers, right?

Comments on code welcome, as always :)


(defun sort-lines-random (start end)
  (interactive "r")
      (narrow-to-region start end)
      (goto-char (point-min))
      (sort-subr nil            ; not REVERSE
                 #'forward-line ; NEXTRECFUN
                 #'end-of-line  ; ENDRECFUN
                 nil nil        ; no keys (STARTKEYFUN and ENDKEYFUN)
                 (lambda (a b) (zerop (random 2)) )))))


(defun sort-whole-lines (start end)
  (interactive "r")
    (let ((start (progn (goto-char start) (line-beginning-position)))
          (end   (progn (goto-char end)   (line-end-position))) )
      (sort-lines nil start end) ))) ; nil = not REVERSE


(defun sort-buffer ()
  (sort-whole-lines (point-min) (point-max)) )

(defun sort-buffer-random ()
  (sort-lines-random (point-min) (point-max)) )

More sorting:

underground experts united

reply via email to

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