all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Removing duplicated lines
@ 2012-11-29 10:50 Dani Moncayo
  2012-11-29 12:12 ` Jambunathan K
  0 siblings, 1 reply; 10+ messages in thread
From: Dani Moncayo @ 2012-11-29 10:50 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

Does (vanilla) Emacs have some command for removing duplicated lines
in a given region?

This is a command I'm missing for some time.

I've done a quick search, but didn't found anything.

If there isn't such command, I think I'd file a feature request.

TIA.

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
       [not found] <mailman.14043.1354186273.855.help-gnu-emacs@gnu.org>
@ 2012-11-29 11:06 ` Sebastien Vauban
  2012-11-29 11:25   ` Dani Moncayo
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Sebastien Vauban @ 2012-11-29 11:06 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hi Dani,

Dani Moncayo wrote:
> Does (vanilla) Emacs have some command for removing duplicated lines
> in a given region?
>
> This is a command I'm missing for some time.
>
> I've done a quick search, but didn't found anything.
>
> If there isn't such command, I think I'd file a feature request.

Shell command on a region: `M-| uniq RET'

Best regards,
  Seb

-- 
Sebastien Vauban


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
  2012-11-29 11:06 ` Removing duplicated lines Sebastien Vauban
@ 2012-11-29 11:25   ` Dani Moncayo
  2012-11-29 11:57     ` Yuri Khan
       [not found]     ` <mailman.14047.1354190273.855.help-gnu-emacs@gnu.org>
  2012-11-29 11:31   ` Yuri Khan
  2013-07-03 12:14   ` naisanza
  2 siblings, 2 replies; 10+ messages in thread
From: Dani Moncayo @ 2012-11-29 11:25 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: help-gnu-emacs

> Shell command on a region: `M-| uniq RET'

Thanks, but this is not exactly what I'd like, because:
* It depends on a shell command, which might not be available
(specially under MS-Windows).
* It shows the compacted region in the echo area (and therefore also
in the *Messages* buffer), but I'd like the command to modify the
region in-place (and show some message in the echo area like "nn
duplicated lines removed").

Thanks for replying.

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
  2012-11-29 11:06 ` Removing duplicated lines Sebastien Vauban
  2012-11-29 11:25   ` Dani Moncayo
@ 2012-11-29 11:31   ` Yuri Khan
  2013-07-03 12:14   ` naisanza
  2 siblings, 0 replies; 10+ messages in thread
From: Yuri Khan @ 2012-11-29 11:31 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Nov 29, 2012 at 6:06 PM, Sebastien Vauban
<wxhgmqzgwmuf@spammotel.com> wrote:
>> Does (vanilla) Emacs have some command for removing duplicated lines
>> in a given region?
> Shell command on a region: `M-| uniq RET'

+1 but I’d add that it will only detect consecutive duplicate lines.
sort|uniq or sort -u will remove all duplicates but will sort the
lines as a side effect, which may or may not be desired.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
  2012-11-29 11:25   ` Dani Moncayo
@ 2012-11-29 11:57     ` Yuri Khan
  2012-11-29 12:07       ` Dani Moncayo
       [not found]     ` <mailman.14047.1354190273.855.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2012-11-29 11:57 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: help-gnu-emacs

On Thu, Nov 29, 2012 at 6:25 PM, Dani Moncayo <dmoncayo@gmail.com> wrote:
>> Shell command on a region: `M-| uniq RET'
>
> Thanks, but this is not exactly what I'd like, because:
> * It depends on a shell command, which might not be available
> (specially under MS-Windows).

True. But if you have Emacs on Windows, you can (should?) also have
UnxUtils or GnuWin32 or Cygwin or msys.

> * It shows the compacted region in the echo area (and therefore also
> in the *Messages* buffer), but I'd like the command to modify the
> region in-place (and show some message in the echo area like "nn
> duplicated lines removed").

To modify in-place, prefix with C-u.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
  2012-11-29 11:57     ` Yuri Khan
@ 2012-11-29 12:07       ` Dani Moncayo
  0 siblings, 0 replies; 10+ messages in thread
From: Dani Moncayo @ 2012-11-29 12:07 UTC (permalink / raw)
  To: Yuri Khan; +Cc: help-gnu-emacs

>> Thanks, but this is not exactly what I'd like, because:
>> * It depends on a shell command, which might not be available
>> (specially under MS-Windows).
>
> True. But if you have Emacs on Windows, you can (should?) also have
> UnxUtils or GnuWin32 or Cygwin or msys.

Maybe.  IMO, the operation is simple and common enough to deserve and
implementation inside Emacs, so that no external utility is required.
And Emacs already have similar commands like `sort-lines' which could
have been delegated also to external tools.

>> * It shows the compacted region in the echo area (and therefore also
>> in the *Messages* buffer), but I'd like the command to modify the
>> region in-place (and show some message in the echo area like "nn
>> duplicated lines removed").
>
> To modify in-place, prefix with C-u.

Indeed, thanks!

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
  2012-11-29 10:50 Dani Moncayo
@ 2012-11-29 12:12 ` Jambunathan K
  2012-11-29 12:18   ` Dani Moncayo
  0 siblings, 1 reply; 10+ messages in thread
From: Jambunathan K @ 2012-11-29 12:12 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: help-gnu-emacs

Dani Moncayo <dmoncayo@gmail.com> writes:

> Hi,
>
> Does (vanilla) Emacs have some command for removing duplicated lines
> in a given region?
>
> This is a command I'm missing for some time.
>
> I've done a quick search, but didn't found anything.
>
> If there isn't such command, I think I'd file a feature request.

Something like this ...

    (defun delete-duplicate-lines (beg end)
      (interactive "r")
      (let ((lines (split-string (buffer-substring beg end) "\n")))
        (delete-region beg end)
        (insert
         (mapconcat #'identity (delete-dups lines) "\n"))))

> TIA.

-- 



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
  2012-11-29 12:12 ` Jambunathan K
@ 2012-11-29 12:18   ` Dani Moncayo
  0 siblings, 0 replies; 10+ messages in thread
From: Dani Moncayo @ 2012-11-29 12:18 UTC (permalink / raw)
  To: Jambunathan K; +Cc: help-gnu-emacs

> Something like this ...
>
>     (defun delete-duplicate-lines (beg end)
>       (interactive "r")
>       (let ((lines (split-string (buffer-substring beg end) "\n")))
>         (delete-region beg end)
>         (insert
>          (mapconcat #'identity (delete-dups lines) "\n"))))

Seem to do the job, indeed.  Thanks!

It could be improved by accepting a prefix argument to control an
optional reordering of the region (as side effect):
* If the argument is > 0 --> Region sorted in ascending order.
* If the argument is < 0 --> Region sorted in descending order.
* If the argument is 0 or nil --> Region is left unsorted.

-- 
Dani Moncayo



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
       [not found]     ` <mailman.14047.1354190273.855.help-gnu-emacs@gnu.org>
@ 2013-07-03 12:13       ` naisanza
  0 siblings, 0 replies; 10+ messages in thread
From: naisanza @ 2013-07-03 12:13 UTC (permalink / raw)
  To: help-gnu-emacs

On Thursday, November 29, 2012 6:57:45 AM UTC-5, Yuri Khan wrote:
> On Thu, Nov 29, 2012 at 6:25 PM, Dani Moncayo <> wrote:
> 
> >> Shell command on a region: `M-| uniq RET'
> 
> >
> 
> > Thanks, but this is not exactly what I'd like, because:
> 
> > * It depends on a shell command, which might not be available
> 
> > (specially under MS-Windows).
> 
> 
> 
> True. But if you have Emacs on Windows, you can (should?) also have
> 
> UnxUtils or GnuWin32 or Cygwin or msys.
> 
> 
> 
> > * It shows the compacted region in the echo area (and therefore also
> 
> > in the *Messages* buffer), but I'd like the command to modify the
> 
> > region in-place (and show some message in the echo area like "nn
> 
> > duplicated lines removed").
> 
> 
> 
> To modify in-place, prefix with C-u.

awesome.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Removing duplicated lines
  2012-11-29 11:06 ` Removing duplicated lines Sebastien Vauban
  2012-11-29 11:25   ` Dani Moncayo
  2012-11-29 11:31   ` Yuri Khan
@ 2013-07-03 12:14   ` naisanza
  2 siblings, 0 replies; 10+ messages in thread
From: naisanza @ 2013-07-03 12:14 UTC (permalink / raw)
  To: help-gnu-emacs

On Thursday, November 29, 2012 6:06:54 AM UTC-5, Sebastien Vauban wrote:
> Hi Dani,
> 
> 
> 
> Dani Moncayo wrote:
> 
> > Does (vanilla) Emacs have some command for removing duplicated lines
> 
> > in a given region?
> 
> >
> 
> > This is a command I'm missing for some time.
> 
> >
> 
> > I've done a quick search, but didn't found anything.
> 
> >
> 
> > If there isn't such command, I think I'd file a feature request.
> 
> 
> 
> Shell command on a region: `M-| uniq RET'
> 
> 
> 
> Best regards,
> 
>   Seb
> 
> 
> 
> -- 
> 
> Sebastien Vauban

This was just what I was looking for


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-07-03 12:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.14043.1354186273.855.help-gnu-emacs@gnu.org>
2012-11-29 11:06 ` Removing duplicated lines Sebastien Vauban
2012-11-29 11:25   ` Dani Moncayo
2012-11-29 11:57     ` Yuri Khan
2012-11-29 12:07       ` Dani Moncayo
     [not found]     ` <mailman.14047.1354190273.855.help-gnu-emacs@gnu.org>
2013-07-03 12:13       ` naisanza
2012-11-29 11:31   ` Yuri Khan
2013-07-03 12:14   ` naisanza
2012-11-29 10:50 Dani Moncayo
2012-11-29 12:12 ` Jambunathan K
2012-11-29 12:18   ` Dani Moncayo

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.