From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rainer Stengele <rainer.stengele@online.de> Newsgroups: gmane.emacs.help Subject: Re: how to sort words in a line Date: Tue, 17 Jul 2007 20:20:52 +0200 Organization: A noiseless patient Spider Message-ID: <f7j1a2$jll$1@registered.motzarella.org> References: <us0ni.4$Cn4.3848351@news.odn.de> <87r6n7l41m.fsf@thalassa.lan.informatimago.com> <f7ivtq$eo4$3@registered.motzarella.org> <87lkdekio7.fsf@thalassa.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1184697767 9194 80.91.229.12 (17 Jul 2007 18:42:47 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 17 Jul 2007 18:42:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 17 20:42:45 2007 Return-path: <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org> Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IAs0S-00088x-BM for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Jul 2007 20:42:44 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IAs0R-0003zc-VR for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Jul 2007 14:42:44 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!oleane.net!oleane!news.ecp.fr!news.motzarella.org!motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 60 Original-X-Trace: tomate.motzarella.org U2FsdGVkX1/zGfgY/vklfYDywlBa2J7WPiakpKum1P6lf5A8PcNC4osDPPh2fMeZA4TGWDN6qnK5oVPWnYDA42+2jPYndiBKnwhHVggFstqtGqQNpYrbnJwahu3AdytsblrTGgwSpWsatB52ruDYDg== Original-X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers Original-NNTP-Posting-Date: Tue, 17 Jul 2007 18:20:50 +0000 (UTC) In-Reply-To: <87lkdekio7.fsf@thalassa.lan.informatimago.com> X-Auth-Sender: U2FsdGVkX1+SraKHj0DsJA9FX9V78hKtZSoB7VykZwTyvEijW98FDUzhZWf5Yfvz User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) Original-Xref: shelby.stanford.edu gnu.emacs.help:150178 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor <help-gnu-emacs.gnu.org> List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/help-gnu-emacs>, <mailto:help-gnu-emacs-request@gnu.org?subject=unsubscribe> List-Archive: <http://lists.gnu.org/pipermail/help-gnu-emacs> List-Post: <mailto:help-gnu-emacs@gnu.org> List-Help: <mailto:help-gnu-emacs-request@gnu.org?subject=help> List-Subscribe: <http://lists.gnu.org/mailman/listinfo/help-gnu-emacs>, <mailto:help-gnu-emacs-request@gnu.org?subject=subscribe> Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:45764 Archived-At: <http://permalink.gmane.org/gmane.emacs.help/45764> Pascal Bourguignon schrieb: > 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 > yes - ok. btw - your code adds whitespaces. This works: (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 " ")) (delete-trailing-whitespace)) (beginning-of-line) (forward-line 1)))