unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* TERRIBLE ERROR :: Invalid search bound - wrong side of point
@ 2009-07-02 23:16 bolega
  2009-07-02 23:35 ` bolega
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: bolega @ 2009-07-02 23:16 UTC (permalink / raw)
  To: help-gnu-emacs

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.


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.

I tried several variants:

(replace-regexp "$" "#" nil (line-beginning-position) (line-end-
position nil) )
(replace-regexp "$" "#" nil (line-beginning-position) (+ (line-end-
position nil) 1))


And why is a first nil needed ? Cant it be a t ?

Here is the error listing.

Debugger entered--Lisp error: (error "Invalid search bound (wrong side
of point)")
  re-search-forward("$" #<marker at 107360 in file.txt> t)
  perform-replace("$" "##" nil t nil nil nil 107360 107360)
  replace-regexp("$" "##" nil 107360 107360)
  eval((replace-regexp "$" "##" nil (point) (line-end-position nil)))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
* call-interactively(eval-last-sexp)
  recursive-edit()



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: TERRIBLE ERROR :: Invalid search bound - wrong side of point
  2009-07-02 23:16 TERRIBLE ERROR :: Invalid search bound - wrong side of point bolega
@ 2009-07-02 23:35 ` bolega
  2009-07-03  3:42 ` Pillsy
  2009-07-03  7:47 ` TomSW
  2 siblings, 0 replies; 6+ messages in thread
From: bolega @ 2009-07-02 23:35 UTC (permalink / raw)
  To: help-gnu-emacs

To save trouble to myself, I searched the whole of google for the
error but no luck. One issue is the "$" which confuses any search
engine.

On Jul 2, 4:16 pm, 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.
>
> 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.
>
> I tried several variants:
>
> (replace-regexp "$" "#" nil (line-beginning-position) (line-end-
> position nil) )
> (replace-regexp "$" "#" nil (line-beginning-position) (+ (line-end-
> position nil) 1))
>
> And why is a first nil needed ? Cant it be a t ?
>
> Here is the error listing.
>
> Debugger entered--Lisp error: (error "Invalid search bound (wrong side
> of point)")
>   re-search-forward("$" #<marker at 107360 in file.txt> t)
>   perform-replace("$" "##" nil t nil nil nil 107360 107360)
>   replace-regexp("$" "##" nil 107360 107360)
>   eval((replace-regexp "$" "##" nil (point) (line-end-position nil)))
>   eval-last-sexp-1(nil)
>   eval-last-sexp(nil)
> * call-interactively(eval-last-sexp)
>   recursive-edit()



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: TERRIBLE ERROR :: Invalid search bound - wrong side of point
  2009-07-02 23:16 TERRIBLE ERROR :: Invalid search bound - wrong side of point bolega
  2009-07-02 23:35 ` bolega
@ 2009-07-03  3:42 ` Pillsy
  2009-07-03  4:46   ` bolega
  2009-07-03  7:47 ` TomSW
  2 siblings, 1 reply; 6+ messages in thread
From: Pillsy @ 2009-07-03  3:42 UTC (permalink / raw)
  To: help-gnu-emacs

On Jul 2, 7:16 pm, bolega <gnuist...@gmail.com> wrote:
[...]
> 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.

You should probably try comp.emacs or gnu.help.emacs, too, since this
group focuses almost entirely on the Common Lisp dialect of Lisp.
Nonetheless, I'll take a stab at answering your question.

> I tried several variants:

> (replace-regexp "$" "#" nil (line-beginning-position) (line-end-
> position nil) )
> (replace-regexp "$" "#" nil (line-beginning-position) (+ (line-end-
> position nil) 1))

Well, one thing that works is to capture the text of the line as a
group, like so:

(replace-regexp "^\\(.*\\)$" "\\1#"
		  nil
		  (line-beginning-position)
		  (line-end-position))

However, if you just want to stick a character onto the end of the
line, why not just move the point there and insert the character
instead of using regexps?

(save-excursion (end-of-line) (insert "#"))

HTH,
Pillsy


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: TERRIBLE ERROR :: Invalid search bound - wrong side of point
  2009-07-03  3:42 ` Pillsy
@ 2009-07-03  4:46   ` bolega
  2009-07-03  7:16     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 6+ messages in thread
From: bolega @ 2009-07-03  4:46 UTC (permalink / raw)
  To: help-gnu-emacs

On Jul 2, 8:42 pm, Pillsy <pillsb...@gmail.com> wrote:
> On Jul 2, 7:16 pm, bolega <gnuist...@gmail.com> wrote:
> [...]
>
> > 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.
>
> You should probably try comp.emacs or gnu.help.emacs, too, since this
> group focuses almost entirely on the Common Lisp dialect of Lisp.
> Nonetheless, I'll take a stab at answering your question.
>
> > I tried several variants:
> > (replace-regexp "$" "#" nil (line-beginning-position) (line-end-
> > position nil) )
> > (replace-regexp "$" "#" nil (line-beginning-position) (+ (line-end-
> > position nil) 1))
>
> Well, one thing that works is to capture the text of the line as a
> group, like so:
>
> (replace-regexp "^\\(.*\\)$" "\\1#"
>                   nil
>                   (line-beginning-position)
>                   (line-end-position))
>
> However, if you just want to stick a character onto the end of the
> line, why not just move the point there and insert the character
> instead of using regexps?
>
> (save-excursion (end-of-line) (insert "#"))
>
> HTH,
> Pillsy

There is something really crazy going on.

When I try your first suggestion,

(replace-regexp "^\\(.*\\)$" "\\1#" nil (line-beginning-position)
(line-end-position))

I get this error:

Debugger entered--Lisp error: (error "Invalid search bound (wrong side
of point)")
  re-search-forward("^\\(.*\\)$" #<marker at 109804 in file.txt> t)
  perform-replace("^\\(.*\\)$" "\\1#" nil t nil nil nil 109703 109803)
  replace-regexp("^\\(.*\\)$" "\\1#" nil 109703 109803)
  eval((replace-regexp "^\\(.*\\)$" "\\1#" nil (line-beginning-
position) (line-end-position)))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
* call-interactively(eval-last-sexp)


I want to understand what is going on so I learn to trace and debug an
error than be doing endless work-arounds. Predictive programming is
desired - which works the first time !!!




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: TERRIBLE ERROR :: Invalid search bound - wrong side of point
  2009-07-03  4:46   ` bolega
@ 2009-07-03  7:16     ` Thien-Thi Nguyen
  0 siblings, 0 replies; 6+ messages in thread
From: Thien-Thi Nguyen @ 2009-07-03  7:16 UTC (permalink / raw)
  To: help-gnu-emacs

() bolega <gnuist006@gmail.com>
() Thu, 2 Jul 2009 21:46:31 -0700 (PDT)

   Predictive programming is
   desired - which works the first time !!!

I take this to mean you find it important to construct
a proper model of the situation before you implement.
Am i mistaken?

thi




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: TERRIBLE ERROR :: Invalid search bound - wrong side of point
  2009-07-02 23:16 TERRIBLE ERROR :: Invalid search bound - wrong side of point bolega
  2009-07-02 23:35 ` bolega
  2009-07-03  3:42 ` Pillsy
@ 2009-07-03  7:47 ` TomSW
  2 siblings, 0 replies; 6+ messages in thread
From: TomSW @ 2009-07-03  7:47 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-07-03  7:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-02 23:16 TERRIBLE ERROR :: Invalid search bound - wrong side of point bolega
2009-07-02 23:35 ` bolega
2009-07-03  3:42 ` Pillsy
2009-07-03  4:46   ` bolega
2009-07-03  7:16     ` Thien-Thi Nguyen
2009-07-03  7:47 ` TomSW

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).