unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Why does this re-search forward fail?
@ 2021-04-20 13:56 Arthur Miller
  2021-04-20 14:13 ` Andreas Schwab
  2021-04-20 14:49 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Arthur Miller @ 2021-04-20 13:56 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1557 bytes --]


Hello,

in rare and spare moments when I am not feeding the cutiest best of all
cute beasts or changing her diapers, I was playing with a little idea to
hide org-babel markers in my init file. I wrote a small minor mode for
this, which I have attached in this mail. There is a small problem with
the loop, where the main action is happening:

#+begin_src emacs-lisp
(while (re-search-forward hbm--src-marker-re (eobp) t)
          (hbm--update-line visibility))
#+end_src

The RE I search for is:

(defvar hbm--src-marker-re "^[ \t]*#\\+\\|begin_src\\|end_src")

What is happeneing is that for some strange reason, the search jumps
over some lines or stop working. If I disable/enable the mode, same
lines that failed, work.

I also wrote a small aritificial test, that will generate 200 src blocks
in a test file, and what I see there is that search fails after ~ 55
blocks, every time. Since all 200 blocks are machine generated I see no
reason why search would fail.

I also tested to iterate through the file with more explicit loop that
went line by line through entire line, but with same result.

#+begin-src emacs-lisp
(defun hbm--update-markers (visibility)
  (save-excursion
    (goto-char (point-min))
    (with-silent-modifications
      (while (not (eobp))
        (beginning-of-line)
        (when (re-search-forward hbm--src-marker-re (eobp) t)
          (hbm--update-line visibility))
        (forward-line)))))
#+end_src

Any idea?

The Emacs at hand is 27.1 (build 1, x86_64-w64-mingw32) of
2020-08-21. The test was done with -Q option.


[-- Attachment #2: ob-hide-markers.el --]
[-- Type: application/emacs-lisp, Size: 4953 bytes --]

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

* Re: Why does this re-search forward fail?
  2021-04-20 13:56 Why does this re-search forward fail? Arthur Miller
@ 2021-04-20 14:13 ` Andreas Schwab
  2021-04-20 14:55   ` Arthur Miller
  2021-04-20 14:49 ` Stefan Monnier
  1 sibling, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2021-04-20 14:13 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-devel

On Apr 20 2021, Arthur Miller wrote:

> The RE I search for is:
>
> (defvar hbm--src-marker-re "^[ \t]*#\\+\\|begin_src\\|end_src")

What is that regexp supposed to match?  Why is it not defined like this:

(defvar hbm--src-marker-re "^[ \t]*#\\+\\(begin_src\\|end_src\\)")

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



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

* Re: Why does this re-search forward fail?
  2021-04-20 13:56 Why does this re-search forward fail? Arthur Miller
  2021-04-20 14:13 ` Andreas Schwab
@ 2021-04-20 14:49 ` Stefan Monnier
  2021-04-20 16:46   ` Arthur Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2021-04-20 14:49 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-devel

> (while (re-search-forward hbm--src-marker-re (eobp) t)

I don't know about your particular problem but the call above looks
wrong in its `limit` argument which is supposed to be either nil or
a position whereas `eobp` returns a boolean (i.e. either nil or t).


        Stefan




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

* Re: Why does this re-search forward fail?
  2021-04-20 14:13 ` Andreas Schwab
@ 2021-04-20 14:55   ` Arthur Miller
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Miller @ 2021-04-20 14:55 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: emacs-devel

Andreas Schwab <schwab@linux-m68k.org> writes:

> On Apr 20 2021, Arthur Miller wrote:
>
>> The RE I search for is:
>>
>> (defvar hbm--src-marker-re "^[ \t]*#\\+\\|begin_src\\|end_src")
>
> What is that regexp supposed to match?

Just #+begin_src or #+end_src

preceded by blanks, just spaces and tabs.

> Why is it not defined like this:
>
> (defvar hbm--src-marker-re "^[ \t]*#\\+\\(begin_src\\|end_src\\)")

I think I had it so at some time, but it didn't worked for some reason,
or it was same problem. I don't remember, but I went away from it. I
just tried again; it made no difference. In test.org I still get first
55 blocks processed.

Anyway thanks, I think it is more correct to group it with '(' and ')'.

/a



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

* Re: Why does this re-search forward fail?
  2021-04-20 14:49 ` Stefan Monnier
@ 2021-04-20 16:46   ` Arthur Miller
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Miller @ 2021-04-20 16:46 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> (while (re-search-forward hbm--src-marker-re (eobp) t)
>
> I don't know about your particular problem but the call above looks
> wrong in its `limit` argument which is supposed to be either nil or
> a position whereas `eobp` returns a boolean (i.e. either nil or t).

Indeed. I ment (point-max) but had something else in m head when I wrote
it.

Thanks.




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

end of thread, other threads:[~2021-04-20 16:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 13:56 Why does this re-search forward fail? Arthur Miller
2021-04-20 14:13 ` Andreas Schwab
2021-04-20 14:55   ` Arthur Miller
2021-04-20 14:49 ` Stefan Monnier
2021-04-20 16:46   ` Arthur Miller

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).