unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tim X <timx@nospam.dev.null>
To: help-gnu-emacs@gnu.org
Subject: Re: (goto-char ...) error
Date: Wed, 23 Feb 2011 09:27:28 +1100	[thread overview]
Message-ID: <87mxlnpuwf.fsf@rapttech.com.au> (raw)
In-Reply-To: mailman.11.1298399070.22047.help-gnu-emacs@gnu.org

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


  parent reply	other threads:[~2011-02-22 22:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-22 16:47 (goto-char ...) error ken
2011-02-22 17:31 ` Deniz Dogan
2011-02-22 18:24   ` ken
2011-02-22 18:45     ` Deniz Dogan
2011-02-22 19:22       ` ken
2011-02-22 19:45         ` Deniz Dogan
2011-02-22 20:55           ` Drew Adams
     [not found]       ` <mailman.1.1298402588.16069.help-gnu-emacs@gnu.org>
2011-02-22 22:50         ` Tim X
     [not found]   ` <mailman.11.1298399070.22047.help-gnu-emacs@gnu.org>
2011-02-22 22:27     ` Tim X [this message]
     [not found] <mailman.3.1298393577.375.help-gnu-emacs@gnu.org>
2011-02-22 22:15 ` Tim X

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mxlnpuwf.fsf@rapttech.com.au \
    --to=timx@nospam.dev.null \
    --cc=help-gnu-emacs@gnu.org \
    /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.
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).