sort.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. ;;; sort.el --- commands to sort text in an Emacs buffer
  2. ;; Copyright (C) 1986-1987, 1994-1995, 2001-2012
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Howie Kaye
  5. ;; Maintainer: FSF
  6. ;; Keywords: unix
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; This package provides the sorting facilities documented in the Emacs
  20. ;; user's manual.
  21. ;;; Code:
  22. (defgroup sort nil
  23. "Commands to sort text in an Emacs buffer."
  24. :group 'data)
  25. (defcustom sort-fold-case nil
  26. "Non-nil if the buffer sort functions should ignore case."
  27. :group 'sort
  28. :type 'boolean)
  29. ;;;###autoload(put 'sort-fold-case 'safe-local-variable 'booleanp)
  30. ;;;###autoload
  31. (defun sort-subr (reverse nextrecfun endrecfun
  32. &optional startkeyfun endkeyfun predicate)
  33. "General text sorting routine to divide buffer into records and sort them.
  34. We divide the accessible portion of the buffer into disjoint pieces
  35. called sort records. A portion of each sort record (perhaps all of
  36. it) is designated as the sort key. The records are rearranged in the
  37. buffer in order by their sort keys. The records may or may not be
  38. contiguous.
  39. Usually the records are rearranged in order of ascending sort key.
  40. If REVERSE is non-nil, they are rearranged in order of descending sort key.
  41. The variable `sort-fold-case' determines whether alphabetic case affects
  42. the sort order.
  43. The next four arguments are functions to be called to move point
  44. across a sort record. They will be called many times from within sort-subr.
  45. NEXTRECFUN is called with point at the end of the previous record.
  46. It moves point to the start of the next record.
  47. It should move point to the end of the buffer if there are no more records.
  48. The first record is assumed to start at the position of point when sort-subr
  49. is called.
  50. ENDRECFUN is called with point within the record.
  51. It should move point to the end of the record.
  52. STARTKEYFUN moves from the start of the record to the start of the key.
  53. It may return either a non-nil value to be used as the key, or
  54. else the key is the substring between the values of point after
  55. STARTKEYFUN and ENDKEYFUN are called. If STARTKEYFUN is nil, the key
  56. starts at the beginning of the record.
  57. ENDKEYFUN moves from the start of the sort key to the end of the sort key.
  58. ENDKEYFUN may be nil if STARTKEYFUN returns a value or if it would be the
  59. same as ENDRECFUN.
  60. PREDICATE is the function to use to compare keys. If keys are numbers,
  61. it defaults to `<', otherwise it defaults to `string<'."
  62. ;; Heuristically try to avoid messages if sorting a small amt of text.
  63. (let ((messages (> (- (point-max) (point-min)) 50000)))
  64. (save-excursion
  65. (if messages (message "Finding sort keys..."))
  66. (let* ((sort-lists (sort-build-lists nextrecfun endrecfun
  67. startkeyfun endkeyfun))
  68. (old (reverse sort-lists))
  69. (case-fold-search sort-fold-case))
  70. (if (null sort-lists)
  71. ()
  72. (or reverse (setq sort-lists (nreverse sort-lists)))
  73. (if messages (message "Sorting records..."))
  74. (setq sort-lists
  75. (sort sort-lists
  76. (cond (predicate
  77. `(lambda (a b) (,predicate (car a) (car b))))
  78. ((numberp (car (car sort-lists)))
  79. 'car-less-than-car)
  80. ((consp (car (car sort-lists)))
  81. (lambda (a b)
  82. (> 0 (compare-buffer-substrings
  83. nil (car (car a)) (cdr (car a))
  84. nil (car (car b)) (cdr (car b))))))
  85. (t
  86. (lambda (a b) (string< (car a) (car b)))))))
  87. (if reverse (setq sort-lists (nreverse sort-lists)))
  88. (if messages (message "Reordering buffer..."))
  89. (sort-reorder-buffer sort-lists old)))
  90. (if messages (message "Reordering buffer... Done"))))
  91. nil)
  92. ;; Parse buffer into records using the arguments as Lisp expressions;
  93. ;; return a list of records. Each record looks like (KEY STARTPOS . ENDPOS)
  94. ;; where KEY is the sort key (a number or string),
  95. ;; and STARTPOS and ENDPOS are the bounds of this record in the buffer.
  96. ;; The records appear in the list lastmost first!
  97. (defun sort-build-lists (nextrecfun endrecfun startkeyfun endkeyfun)
  98. (let ((sort-lists ())
  99. (start-rec nil)
  100. done key)
  101. ;; Loop over sort records.
  102. ;(goto-char (point-min)) -- it is the caller's responsibility to
  103. ;arrange this if necessary
  104. (while (not (eobp))
  105. (setq start-rec (point)) ;save record start
  106. (setq done nil)
  107. ;; Get key value, or move to start of key.
  108. (setq key (catch 'key
  109. (or (and startkeyfun (funcall startkeyfun))
  110. ;; If key was not returned as value,
  111. ;; move to end of key and get key from the buffer.
  112. (let ((start (point)))
  113. (funcall (or endkeyfun
  114. (prog1 endrecfun (setq done t))))
  115. (cons start (point))))))
  116. ;; Move to end of this record (start of next one, or end of buffer).
  117. (cond ((prog1 done (setq done nil)))
  118. (endrecfun (funcall endrecfun))
  119. (nextrecfun (funcall nextrecfun) (setq done t)))
  120. (if key (push
  121. ;; consing optimization in case in which key is same as record.
  122. (if (and (consp key)
  123. (equal (car key) start-rec)
  124. (equal (cdr key) (point)))
  125. (cons key key)
  126. (cons key (cons start-rec (point))))
  127. sort-lists))
  128. (and (not done) nextrecfun (funcall nextrecfun)))
  129. sort-lists))
  130. (defun sort-reorder-buffer (sort-lists old)
  131. (let ((last (point-min))
  132. (min (point-min)) (max (point-max))
  133. (old-buffer (current-buffer))
  134. (mb enable-multibyte-characters)
  135. temp-buffer)
  136. (with-temp-buffer
  137. (set-buffer-multibyte mb)
  138. ;; Record the temporary buffer.
  139. (setq temp-buffer (current-buffer))
  140. ;; Copy the sorted text into the temporary buffer.
  141. (while sort-lists
  142. (goto-char (point-max))
  143. (insert-buffer-substring old-buffer
  144. last
  145. (nth 1 (car old)))
  146. (goto-char (point-max))
  147. (insert-buffer-substring old-buffer
  148. (nth 1 (car sort-lists))
  149. (cdr (cdr (car sort-lists))))
  150. (setq last (cdr (cdr (car old)))
  151. sort-lists (cdr sort-lists)
  152. old (cdr old)))
  153. (goto-char (point-max))
  154. (insert-buffer-substring old-buffer last max)
  155. ;; Copy the reordered text from the temporary buffer
  156. ;; to the buffer we sorted (OLD-BUFFER).
  157. (set-buffer old-buffer)
  158. (let ((inhibit-quit t))
  159. ;; Make sure insertions done for reordering
  160. ;; saves any markers at the end of the sorted region,
  161. ;; by leaving the last character of the region.
  162. (delete-region min (1- max))
  163. ;; Now replace the one remaining old character with the sorted text.
  164. (goto-char (point-min))
  165. (insert-buffer-substring temp-buffer)
  166. (delete-region max (1+ max))))))
  167. ;;;###autoload
  168. (defun sort-lines (reverse beg end)
  169. "Sort lines in region alphabetically; argument means descending order.
  170. Called from a program, there are three arguments:
  171. REVERSE (non-nil means reverse order), BEG and END (region to sort).
  172. The variable `sort-fold-case' determines whether alphabetic case affects
  173. the sort order."
  174. (interactive "P\nr")
  175. (save-excursion
  176. (save-restriction
  177. (narrow-to-region beg end)
  178. (goto-char (point-min))
  179. (let ;; To make `end-of-line' and etc. to ignore fields.
  180. ((inhibit-field-text-motion t))
  181. (sort-subr reverse 'forward-line 'end-of-line)))))
  182. ;;;###autoload
  183. (defun sort-paragraphs (reverse beg end)
  184. "Sort paragraphs in region alphabetically; argument means descending order.
  185. Called from a program, there are three arguments:
  186. REVERSE (non-nil means reverse order), BEG and END (region to sort).
  187. The variable `sort-fold-case' determines whether alphabetic case affects
  188. the sort order."
  189. (interactive "P\nr")
  190. (save-excursion
  191. (save-restriction
  192. (narrow-to-region beg end)
  193. (goto-char (point-min))
  194. (sort-subr reverse
  195. (function
  196. (lambda ()
  197. (while (and (not (eobp)) (looking-at paragraph-separate))
  198. (forward-line 1))))
  199. 'forward-paragraph))))
  200. ;;;###autoload
  201. (defun sort-pages (reverse beg end)
  202. "Sort pages in region alphabetically; argument means descending order.
  203. Called from a program, there are three arguments:
  204. REVERSE (non-nil means reverse order), BEG and END (region to sort).
  205. The variable `sort-fold-case' determines whether alphabetic case affects
  206. the sort order."
  207. (interactive "P\nr")
  208. (save-excursion
  209. (save-restriction
  210. (narrow-to-region beg end)
  211. (goto-char (point-min))
  212. (sort-subr reverse
  213. (function (lambda () (skip-chars-forward "\n")))
  214. 'forward-page))))
  215. (defvar sort-fields-syntax-table nil)
  216. (if sort-fields-syntax-table nil
  217. (let ((table (make-syntax-table))
  218. (i 0))
  219. (while (< i 256)
  220. (modify-syntax-entry i "w" table)
  221. (setq i (1+ i)))
  222. (modify-syntax-entry ?\s " " table)
  223. (modify-syntax-entry ?\t " " table)
  224. (modify-syntax-entry ?\n " " table)
  225. (modify-syntax-entry ?\. "_" table) ; for floating pt. numbers. -wsr
  226. (setq sort-fields-syntax-table table)))
  227. (defcustom sort-numeric-base 10
  228. "The default base used by `sort-numeric-fields'."
  229. :group 'sort
  230. :type 'integer)
  231. ;;;###autoload(put 'sort-numeric-base 'safe-local-variable 'integerp)
  232. ;;;###autoload
  233. (defun sort-numeric-fields (field beg end)
  234. "Sort lines in region numerically by the ARGth field of each line.
  235. Fields are separated by whitespace and numbered from 1 up.
  236. Specified field must contain a number in each line of the region,
  237. which may begin with \"0x\" or \"0\" for hexadecimal and octal values.
  238. Otherwise, the number is interpreted according to sort-numeric-base.
  239. With a negative arg, sorts by the ARGth field counted from the right.
  240. Called from a program, there are three arguments:
  241. FIELD, BEG and END. BEG and END specify region to sort."
  242. (interactive "p\nr")
  243. (let ;; To make `end-of-line' and etc. to ignore fields.
  244. ((inhibit-field-text-motion t))
  245. (sort-fields-1 field beg end
  246. (lambda ()
  247. (sort-skip-fields field)
  248. (let* ((case-fold-search t)
  249. (base
  250. (if (looking-at "\\(0x\\)[0-9a-f]\\|\\(0\\)[0-7]")
  251. (cond ((match-beginning 1)
  252. (goto-char (match-end 1))
  253. 16)
  254. ((match-beginning 2)
  255. (goto-char (match-end 2))
  256. 8)
  257. (t nil)))))
  258. (string-to-number (buffer-substring (point)
  259. (save-excursion
  260. (forward-sexp 1)
  261. (point)))
  262. (or base sort-numeric-base))))
  263. nil)))
  264. ;;;;;###autoload
  265. ;;(defun sort-float-fields (field beg end)
  266. ;; "Sort lines in region numerically by the ARGth field of each line.
  267. ;;Fields are separated by whitespace and numbered from 1 up. Specified field
  268. ;;must contain a floating point number in each line of the region. With a
  269. ;;negative arg, sorts by the ARGth field counted from the right. Called from a
  270. ;;program, there are three arguments: FIELD, BEG and END. BEG and END specify
  271. ;;region to sort."
  272. ;; (interactive "p\nr")
  273. ;; (sort-fields-1 field beg end
  274. ;; (function (lambda ()
  275. ;; (sort-skip-fields field)
  276. ;; (string-to-number
  277. ;; (buffer-substring
  278. ;; (point)
  279. ;; (save-excursion
  280. ;; (re-search-forward
  281. ;; "[+-]?[0-9]*\.?[0-9]*\\([eE][+-]?[0-9]+\\)?")
  282. ;; (point))))))
  283. ;; nil))
  284. ;;;###autoload
  285. (defun sort-fields (field beg end)
  286. "Sort lines in region lexicographically by the ARGth field of each line.
  287. Fields are separated by whitespace and numbered from 1 up.
  288. With a negative arg, sorts by the ARGth field counted from the right.
  289. Called from a program, there are three arguments:
  290. FIELD, BEG and END. BEG and END specify region to sort.
  291. The variable `sort-fold-case' determines whether alphabetic case affects
  292. the sort order."
  293. (interactive "p\nr")
  294. (let ;; To make `end-of-line' and etc. to ignore fields.
  295. ((inhibit-field-text-motion t))
  296. (sort-fields-1 field beg end
  297. (function (lambda ()
  298. (sort-skip-fields field)
  299. nil))
  300. (function (lambda () (skip-chars-forward "^ \t\n"))))))
  301. (defun sort-fields-1 (field beg end startkeyfun endkeyfun)
  302. (let ((tbl (syntax-table)))
  303. (if (zerop field) (setq field 1))
  304. (unwind-protect
  305. (save-excursion
  306. (save-restriction
  307. (narrow-to-region beg end)
  308. (goto-char (point-min))
  309. (set-syntax-table sort-fields-syntax-table)
  310. (sort-subr nil
  311. 'forward-line 'end-of-line
  312. startkeyfun endkeyfun)))
  313. (set-syntax-table tbl))))
  314. ;; Position at the beginning of field N on the current line,
  315. ;; assuming point is initially at the beginning of the line.
  316. (defun sort-skip-fields (n)
  317. (if (> n 0)
  318. ;; Skip across N - 1 fields.
  319. (let ((i (1- n)))
  320. (while (> i 0)
  321. (skip-chars-forward " \t")
  322. (skip-chars-forward "^ \t\n")
  323. (setq i (1- i)))
  324. (skip-chars-forward " \t")
  325. (if (eolp)
  326. (error "Line has too few fields: %s"
  327. (buffer-substring
  328. (line-beginning-position)
  329. (line-end-position)))))
  330. (end-of-line)
  331. ;; Skip back across - N - 1 fields.
  332. (let ((i (1- (- n))))
  333. (while (> i 0)
  334. (skip-chars-backward " \t")
  335. (skip-chars-backward "^ \t\n")
  336. (setq i (1- i)))
  337. (skip-chars-backward " \t"))
  338. (if (bolp)
  339. (error "Line has too few fields: %s"
  340. (buffer-substring
  341. (line-beginning-position)
  342. (line-end-position))))
  343. ;; Position at the front of the field
  344. ;; even if moving backwards.
  345. (skip-chars-backward "^ \t\n")))
  346. (defvar sort-regexp-fields-regexp)
  347. (defvar sort-regexp-record-end)
  348. ;; Move to the beginning of the next match for record-regexp,
  349. ;; and set sort-regexp-record-end to the end of that match.
  350. ;; If the next match is empty and does not advance point,
  351. ;; skip one character and try again.
  352. (defun sort-regexp-fields-next-record ()
  353. (let ((oldpos (point)))
  354. (and (re-search-forward sort-regexp-fields-regexp nil 'move)
  355. (setq sort-regexp-record-end (match-end 0))
  356. (if (= sort-regexp-record-end oldpos)
  357. (progn
  358. (forward-char 1)
  359. (re-search-forward sort-regexp-fields-regexp nil 'move)
  360. (setq sort-regexp-record-end (match-end 0)))
  361. t)
  362. (goto-char (match-beginning 0)))))
  363. ;;;###autoload
  364. (defun sort-regexp-fields (reverse record-regexp key-regexp beg end)
  365. "Sort the region lexicographically as specified by RECORD-REGEXP and KEY.
  366. RECORD-REGEXP specifies the textual units which should be sorted.
  367. For example, to sort lines RECORD-REGEXP would be \"^.*$\"
  368. KEY specifies the part of each record (ie each match for RECORD-REGEXP)
  369. is to be used for sorting.
  370. If it is \"\\\\digit\" then the digit'th \"\\\\(...\\\\)\" match field from
  371. RECORD-REGEXP is used.
  372. If it is \"\\\\&\" then the whole record is used.
  373. Otherwise, it is a regular-expression for which to search within the record.
  374. If a match for KEY is not found within a record then that record is ignored.
  375. With a negative prefix arg sorts in reverse order.
  376. The variable `sort-fold-case' determines whether alphabetic case affects
  377. the sort order.
  378. For example: to sort lines in the region by the first word on each line
  379. starting with the letter \"f\",
  380. RECORD-REGEXP would be \"^.*$\" and KEY would be \"\\\\=\\<f\\\\w*\\\\>\""
  381. ;; using negative prefix arg to mean "reverse" is now inconsistent with
  382. ;; other sort-.*fields functions but then again this was before, since it
  383. ;; didn't use the magnitude of the arg to specify anything.
  384. (interactive "P\nsRegexp specifying records to sort: \n\
  385. sRegexp specifying key within record: \nr")
  386. (cond ((or (equal key-regexp "") (equal key-regexp "\\&"))
  387. (setq key-regexp 0))
  388. ((string-match "\\`\\\\[1-9]\\'" key-regexp)
  389. (setq key-regexp (- (aref key-regexp 1) ?0))))
  390. (save-excursion
  391. (save-restriction
  392. (narrow-to-region beg end)
  393. (goto-char (point-min))
  394. (let (sort-regexp-record-end
  395. (sort-regexp-fields-regexp record-regexp))
  396. (re-search-forward sort-regexp-fields-regexp nil t)
  397. (setq sort-regexp-record-end (point))
  398. (goto-char (match-beginning 0))
  399. (sort-subr reverse
  400. 'sort-regexp-fields-next-record
  401. (function (lambda ()
  402. (goto-char sort-regexp-record-end)))
  403. (function (lambda ()
  404. (let ((n 0))
  405. (cond ((numberp key-regexp)
  406. (setq n key-regexp))
  407. ((re-search-forward
  408. key-regexp sort-regexp-record-end t)
  409. (setq n 0))
  410. (t (throw 'key nil)))
  411. (condition-case ()
  412. (cons (match-beginning n)
  413. (match-end n))
  414. ;; if there was no such register
  415. (error (throw 'key nil)))))))))))
  416. (defvar sort-columns-subprocess t)
  417. ;;;###autoload
  418. (defun sort-columns (reverse &optional beg end)
  419. "Sort lines in region alphabetically by a certain range of columns.
  420. For the purpose of this command, the region BEG...END includes
  421. the entire line that point is in and the entire line the mark is in.
  422. The column positions of point and mark bound the range of columns to sort on.
  423. A prefix argument means sort into REVERSE order.
  424. The variable `sort-fold-case' determines whether alphabetic case affects
  425. the sort order.
  426. Note that `sort-columns' rejects text that contains tabs,
  427. because tabs could be split across the specified columns
  428. and it doesn't know how to handle that. Also, when possible,
  429. it uses the `sort' utility program, which doesn't understand tabs.
  430. Use \\[untabify] to convert tabs to spaces before sorting."
  431. (interactive "P\nr")
  432. (save-excursion
  433. (let ;; To make `end-of-line' and etc. to ignore fields.
  434. ((inhibit-field-text-motion t)
  435. beg1 end1 col-beg1 col-end1 col-start col-end)
  436. (goto-char (min beg end))
  437. (setq col-beg1 (current-column))
  438. (beginning-of-line)
  439. (setq beg1 (point))
  440. (goto-char (max beg end))
  441. (setq col-end1 (current-column))
  442. (forward-line)
  443. (setq end1 (point))
  444. (setq col-start (min col-beg1 col-end1))
  445. (setq col-end (max col-beg1 col-end1))
  446. (if (search-backward "\t" beg1 t)
  447. (error "sort-columns does not work with tabs -- use M-x untabify"))
  448. (if (not (or (memq system-type '(windows-nt))
  449. (let ((pos beg1) plist fontified)
  450. (catch 'found
  451. (while (< pos end1)
  452. (setq plist (text-properties-at pos))
  453. (setq fontified (plist-get plist 'fontified))
  454. (while (consp plist)
  455. (unless (or (eq (car plist) 'fontified)
  456. (and (eq (car plist) 'face)
  457. fontified))
  458. (throw 'found t))
  459. (setq plist (cddr plist)))
  460. (setq pos (next-property-change pos nil end1)))))))
  461. ;; Use the sort utility if we can; it is 4 times as fast.
  462. ;; Do not use it if there are any non-font-lock properties
  463. ;; in the region, since the sort utility would lose the
  464. ;; properties. Tabs are used as field separator; on NetBSD,
  465. ;; sort complains if "\n" is used as field separator.
  466. (let ((sort-args (list (if reverse "-rt\t" "-t\t")
  467. (format "-k1.%d,1.%d"
  468. (1+ col-start)
  469. (1+ col-end)))))
  470. (when sort-fold-case
  471. (push "-f" sort-args))
  472. (apply #'call-process-region beg1 end1 "sort" t t nil sort-args))
  473. ;; On ms-windows, use Emacs's own facilities.
  474. (save-excursion
  475. (save-restriction
  476. (narrow-to-region beg1 end1)
  477. (goto-char beg1)
  478. (sort-subr reverse 'forward-line 'end-of-line
  479. #'(lambda () (move-to-column col-start) nil)
  480. #'(lambda () (move-to-column col-end) nil))))))))
  481. ;;;###autoload
  482. (defun reverse-region (beg end)
  483. "Reverse the order of lines in a region.
  484. From a program takes two point or marker arguments, BEG and END."
  485. (interactive "r")
  486. (if (> beg end)
  487. (let (mid) (setq mid end end beg beg mid)))
  488. (save-excursion
  489. ;; put beg at the start of a line and end and the end of one --
  490. ;; the largest possible region which fits this criteria
  491. (goto-char beg)
  492. (or (bolp) (forward-line 1))
  493. (setq beg (point))
  494. (goto-char end)
  495. ;; the test for bolp is for those times when end is on an empty line;
  496. ;; it is probably not the case that the line should be included in the
  497. ;; reversal; it isn't difficult to add it afterward.
  498. (or (and (eolp) (not (bolp))) (progn (forward-line -1) (end-of-line)))
  499. (setq end (point-marker))
  500. ;; the real work. this thing cranks through memory on large regions.
  501. (let (ll (do t))
  502. (while do
  503. (goto-char beg)
  504. (setq ll (cons (buffer-substring (point) (progn (end-of-line) (point)))
  505. ll))
  506. (setq do (/= (point) end))
  507. (delete-region beg (if do (1+ (point)) (point))))
  508. (while (cdr ll)
  509. (insert (car ll) "\n")
  510. (setq ll (cdr ll)))
  511. (insert (car ll)))))
  512. (provide 'sort)
  513. ;;; sort.el ends here