164 |
sort-lists)) |
sort-lists)) |
165 |
|
|
166 |
(defun sort-reorder-buffer (sort-lists old) |
(defun sort-reorder-buffer (sort-lists old) |
167 |
(let ((inhibit-quit t) |
(let ((last (point-min)) |
168 |
(last (point-min)) |
(min (point-min)) (max (point-max)) |
169 |
(min (point-min)) (max (point-max))) |
(old-buffer (current-buffer)) |
170 |
;; Make sure insertions done for reordering |
temp-buffer) |
171 |
;; do not go after any markers at the end of the sorted region, |
(with-temp-buffer |
172 |
;; by inserting a space to separate them. |
;; Record the temporary buffer. |
173 |
(goto-char (point-max)) |
(setq temp-buffer (current-buffer)) |
174 |
(insert-before-markers " ") |
|
175 |
(narrow-to-region min (1- (point-max))) |
;; Copy the sorted text into the temporary buffer. |
176 |
(while sort-lists |
(while sort-lists |
177 |
|
(goto-char (point-max)) |
178 |
|
(insert-buffer-substring old-buffer |
179 |
|
last |
180 |
|
(nth 1 (car old))) |
181 |
|
(goto-char (point-max)) |
182 |
|
(insert-buffer-substring old-buffer |
183 |
|
(nth 1 (car sort-lists)) |
184 |
|
(cdr (cdr (car sort-lists)))) |
185 |
|
(setq last (cdr (cdr (car old))) |
186 |
|
sort-lists (cdr sort-lists) |
187 |
|
old (cdr old))) |
188 |
(goto-char (point-max)) |
(goto-char (point-max)) |
189 |
(insert-buffer-substring (current-buffer) |
(insert-buffer-substring old-buffer |
190 |
last |
last |
191 |
(nth 1 (car old))) |
max) |
192 |
(goto-char (point-max)) |
|
193 |
(insert-buffer-substring (current-buffer) |
;; Copy the reordered text from the temporary buffer |
194 |
(nth 1 (car sort-lists)) |
;; to the buffer we sorted (OLD-BUFFER). |
195 |
(cdr (cdr (car sort-lists)))) |
(set-buffer old-buffer) |
196 |
(setq last (cdr (cdr (car old))) |
(let ((inhibit-quit t)) |
197 |
sort-lists (cdr sort-lists) |
;; Make sure insertions done for reordering |
198 |
old (cdr old))) |
;; do not go after any markers at the end of the sorted region, |
199 |
(goto-char (point-max)) |
;; by inserting a space to separate them. |
200 |
(insert-buffer-substring (current-buffer) |
(goto-char max) |
201 |
last |
(insert-before-markers " ") |
202 |
max) |
;; Delete the original copy of the text. |
203 |
;; Delete the original copy of the text. |
(delete-region min max) |
204 |
(delete-region min max) |
;; Now replace the separator " " with the sorted text. |
205 |
;; Get rid of the separator " ". |
(goto-char (point-max)) |
206 |
(goto-char (point-max)) |
(insert-buffer-substring temp-buffer 1 (1+ (- max min))) |
207 |
(narrow-to-region min (1+ (point))) |
(delete-region min (1+ min)))))) |
|
(delete-region (point) (1+ (point))))) |
|
208 |
|
|
209 |
;;;###autoload |
;;;###autoload |
210 |
(defun sort-lines (reverse beg end) |
(defun sort-lines (reverse beg end) |