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 12:26:13 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.1.50 (gnu/linux)

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)))


-- 
__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]