From: Pascal Bourguignon <spam@mouse-potato.com>
Subject: Re: match-string debugging problem
Date: 10 Mar 2005 18:06:52 +0100 [thread overview]
Message-ID: <87ekenmnv7.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: mailman.3303.1110470311.32256.help-gnu-emacs@gnu.org
Stephen Berman <Stephen.Berman@gmx.net> writes:
> There seems to be something about match-string that I don't
> understand. Here is an example of the kind of code I'm working with:
>
> (defvar mystring1 "+++++ ")
> (defvar mystring2 " ~~~~~")
> (defun mystring-list ()
> (interactive)
> (with-current-buffer (get-buffer-create "*test*")
> (switch-to-buffer "*test*")
> (dotimes (num 5)
> (insert mystring1 "test" (int-to-string (1+ num)) mystring2 "\n"))
> (goto-char (point-min))
> (let ((mystring-list ()))
> (while (re-search-forward
> (concat "^" (regexp-quote mystring1) "\\(.+\\)"
> (regexp-quote mystring2) "$")
> (point-max) t)
> (setq mystring-list (append (list (match-string 1)) mystring-list)))
> (insert "\n")
> (setq mystring-list (reverse mystring-list))
> (dolist (elt mystring-list)
> (insert elt " ")))))
>
> After evalling this code and typing `M-x mystring-list', buffer *test*
> consists of these lines:
>
> +++++ test1 ~~~~~
> +++++ test2 ~~~~~
> +++++ test3 ~~~~~
> +++++ test4 ~~~~~
> +++++ test5 ~~~~~
> test1 test2 test3 test4 test5
>
> The last line indicates that match-string correctly matches the
> strings that build mystring-list. But when I step through the code
> with edebug, match-string always returns nil and a wrong-type-argument
> error is raised at the insert (since nil is not char-or-string-p).
> (Edebug isn't the problem: evalling first the regexp search code in
> *test* and then (match-string 1) also returns nil.) Because of this
> I'm having a hard time debugging other code that uses match-string.
> Can someone explain what's going on?
re-search-forward uses global state (buffer, matched range, etc) as
match-data, to communicate with match-string. When you're debugging,
this global state is switched or modified. One could consider it a
bug in the debugger.
See: match-data
save-match-data
save-excursion
save-buffer
--
__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
next parent reply other threads:[~2005-03-10 17:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.3303.1110470311.32256.help-gnu-emacs@gnu.org>
2005-03-10 17:06 ` Pascal Bourguignon [this message]
2005-03-10 22:27 ` match-string debugging problem Stephen Berman
[not found] ` <mailman.3372.1110495427.32256.help-gnu-emacs@gnu.org>
2005-03-10 23:40 ` Pascal Bourguignon
2005-03-11 22:18 ` Stephen Berman
2005-03-13 21:52 ` Alan Wehmann
2005-03-14 19:32 ` Stephen Berman
2005-03-10 15:18 Stephen Berman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ekenmnv7.fsf@thalassa.informatimago.com \
--to=spam@mouse-potato.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.