[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
sort-lines in HEAD is not compatible with current Emacs - with patch
From: |
Ehud Karni |
Subject: |
sort-lines in HEAD is not compatible with current Emacs - with patch |
Date: |
Thu, 27 Mar 2003 17:46:46 +0200 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
In GNU Emacs 21.3.50.3 (i686-redhat-linux-gnu)
of 2003-03-26 on beta
configured using `configure '--host=i686-redhat-linux-gnu' '--with-pop'
'--with-x-toolkit=gtk' '--with-xpm' '--with-jpeg' '--with-tiff' '--with-gif'
'--with-png' 'CFLAGS=-O2 -DSITELOAD_PURESIZE_EXTRA=800000'
'host_alias=i686-redhat-linux-gnu''
I found an incompatibility in `sort-lines' (and really any buffer sort)
between the HEAD version and the current version. The HEAD version
destroys markers at the _end_ of the sorted area. To demonstrate it
use the following function:
(defun test-sort-lines ()
(interactive)
(let ((cnt 17)
(reverse nil)
beg end
mrkb mrki mrke)
(set-buffer (get-buffer-create "test-sort-buf"))
(delete-region (point-min) (point-max))
(while (> cnt 0)
(insert (format " line == %3d ==\n" cnt))
(setq cnt (1- cnt)))
(goto-char (point-min))
(forward-line 5)
(setq mrkb (point-marker))
(setq beg (point))
(forward-line 3)
(setq mrki (point-marker))
(forward-line 3)
(setq end (point))
(setq mrke (point-marker))
(message "Before: beg=%d, end=%d, Markers: beg=%S, in=%S, end=%S" beg end
mrkb mrki mrke)
(sort-lines reverse beg end)
(message "After: beg=%d, end=%d, Markers: beg=%S, in=%S, end=%S" beg end
mrkb mrki mrke)
))
The results are:
"21.1.3" (Branch, just released)
Before: beg=81, end=177,
Markers: beg=#<marker at 81 in test-sort-buf>,
in=#<marker at 129 in test-sort-buf>,
end=#<marker at 177 in test-sort-buf>
After: beg=81, end=177,
Markers: beg=#<marker at 81 in test-sort-buf>,
in=#<marker at 81 in test-sort-buf>,
end=#<marker at 177 in test-sort-buf>
"21.3.50.3" (HEAD)
Before: beg=81, end=177,
Markers: beg=#<marker at 81 in test-sort-buf>,
in=#<marker at 129 in test-sort-buf>,
end=#<marker at 177 in test-sort-buf>
After: beg=81, end=177,
Markers: beg=#<marker at 81 in test-sort-buf>,
in=#<marker at 81 in test-sort-buf>,
end=#<marker at 81 in test-sort-buf>
As you can see the "end" marker is destroyed in HEAD but not in
the current Emacs.
I found that this was caused by a change to `sort-reorder-buffer'
in sort.el that now uses a temp buffer. I hacked it a little:
diff -c /usr/local/share/emacs/21.3.50/lisp/sort-org.el
/usr/local/share/emacs/21.3.50/lisp/sort.el
*** /usr/local/share/emacs/21.3.50/lisp/sort-org.el Mon Feb 10 23:36:03 2003
- --- /usr/local/share/emacs/21.3.50/lisp/sort.el Thu Mar 27 17:40:27 2003
***************
*** 164,170 ****
(defun sort-reorder-buffer (sort-lists old)
(let ((last (point-min))
! (min (point-min)) (max (point-max))
(old-buffer (current-buffer))
temp-buffer)
(with-temp-buffer
- --- 164,170 ----
(defun sort-reorder-buffer (sort-lists old)
(let ((last (point-min))
! (rest (point-max))
(old-buffer (current-buffer))
temp-buffer)
(with-temp-buffer
***************
*** 185,207 ****
sort-lists (cdr sort-lists)
old (cdr old)))
(goto-char (point-max))
! (insert-buffer-substring old-buffer last max)
;; Copy the reordered text from the temporary buffer
;; to the buffer we sorted (OLD-BUFFER).
(set-buffer old-buffer)
(let ((inhibit-quit t))
;; Make sure insertions done for reordering
! ;; do not go after any markers at the end of the sorted region,
! ;; by inserting a space to separate them.
! (goto-char max)
! (insert-before-markers " ")
! ;; Delete the original copy of the text.
! (delete-region min max)
! ;; Now replace the separator " " with the sorted text.
! (goto-char (point-max))
(insert-buffer-substring temp-buffer)
! (delete-region min (1+ min))))))
;;;###autoload
(defun sort-lines (reverse beg end)
- --- 185,201 ----
sort-lists (cdr sort-lists)
old (cdr old)))
(goto-char (point-max))
! (insert-buffer-substring old-buffer last rest)
;; Copy the reordered text from the temporary buffer
;; to the buffer we sorted (OLD-BUFFER).
(set-buffer old-buffer)
(let ((inhibit-quit t))
;; Make sure insertions done for reordering
! (goto-char (point-min))
(insert-buffer-substring temp-buffer)
! ;; Delete the original copy of the text.
! (delete-region (point) (point-max))))))
;;;###autoload
(defun sort-lines (reverse beg end)
Diff finished at Thu Mar 27 17:41:24
With my patch the results are:
Patched "21.3.50.3"
Before: beg=81, end=177,
Markers: beg=#<marker at 81 in test-sort-buf>,
in=#<marker at 129 in test-sort-buf>,
end=#<marker at 177 in test-sort-buf>
After: beg=81, end=177,
Markers: beg=#<marker at 81 in test-sort-buf>,
in=#<marker at 176 in test-sort-buf>,
end=#<marker at 177 in test-sort-buf>
Which keeps the "beg" and "end" markers, and sets all the intermediate
markers to the end position (contrast with current version that sets
all these markers to beginning position).
Ehud.
- --
Ehud Karni Tel: +972-3-7966-561 /"\
Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign
Insurance agencies (USA) voice mail and X Against HTML Mail
http://www.mvs.co.il FAX: 1-815-5509341 / \
mailto:address@hidden Better Safe Than Sorry
-----BEGIN PGP SIGNATURE-----
Comment: use http://www.keyserver.net/ to get my key (and others)
iD8DBQE+gxzlLFvTvpjqOY0RAiywAKCHt9/IAZZiXSCC9M0Tv6bD3n3nbACdHfar
dvoV+qr9sJDPPMnK7hUe6GQ=
=iDw7
-----END PGP SIGNATURE-----
- sort-lines in HEAD is not compatible with current Emacs - with patch,
Ehud Karni <=