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

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

Re: TERRIBLE ERROR :: Invalid search bound - wrong side of point


From: TomSW
Subject: Re: TERRIBLE ERROR :: Invalid search bound - wrong side of point
Date: Fri, 3 Jul 2009 00:47:51 -0700 (PDT)
User-agent: G2/1.0

On Jul 3, 1:16 am, bolega <gnuist...@gmail.com> wrote:
> I am doing a very simple and trivial thing that you often do in bash
> using sed. Replace the end of the line by a token such as #.
>
> I loath to use newline which is a break in emacs since it probably
> does not accept \n.

It does.

> I only want to replace this on one line such as the current line. I
> could narrow to the line but is it really necessary ? Cant I just
> specify the limits in replace-regexp ? Either there is something
> seriously wrong with my understanding of emacs so I must pursue this
> for the sake of learning.

If you specify the limits of a replace operation you normally ensure
that the replacements don't add characters to the region being
changed. Otherwise there is a chance that the replacements will push
point beyond the end limit and you will get the error "Invalid search
bound". Narrowing means you don't need to worry about this.

Generally you should also avoid using replace-regexp in a program (as
explained in the documentation). Since you only want to do one
replacement, all you need is:

 (save-excursion
    (when (re-search-forward "$" nil :noerr)
      (replace-match "#")))

or even:

 (save-excursion
    (goto-char (line-end-position))
    (insert "#"))

regards,
Tom SW


reply via email to

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