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

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

Re: (goto-char ...) error


From: Tim X
Subject: Re: (goto-char ...) error
Date: Wed, 23 Feb 2011 09:27:28 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

ken <gebser@mousecar.com> writes:

> On 02/22/2011 12:31 PM Deniz Dogan wrote:
>> 2011/2/22 ken <gebser@mousecar.com>:
>>> Performing one search, I save the result with
>>>
>>> (setq ptname (re-search-forward ...))
>>>
>>> Then I want to back up one character and perform another search, so I do
>>>
>>> (goto-char (- ptname 1))
>>>
>>> But this pukes an error.  What's unkosher here?
>>>
>> 
>> It's much easier if you tell us what the error is.
>> 
>> I tried to reproduce the problem using this code:
>> 
>> ;; search for "a"
>> (let ((ptname (re-search-forward "a" nil t)))
>>   (when ptname
>>     (goto-char (- ptname 1))))
>> 
>> It all depends on how you use re-search-forward. As you can see in my
>> example, I pass t as the third argument meaning "don't error if you
>> can't find it, just return nil". I then make sure that ptname is
>> non-nil before I try to act on it using `-', otherwise we would be
>> doing (- nil 1) which makes no sense.
>> 
>
> My understanding is that the 4th arg to re-search-forward is to repeat
> the search, so I set that to nil.
>
> I get the same error whether the 3rd arg is t or nil (!?):
>
> (setq ptname (re-search-forward "REGEXP" endpt t nil))
>       (if ptname
>         ((goto-char (- ptname 1))
>            ....
>
> The error line in *Messages* says:
>
> if: Invalid function: (goto-char (- begin-name-value 1))
>

You probably don't need the ptname because re-search-forward sets point
and you can always get the value from the variable match-beginning

(when (re-search-forward "REGEXP" limit t)
      (goto-char (max (1- (point))
                      (point-min)))
      .....)

Note also that there is no need to put a 'nil' for the last optional
argument - if you don't provide a value, it will default to nil.

Tim

-- 
tcross (at) rapttech dot com dot au


reply via email to

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