From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: anshul.verma86@gmail.com Newsgroups: gmane.emacs.help Subject: Re: align-regexp for many column separators Date: Sun, 18 Jan 2015 08:49:27 -0800 (PST) Message-ID: <315b4947-d4c2-4b7f-b56d-e94007fb9d34@googlegroups.com> References: <78620bdf-a2c8-4e54-84eb-74acc9c8f8c3@i21g2000yqd.googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1421616956 24804 80.91.229.3 (18 Jan 2015 21:35:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 18 Jan 2015 21:35:56 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 18 22:35:56 2015 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 1YCxVj-0001ja-Rg for geh-help-gnu-emacs@m.gmane.org; Sun, 18 Jan 2015 22:35:55 +0100 Original-Received: from localhost ([::1]:34789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YCxVi-0004Hv-Uz for geh-help-gnu-emacs@m.gmane.org; Sun, 18 Jan 2015 16:35:54 -0500 X-Received: by 10.182.65.227 with SMTP id a3mr19412292obt.2.1421599768833; Sun, 18 Jan 2015 08:49:28 -0800 (PST) X-Received: by 10.51.16.165 with SMTP id fx5mr186415igd.16.1421599768653; Sun, 18 Jan 2015 08:49:28 -0800 (PST) Original-Path: usenet.stanford.edu!r10no845927igi.0!news-out.google.com!qk8ni9169igc.0!nntp.google.com!r10no845916igi.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: <78620bdf-a2c8-4e54-84eb-74acc9c8f8c3@i21g2000yqd.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:9:8302:3890:cccd:85c6:8ffd:96d; posting-account=WjE5zAoAAAD7LLL0plXMevTda_PHX2iW Original-NNTP-Posting-Host: 2601:9:8302:3890:cccd:85c6:8ffd:96d User-Agent: G2/1.0 Injection-Date: Sun, 18 Jan 2015 16:49:28 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:209866 X-Mailman-Approved-At: Sun, 18 Jan 2015 16:35:44 -0500 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:102145 Archived-At: Thanks @jpkotta...works like a charm! On Friday, September 2, 2011 at 7:59:42 AM UTC-7, jpkotta wrote: > On Aug 24, 9:43=A0am, Michael Chen wrote: > > Dear there, > > I would like to align at "&": > > > > 1&2&3\\ > > 1000&2000&3000\\ > > > > =3D=3D> > > > > 1 =A0 =A0 =A0&2 =A0 =A0 =A0&3\\ > > 1000&2000&3000\\ > > > > M-x align-regexp only aligns the first "&", i.e., I get > > 1 =A0 =A0 =A0&2&3\\ > > 1000&2000&3000\\ > > > > Any suggestions? > > > > -- > > All the best, > > Michael Chen >=20 > You can do it directly with align-regexp, but I can't ever remember > exactly how when I need it. So I use this: >=20 > (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)))