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

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

Re: how to sort words in a line


From: Pascal Bourguignon
Subject: Re: how to sort words in a line
Date: Tue, 17 Jul 2007 20:07:52 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.1.50 (gnu/linux)

Rainer Stengele <rainer.stengele@online.de> writes:

> Pascal Bourguignon schrieb:
>> Rainer Stengele <rainer.stengele@diplan.de> writes:
>>> I just couldn't find a fast solution to sort a line of words:
>>>
>>> zzz aaa hhhh
>>>
>>> -->
>>>
>>> aaa hhhh zzz
>>>
>>>
>>> Did I miss a simple command?
>> 
>> AFAIK, no.
>> 
>> But it's rather simple a command to write:
>> 
>> (defun sort-words-in-lines (start end)
>>    (interactive "r")
>>    (goto-char start)
>>    (beginning-of-line)
>>    (while (< (setq start (point)) end)
>>       (let ((words (sort (split-string (buffer-substring start 
>> (line-end-position)))
>>                          (function string-lessp))))
>>         (delete-region start (line-end-position))
>>         (dolist (word words ) (insert word " ")))
>>       (beginning-of-line) (forward-line 1)))
>> 
>> 
> thanx!
>
> Wow! Thats quite a piece of code for a not-yet Lisp programmer.
> Coming from perl this would be a simple one-liner doing the work.
> Don't misunderstand me - I understand the power and flexibility of elisp
> in emacs. I just wonder if there is not a built in solution.
>
> Somebody?

Of course there is a one-liner!

You select your lines, and type M-x sort-words-in-lines RET

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.


reply via email to

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