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: Fri, 25 Apr 2014 20:02:04 -0700 (PDT) Message-ID: <2b2bb390-600b-4f02-9dce-95cd28d3f9f4@googlegroups.com> References: <787a28ce-2ab1-4b11-92fd-ca4506447baa@googlegroups.com> <8a35bad7-fd4a-4755-95c2-528b96e032b1@googlegroups.com> <02d45a30-ac9e-46a1-8f7b-1e3ce651de00@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 1398481526 26912 80.91.229.3 (26 Apr 2014 03:05:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 26 Apr 2014 03:05:26 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Apr 26 05:05:19 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 1WdsvX-0005RO-Ed for geh-help-gnu-emacs@m.gmane.org; Sat, 26 Apr 2014 05:05:19 +0200 Original-Received: from localhost ([::1]:60719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdsvW-0007Pv-Ac for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Apr 2014 23:05:18 -0400 X-Received: by 10.236.4.201 with SMTP id 49mr4700473yhj.47.1398481324442; Fri, 25 Apr 2014 20:02:04 -0700 (PDT) X-Received: by 10.140.94.75 with SMTP id f69mr1168qge.30.1398481324408; Fri, 25 Apr 2014 20:02:04 -0700 (PDT) Original-Path: usenet.stanford.edu!cm18no6390796qab.0!news-out.google.com!du2ni15315qab.0!nntp.google.com!cm18no6390793qab.0!postnews.google.com!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=98.217.114.175; posting-account=Hx-_8AoAAACyMXgs4MCS3wNERNLct_lk Original-NNTP-Posting-Host: 98.217.114.175 User-Agent: G2/1.0 Injection-Date: Sat, 26 Apr 2014 03:02:04 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:205110 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:97376 Archived-At: Took some more tweaking, but I finally got this working. Comments or recommendations welcome. I was never able to figure out if align-regexp could do what I needed. Figured I'd post the final function: (defun my-justify-equals (start end) "Indents current region to justify equals signs. Indents lines with no equals sign to default tab width" (interactive "r") (save-excursion (goto-char end) (goto-char (line-beginning-position)) (let ((left-length 0)) (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) (goto-char (line-beginning-position)) (while (>= (point) start) (if (re-search-forward "^[ \t]*\\(.*\\)=" (line-end-position) t) (indent-line-to (+ tab-width (- left-length (length (match-string-no-properties 1))))) (indent-line-to tab-width)) (forward-line -1)))))