bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23863: 25.0.94; `delete-duplicate-lines' ignores first line in when


From: Stephen Berman
Subject: bug#23863: 25.0.94; `delete-duplicate-lines' ignores first line in when REVERSE is non-nil
Date: Wed, 29 Jun 2016 11:04:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

On Tue, 28 Jun 2016 21:43:48 +0200 Adrián Medraño Calvo 
<adrian@medranocalvo.com> wrote:

> When running `delete-duplicate-lines' in reverse mode (i.e., REVERSE is
> non-nil) the topmost line is not deleted.  Please, see recipe:
>
> 1. Place the following lines in a buffer:
>
> This is line A.
> This is line B.
> This is line A.
> This is line C.
> This is line A.
>
> 2. Select all the lines
> 3. Invoke "C-u M-x delete-duplicate-lines".
> 4. Result is:
>
> This is line A.
> This is line B.
> This is line C.
> This is line A.
>
> The top line "This is line A." should have been deleted.

The patch below fixes this.  This bug has existed since the command
was introduced in Emacs 24, i.e., it's not a regression in Emacs 25, so
if the patch is acceptable, should it be pushed to master?

Steve Berman

diff --git a/lisp/sort.el b/lisp/sort.el
index 4d7311f..8bc7138 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -596,7 +596,7 @@ delete-duplicate-lines
           (equal current-prefix-arg '(64))
           t)))
   (let ((lines (unless adjacent (make-hash-table :test 'equal)))
-       line prev-line
+       line prev-line first-line
        (count 0)
        (beg (copy-marker beg))
        (end (copy-marker end)))
@@ -604,8 +604,9 @@ delete-duplicate-lines
       (goto-char (if reverse end beg))
       (if (and reverse (bolp)) (forward-char -1))
       (while (if reverse
-                (and (> (point) beg) (not (bobp)))
+                (not first-line)
               (and (< (point) end) (not (eobp))))
+       (setq first-line (and reverse (or (<= (point) beg) (bobp))))
        (setq line (buffer-substring-no-properties
                    (line-beginning-position) (line-end-position)))
         (if (and keep-blanks (string= "" line))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]