[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 :)
;;; RANDOM
(defun sort-lines-random (start end)
(interactive "r")
(save-excursion
(save-restriction
(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)) )))))
;;; WHOLE LINES
(defun sort-whole-lines (start end)
(interactive "r")
(save-excursion
(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
;;; ENTIRE BUFFER
(defun sort-buffer ()
(interactive)
(sort-whole-lines (point-min) (point-max)) )
(defun sort-buffer-random ()
(interactive)
(sort-lines-random (point-min) (point-max)) )
More sorting:
http://user.it.uu.se/~embe8573/emacs-init/sort-my.el
--
underground experts united
http://user.it.uu.se/~embe8573
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- sort buffer [random] and sort whole lines,
Emanuel Berg <=