From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: jpkotta Newsgroups: gmane.emacs.help Subject: Re: align-regexp not working as intended Date: Mon, 18 Mar 2013 11:39:48 -0700 (PDT) Message-ID: <0e465eb6-830c-4abe-b387-c471328ddb90@googlegroups.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1363647386 8082 80.91.229.3 (18 Mar 2013 22:56:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 Mar 2013 22:56:26 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: gnu.emacs.help@googlegroups.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 18 23:56:52 2013 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 1UHiz5-00044k-S5 for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Mar 2013 23:56:51 +0100 Original-Received: from localhost ([::1]:41079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHiyi-0000nt-Ul for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Mar 2013 18:56:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHeyO-0004Y6-RY for help-gnu-emacs@gnu.org; Mon, 18 Mar 2013 14:39:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UHeyL-0003Td-Lh for help-gnu-emacs@gnu.org; Mon, 18 Mar 2013 14:39:52 -0400 Original-Received: from mail-ia0-x239.google.com ([2607:f8b0:4001:c02::239]:55042) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHeyL-0003TJ-H9 for help-gnu-emacs@gnu.org; Mon, 18 Mar 2013 14:39:49 -0400 Original-Received: by mail-ia0-f185.google.com with SMTP id m10so2474096iam.12 for ; Mon, 18 Mar 2013 11:39:48 -0700 (PDT) X-Received: by 10.49.35.208 with SMTP id k16mr1352543qej.1.1363631988561; Mon, 18 Mar 2013 11:39:48 -0700 (PDT) Original-Path: glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.97.12.233; posting-account=EwI0QQoAAADdqmqX_mVfawBNtwyks2YE Original-NNTP-Posting-Host: 70.97.12.233 User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 70.97.12.233 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c02::239 X-Mailman-Approved-At: Mon, 18 Mar 2013 18:56:17 -0400 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:89589 Archived-At: On Monday, March 18, 2013 5:15:25 AM UTC-5, Florian Lindner wrote: > Hello, > > > > on my Emacs 24.2.1 7 / Arch align-regexp is not working like I expect it to: > > > > I have a latex table: > > > > & $C_D$ & $C_L$ & $C_M$ & $C_D$ & $C_L$ & $C_M$ & $C_D$ & $C_L$ & > > $C_M$ \\ \hline > > 5-Spoke & $0.640$ & $0.396$ & $\approx 0$ & $0.599$ & $0.394$ & > > $0.017$ & $0.599$ & $0.356$ & $0.019$ \\ > > 7-Spoke & $0.646$ & $0.407$ & $0.0017$ & $0.592$ & $0.377$ & > > $0.0167$ & $0.606$ & $0.349$ & $0.0280$ \\ > > DA Wheel & $0.649$ & $0.421$ & $-0.0004$ & $0.607$ & $0.392$ & > > $0.0145$ & $0.614$ & $0.384$ & $0.024$ \\ > > GenWheel Open & $0.640$ & $0.330$ & $0.0012$ & $0.613$ & $0.253$ & > > $0.018$ & $0.660$ & $0.201$ & $0.031$ \\ > > GenWheel Closed & $0.617$ & $0.302$ & $0.0015$ & $0.579$ & $0.280$ > > & $0.0206$ & $0.580$ & $0.281$ & $0.0206$ \\ > > > > This should be aligned at the &: M-x align-regexp & with the part > > above as active region gives me: > > > > & $C_D$ & $C_L$ & $C_M$ & $C_D$ & $C_L$ & $C_M$ & > > $C_D$ & $C_L$ & $C_M$ \\ \hline > > 5-Spoke & $0.640$ & $0.396$ & $\approx 0$ & $0.599$ & > > $0.394$ & $0.017$ & $0.599$ & $0.356$ & $0.019$ \\ > > 7-Spoke & $0.646$ & $0.407$ & $0.0017$ & $0.592$ & $0.377$ > > & $0.0167$ & $0.606$ & $0.349$ & $0.0280$ \\ > > DA Wheel & $0.649$ & $0.421$ & $-0.0004$ & $0.607$ & > > $0.392$ & $0.0145$ & $0.614$ & $0.384$ & $0.024$ \\ > > GenWheel Open & $0.640$ & $0.330$ & $0.0012$ & $0.613$ & $0.253$ > > & $0.018$ & $0.660$ & $0.201$ & $0.031$ \\ > > GenWheel Closed & $0.617$ & $0.302$ & $0.0015$ & $0.579$ & $0.280$ > > & $0.0206$ & $0.580$ & $0.281$ & $0.0206$ \\ > > > > (you should swith your font to fixed-width now) > > > > The align is fine at the first columns but somehow got off later... > > > > What is the problem here? > > > > If there is some problem with mail reader introduced line breaks or > > font width, the entire posting is available here: > > http://pastebin.com/raw.php?i=3JZiKiaS > > > > Thanks! > > > > Florian align-regexp has an optional repeat argument which must be set to t to do what you want. Here is a command that I use for these sorts of tasks: (defun align-regexp-repeated (start stop regexp) "Like align-regexp, but repeated for multiple columns. See http://www.emacswiki.org/emacs/AlignCommands" (interactive "r\nsAlign regexp: ") (let ((spacing 1) (old-buffer-size (buffer-size))) ;; If our align regexp is just spaces, then we don't need any ;; extra spacing. (when (string-match regexp " ") (setq spacing 0)) (align-regexp start stop ;; add space at beginning of regexp (concat "\\([[:space:]]*\\)" regexp) 1 spacing t) ;; modify stop because align-regexp will add/remove characters (align-regexp start (+ stop (- (buffer-size) old-buffer-size)) ;; add space at end of regexp (concat regexp "\\([[:space:]]*\\)") 1 spacing t)))