From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jacob Gerlach Newsgroups: gmane.emacs.help Subject: Re: Operate on each line in region Date: Wed, 23 Apr 2014 16:23:20 -0700 (PDT) Message-ID: <02d45a30-ac9e-46a1-8f7b-1e3ce651de00@googlegroups.com> References: <787a28ce-2ab1-4b11-92fd-ca4506447baa@googlegroups.com> <8a35bad7-fd4a-4755-95c2-528b96e032b1@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1398295532 28428 80.91.229.3 (23 Apr 2014 23:25:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Apr 2014 23:25:32 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 24 01:25:23 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 1Wd6Xa-0002w3-5v for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Apr 2014 01:25:22 +0200 Original-Received: from localhost ([::1]:35120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wd6XZ-0005oL-KJ for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Apr 2014 19:25:21 -0400 X-Received: by 10.182.70.106 with SMTP id l10mr28118035obu.7.1398295400671; Wed, 23 Apr 2014 16:23:20 -0700 (PDT) X-Received: by 10.140.107.35 with SMTP id g32mr482769qgf.2.1398295400637; Wed, 23 Apr 2014 16:23:20 -0700 (PDT) Original-Path: usenet.stanford.edu!c1no2850855igq.0!news-out.google.com!du2ni14990qab.0!nntp.google.com!cm18no5822198qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: <8a35bad7-fd4a-4755-95c2-528b96e032b1@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=98.217.114.175; posting-account=Hx-_8AoAAACyMXgs4MCS3wNERNLct_lk Original-NNTP-Posting-Host: 98.217.114.175 User-Agent: G2/1.0 Injection-Date: Wed, 23 Apr 2014 23:23:20 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:205079 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:97345 Archived-At: I'm having more trouble figuring this out that I expected. I tried building a function around align-regexp: (defun my-justify-equals (start end) "Indents current region to justify equals signs" (interactive 'r') (align-regexp start end "\\([ \t]*\\)\\(.*\\)=" 1 nil nil)) But when I attempt to evaluate the defun I get Invalid read syntax: ")" In any case, I still can't get the right result using align-regexp interactively. I tried "\([ \t]*\)\(.*\)=" as my regexp, with 1 for 'group' and 'spacing.' This inserts a tab character at the beginning of the line... After reviewing the documentation more closely, perhaps align regexp doesn't do what I need. The description for group states: The "alignment character" is always the first character immediately following this parenthesis group. However, I want a different behavior, where the alignment character is later in the string, so it seems that what I want to do isn't actually possible with align-regexp. So I tried something more in line with my original idea, except working from the end to the beginning as Stefan suggested: (defun my-justify-equals (start end) "Indents current region to justify equals signs" (interactive 'r') (save-excursion (goto-char end) (let (left-length) (save-excursion (while (> (point) start) (if (re-search-forward "^[ \t]*\\(.*\\)=" (line-end-position) t) (when (> (length (match-string-no-properties 1)) left-length) (setq left-length (length (match-string-no-properties 1))))) (forward-line -1))) (goto-char end) (while (> (point) start) (if (re-search-forward "^[ \t]*\\(.*\\)=" (line-end-position) t) (indent-line-to (+ tab-width (length (match-string-no-properties 1)))) (indent-line-to tab-width)) (forward-line -1))))) However, I can't test this. Attempting to evaluate the defun gives "Invalid read syntax ")". I followed the instructions at http://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Errors.html, but was unable to identify an error. What am I missing? Thanks, Jake