From: Jacob Gerlach <jacobgerlach@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Operate on each line in region
Date: Fri, 25 Apr 2014 20:02:04 -0700 (PDT) [thread overview]
Message-ID: <2b2bb390-600b-4f02-9dce-95cd28d3f9f4@googlegroups.com> (raw)
In-Reply-To: <barmar-8E00EC.19441823042014@news.eternal-september.org>
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)))))
prev parent reply other threads:[~2014-04-26 3:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-23 17:45 Operate on each line in region Jacob Gerlach
2014-04-23 18:03 ` Doug Lewan
2014-04-23 18:05 ` Stefan Monnier
2014-04-23 18:15 ` Pascal J. Bourguignon
[not found] ` <mailman.20129.1398276348.10748.help-gnu-emacs@gnu.org>
2014-04-23 19:06 ` Barry Margolin
2014-04-23 19:18 ` Jacob Gerlach
2014-04-23 23:23 ` Jacob Gerlach
2014-04-23 23:44 ` Barry Margolin
2014-04-26 3:02 ` Jacob Gerlach [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2b2bb390-600b-4f02-9dce-95cd28d3f9f4@googlegroups.com \
--to=jacobgerlach@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.