help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Operate on each line in region


From: Stefan Monnier
Subject: Re: Operate on each line in region
Date: Wed, 23 Apr 2014 14:05:18 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

> (defun my-justify (start end)
> (interactive 'r')
> (while (< (point) end))
> ...body...
> (forward-line 1)))

Just beware that as you go modify the buffer, the position that you
consider as "the end" will move as well.  You can solve this problem in
a few different ways:
- loop from end to start.
- make sure `end' is a marker rather than an integer so it will be
  automatically adjusted to keep pointing to the same logical position in
  the text.
- use narrowing (which uses similar machinery as a marker).

I personally recommend against using narrowing, unless it's *really*
much simpler.  The reason for it is that narrowing affects "everything",
so it's kind of a sledgehammer which can have unintended consequences.

> I'm wondering if there is a more straightforward way to accomplish this.

Not sure what "more straightforward" would look like.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]