[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Why does this re-search forward fail?
From: |
Arthur Miller |
Subject: |
Why does this re-search forward fail? |
Date: |
Tue, 20 Apr 2021 15:56:07 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (windows-nt) |
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.
ob-hide-markers.el
Description: application/emacs-lisp
- Why does this re-search forward fail?,
Arthur Miller <=