Advertisement
mark-naylor-1701

sort rectangle

May 20th, 2024 (edited)
1,432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.48 KB | None | 0 0
  1. (defun sort-rectangle (prefix)
  2.   "Sort the text of a rectangle.
  3.  
  4. Has the effect of sorting in place."
  5.   (interactive "p")
  6.   (when-let ((_ (region-active-p))
  7.              (anchor (region-beginning)))
  8.     (kill-rectangle anchor (region-end))
  9.     (with-temp-buffer
  10.      (yank-rectangle)
  11.      (let ((start (point-min))
  12.            (stop  (point-max)))
  13.        (sort-lines (= prefix 4) start stop)
  14.        (kill-rectangle start stop)))
  15.     (goto-char anchor)
  16.     (yank-rectangle)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement