help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error in replace-match: "args out of range"


From: ken
Subject: Re: error in replace-match: "args out of range"
Date: Mon, 04 Apr 2011 12:13:15 -0400
User-agent: Thunderbird 2.0.0.24 (X11/20101213)

On 04/03/2011 07:19 PM PJ Weisberg wrote:
> On 4/3/11, ken <address@hidden> wrote:
>> On 03/28/2011 04:32 PM Stefan Monnier wrote:
>>> I'm just saying that
>>>
>>> M-: (some-regexp-search) RET
>>> M-: (replace-match ...) RET
>>>
>>> won't always do what you want, because a whole lot of code will run
>>> between the two.
>>>
>>>
>>>         Stefan
>> Hmm.  I'm hearing "this is faith-based functionality."  Does it have to
>> do with the fact that all processes running from one emacs session have
>> the one and the same PID?  I recall reading a discussion on this list
>> (which was largely outside my capacity) multiple years ago about some
>> problem which 'would be resolved when threading is implemented.'  Is
>> this an issue of that sort?
> 
> It sounds more like the sort of issue that would be *created* when
> threading was implemented.

Probably this discussion won't solve anything, so let's leave it for
another time.


> 
> Based on what Stefan said, a more helpful question might be: what
> happens between the call to match-string and the call to
> replace-match?  Are they in the same function, and close together?
> What can match-string tell you about the string you're trying to
> replace?
> 
> -PJ
> 

Here's the relevant code fragment:

    (if (re-search-forward aname-re-str head-text-end-pt t)
        (progn  
          (setq aname-str (match-string 2))
          (setq head-text-nested (match-string 4))
          (if (equal head-text-nested "")
              (progn
                (setq head-text-nested (create-heading-text))
                (if (equal aname-str "")
                    (progn
                      (setq aname-str (create-aname head-text-nested))
                      (replace-match head-text-nested t nil nil 4)
                      (replace-match aname-str t nil nil 2))
                  (replace-match head-text-nested t t nil 4))) ;ERROR:

The top line above is the search.  The last line is the replace-match
which fails.  The couple replace-match lines above it might also fail...
haven't tested those yet.

create-aname is nothing but a set of setq's and a read-from-minibuffer.
 create-heading-text is just a read-from-minibuffer.

So, yes, the search and replace-match are in the same function.  Are
they "close together"?  I'd say yes, but that's a judgment call really.
 The string I want to replace in this particular instance is a null string.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]