all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Strange behavior in search-forward-regexp?
@ 2006-02-11  1:43 Mathias Dahl
  2006-02-11  2:04 ` Barry Margolin
  2006-02-11 11:48 ` Peter Dyballa
  0 siblings, 2 replies; 10+ messages in thread
From: Mathias Dahl @ 2006-02-11  1:43 UTC (permalink / raw)



Take these "buffers":

Buffer 0:

---------- this line is not part of the buffer ----------
row0;test0
row1;test1
row2;test2
---------------------------------------------------------

Buffer 1:

---------- this line is not part of the buffer ----------

row0;test0
row1;test1
row2;test2
---------------------------------------------------------

Evaluate these functions:

(defun test1 ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (if (search-forward-regexp "^[^;]+;.*test1" nil t)
        (message (match-string-no-properties 0)))))

(defun test2 ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (if (search-forward-regexp "^.*test1" nil t)
        (message (match-string-no-properties 0)))))

In buffer 0, test1 and test2 willreturn the same result, "row1;test1",
but in buffer 1, test1 will return "\nrow1;test1" (\n is a newline)
and test2 "row1;test1".

Can someone explain this to me? Why would, in the case of test1, the
newline be included just because the line before is empty?

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

* Re: Strange behavior in search-forward-regexp?
  2006-02-11  1:43 Strange behavior in search-forward-regexp? Mathias Dahl
@ 2006-02-11  2:04 ` Barry Margolin
  2006-02-11  9:45   ` Mathias Dahl
  2006-02-11 11:48 ` Peter Dyballa
  1 sibling, 1 reply; 10+ messages in thread
From: Barry Margolin @ 2006-02-11  2:04 UTC (permalink / raw)


In article <m2wtg21xhd.fsf@gmail.com>,
 Mathias Dahl <brakjoller@gmail.com> wrote:

> Take these "buffers":
> 
> Buffer 0:
> 
> ---------- this line is not part of the buffer ----------
> row0;test0
> row1;test1
> row2;test2
> ---------------------------------------------------------
> 
> Buffer 1:
> 
> ---------- this line is not part of the buffer ----------
> 
> row0;test0
> row1;test1
> row2;test2
> ---------------------------------------------------------
> 
> Evaluate these functions:
> 
> (defun test1 ()
>   (interactive)
>   (save-excursion
>     (goto-char (point-min))
>     (if (search-forward-regexp "^[^;]+;.*test1" nil t)
>         (message (match-string-no-properties 0)))))
> 
> (defun test2 ()
>   (interactive)
>   (save-excursion
>     (goto-char (point-min))
>     (if (search-forward-regexp "^.*test1" nil t)
>         (message (match-string-no-properties 0)))))
> 
> In buffer 0, test1 and test2 willreturn the same result, "row1;test1",
> but in buffer 1, test1 will return "\nrow1;test1" (\n is a newline)
> and test2 "row1;test1".
> 
> Can someone explain this to me? Why would, in the case of test1, the
> newline be included just because the line before is empty?

Because the regular expression . matches any character except newline, 
while [^;] matches any character except ';'.  So newline matches [^;].

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

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

* Re: Strange behavior in search-forward-regexp?
  2006-02-11  2:04 ` Barry Margolin
@ 2006-02-11  9:45   ` Mathias Dahl
  2006-02-12  9:58     ` Barry Margolin
  0 siblings, 1 reply; 10+ messages in thread
From: Mathias Dahl @ 2006-02-11  9:45 UTC (permalink / raw)


Barry Margolin <barmar@alum.mit.edu> writes:

> Because the regular expression . matches any character except newline, 
> while [^;] matches any character except ';'.  So newline matches [^;].

So what happens is that the match begin at the empty line then and
then "wraps around" to the next row? How can I avoid it?

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

* Re: Strange behavior in search-forward-regexp?
  2006-02-11  1:43 Strange behavior in search-forward-regexp? Mathias Dahl
  2006-02-11  2:04 ` Barry Margolin
@ 2006-02-11 11:48 ` Peter Dyballa
  2006-02-11 19:00   ` Mattis
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Dyballa @ 2006-02-11 11:48 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 11.02.2006 um 02:43 schrieb Mathias Dahl:

> In buffer 0, test1 and test2 willreturn the same result, "row1;test1",
> but in buffer 1, test1 will return "\nrow1;test1" (\n is a newline)
> and test2 "row1;test1".

Could you check the encodings used in the two buffers?

--
Greetings

   Pete

The box said "Use Windows 95 or better," so I got a Macintosh

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

* Re: Strange behavior in search-forward-regexp?
  2006-02-11 11:48 ` Peter Dyballa
@ 2006-02-11 19:00   ` Mattis
  2006-02-11 19:33     ` Peter Dyballa
       [not found]     ` <mailman.17.1139690074.2858.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 10+ messages in thread
From: Mattis @ 2006-02-11 19:00 UTC (permalink / raw)
  Cc: help-gnu-emacs

> > In buffer 0, test1 and test2 willreturn the same result, "row1;test1",
> > but in buffer 1, test1 will return "\nrow1;test1" (\n is a newline)
> > and test2 "row1;test1".
>
> Could you check the encodings used in the two buffers?

Actually, I was bluffing when I wrote I had two buffers. :) It was easier to
explain that way.

And, to answer your question:

Coding system for saving this buffer:
  1 -- iso-latin-1 (alias: iso-8859-1 latin-1)

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

* Re: Strange behavior in search-forward-regexp?
  2006-02-11 19:00   ` Mattis
@ 2006-02-11 19:33     ` Peter Dyballa
       [not found]     ` <mailman.17.1139690074.2858.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Peter Dyballa @ 2006-02-11 19:33 UTC (permalink / raw)
  Cc: Emacs help


Am 11.02.2006 um 20:00 schrieb Mattis:

>>> In buffer 0, test1 and test2 willreturn the same result,  
>>> "row1;test1",
>>> but in buffer 1, test1 will return "\nrow1;test1" (\n is a newline)
>>> and test2 "row1;test1".

I've seen the same behaviour of search-forward-regexp "^[^;]+;.*text"  
a few times, wrapping around into the next line. It's obvious that  
newline is not semicolon, so it complies with the search regexp. I  
have no better advice than to use a non-discriminating regexp, i.e.  
search for a set of real characters.

It would probably make more sense to learn the new set of descriptors  
for regexp's (the Perl look alikes), and in which version of GNU  
Emacs they actually work ...

--
Greetings

   Pete

“Computers are good at following instructions, but not at reading  
your mind.”
    - D. E. Knuth, The TeXbook, Addison-Wesley 1984, 1986, 1996, p. 9

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

* Re: Strange behavior in search-forward-regexp?
       [not found]     ` <mailman.17.1139690074.2858.help-gnu-emacs@gnu.org>
@ 2006-02-11 21:43       ` Mathias Dahl
  0 siblings, 0 replies; 10+ messages in thread
From: Mathias Dahl @ 2006-02-11 21:43 UTC (permalink / raw)


Peter Dyballa <Peter_Dyballa@web.de> writes:

> I've seen the same behaviour of search-forward-regexp "^[^;]+;.*text"
> a few times, wrapping around into the next line. It's obvious that
> newline is not semicolon, so it complies with the search regexp. I
> have no better advice than to use a non-discriminating regexp, i.e.
> search for a set of real characters.

The solution was easy:

(defun test3 ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (if (search-forward-regexp "^[^\n.;]+;.*test1" nil t)
        (message (match-string-no-properties 0)))))

Thanks for the hint, you just fixed a bug in tumme! :)

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

* Re: Strange behavior in search-forward-regexp?
  2006-02-11  9:45   ` Mathias Dahl
@ 2006-02-12  9:58     ` Barry Margolin
  2006-02-12 14:58       ` Mathias Dahl
  0 siblings, 1 reply; 10+ messages in thread
From: Barry Margolin @ 2006-02-12  9:58 UTC (permalink / raw)


In article <m27j825iw0.fsf@gmail.com>,
 Mathias Dahl <brakjoller@gmail.com> wrote:

> Barry Margolin <barmar@alum.mit.edu> writes:
> 
> > Because the regular expression . matches any character except newline, 
> > while [^;] matches any character except ';'.  So newline matches [^;].
> 
> So what happens is that the match begin at the empty line then and
> then "wraps around" to the next row? How can I avoid it?

Use [^;<newline>] in the regular expression, where <newline> is entered 
with C-q C-j.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

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

* Re: Strange behavior in search-forward-regexp?
  2006-02-12  9:58     ` Barry Margolin
@ 2006-02-12 14:58       ` Mathias Dahl
  2006-02-12 21:19         ` Barry Margolin
  0 siblings, 1 reply; 10+ messages in thread
From: Mathias Dahl @ 2006-02-12 14:58 UTC (permalink / raw)


Barry Margolin <barmar@alum.mit.edu> writes:

>> So what happens is that the match begin at the empty line then and
>> then "wraps around" to the next row? How can I avoid it?
>
> Use [^;<newline>] in the regular expression, where <newline> is entered 
> with C-q C-j.

Thanks!  That's what I eventually did (although I used `\n'
instead)and posted the answer here, but it seems thet gmane or the
list has had problems yesterday.

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

* Re: Strange behavior in search-forward-regexp?
  2006-02-12 14:58       ` Mathias Dahl
@ 2006-02-12 21:19         ` Barry Margolin
  0 siblings, 0 replies; 10+ messages in thread
From: Barry Margolin @ 2006-02-12 21:19 UTC (permalink / raw)


In article <m2hd74fwu9.fsf@gmail.com>,
 Mathias Dahl <brakjoller@gmail.com> wrote:

> Barry Margolin <barmar@alum.mit.edu> writes:
> 
> >> So what happens is that the match begin at the empty line then and
> >> then "wraps around" to the next row? How can I avoid it?
> >
> > Use [^;<newline>] in the regular expression, where <newline> is entered 
> > with C-q C-j.
> 
> Thanks!  That's what I eventually did (although I used `\n'
> instead)and posted the answer here, but it seems thet gmane or the
> list has had problems yesterday.

Yeah, I didn't remember until after I posted that you were doing this in 
code, not interactively.  When using interactive re-search, you have to 
type C-q C-j.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

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

end of thread, other threads:[~2006-02-12 21:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-11  1:43 Strange behavior in search-forward-regexp? Mathias Dahl
2006-02-11  2:04 ` Barry Margolin
2006-02-11  9:45   ` Mathias Dahl
2006-02-12  9:58     ` Barry Margolin
2006-02-12 14:58       ` Mathias Dahl
2006-02-12 21:19         ` Barry Margolin
2006-02-11 11:48 ` Peter Dyballa
2006-02-11 19:00   ` Mattis
2006-02-11 19:33     ` Peter Dyballa
     [not found]     ` <mailman.17.1139690074.2858.help-gnu-emacs@gnu.org>
2006-02-11 21:43       ` Mathias Dahl

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.