From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Sorting lines by length Date: Tue, 16 Sep 2014 19:53:43 -0700 (PDT) Message-ID: <790f6664-2267-4bda-b2ed-5620859fd093@default> References: <87k353zptq.fsf@hornfels.zedat.fu-berlin.de> <87fvfryovx.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1410922468 9624 80.91.229.3 (17 Sep 2014 02:54:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Sep 2014 02:54:28 +0000 (UTC) To: "Pascal J. Bourguignon" , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 17 04:54:21 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XU5Ns-0007YA-1o for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Sep 2014 04:54:20 +0200 Original-Received: from localhost ([::1]:41783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XU5Nr-0001FU-Lg for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Sep 2014 22:54:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XU5NY-0001Ep-Eo for help-gnu-emacs@gnu.org; Tue, 16 Sep 2014 22:54:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XU5NQ-0004zE-RS for help-gnu-emacs@gnu.org; Tue, 16 Sep 2014 22:54:00 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:18667) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XU5NQ-0004y4-LA for help-gnu-emacs@gnu.org; Tue, 16 Sep 2014 22:53:52 -0400 Original-Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s8H2rlV4029246 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 17 Sep 2014 02:53:48 GMT Original-Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s8H2rigA011555 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 17 Sep 2014 02:53:44 GMT Original-Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8H2rhmZ019708; Wed, 17 Sep 2014 02:53:43 GMT In-Reply-To: <87fvfryovx.fsf@kuiper.lan.informatimago.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8.2 (807160) [OL 12.0.6691.5000 (x86)] X-Source-IP: ucsinet22.oracle.com [156.151.31.94] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:99973 Archived-At: > You want the longest line. This is quite different than wanting to > sort lines. Finding the longest line is a O(n) operation. > Sorting lines is a O(n*log(n)) operation. >=20 > (defun goto-longest-line () > (interactive) > (let ((max-line-start 0) > (max-line-length 0)) > (goto-char (point-min)) > (while (< (point) (point-max)) > (let ((start (point))) > (forward-line) > (let ((length (- (point) start))) > (if (< max-line-length length) > (setf max-line-length length > max-line-start start))))) > (goto-char max-line-start) > (set-mark (+ max-line-start max-line-length)))) FWIW - The version of `goto-longest-line' (coincidentally the same name) in `misc-cmds.el' is similar but does a bit more. Here is the doc string: ,---- | goto-longest-line is an interactive Lisp function in `misc-cmds.el'. | (goto-longest-line BEG END) |=20 | Go to the first of the longest lines in the region or buffer. | If the region is active, it is checked. | If not, the buffer (or its restriction) is checked. |=20 | Returns a list of three elements: |=20 | (LINE LINE-LENGTH OTHER-LINES LINES-CHECKED) |=20 | LINE is the first of the longest lines measured. | LINE-LENGTH is the length of LINE. | OTHER-LINES is a list of other lines checked that are as long as LINE. | LINES-CHECKED is the number of lines measured. |=20 | Interactively, a message displays this information. |=20 | If there is only one line in the active region, then the region is | deactivated after this command, and the message mentions only LINE and | LINE-LENGTH. |=20 | If this command is repeated, it checks for the longest line after the | cursor. That is *not* necessarily the longest line other than the | current line. That longest line could be before or after the current | line. |=20 | To search only from the current line forward, not throughout the | buffer, you can use `C-SPC' to set the mark, then use this | (repeatedly). `---- And if you use `isearch+.el' then `C-end' is (by default) bound to this command during Isearch. `C-g' puts you back where you left off searching, `C-s' resumes searching from wherever you stop hitting `C-end', etc. I use this quite often during Isearch. http://www.emacswiki.org/emacs-en/download/misc-cmds.el http://www.emacswiki.org/emacs-en/download/isearch%2b.el http://www.emacswiki.org/IsearchPlus