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: Thien-Thi Nguyen
Subject: Re: how to sort words in a line
Date: Tue, 17 Jul 2007 21:20:03 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

() Rainer Stengele <rainer.stengele@online.de>
() Tue, 17 Jul 2007 19:57:17 +0200

   simple one-liner doing the work.

perhaps one expression, nicely (readably) laid out, would please you:

(defun sort-words-on-line ()
  (interactive)
  (insert (mapconcat 'identity
                     (sort (split-string 
                            (delete-and-extract-region
                             (point) (1+ (line-end-position)))) 
                           'string<)
                     " ")
          "\n"))

for this command to work, you have to be at bol and the line must end
w/ newline.  in exchange for these restrictions, it has the feature of
moving you to the next line automatically (handy for kbd macro use).

thi


reply via email to

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