all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Deniz Dogan <deniz.a.m.dogan@gmail.com>
To: gebser@mousecar.com
Cc: GNU Emacs List <help-gnu-emacs@gnu.org>
Subject: Re: (goto-char ...) error
Date: Tue, 22 Feb 2011 19:45:30 +0100	[thread overview]
Message-ID: <AANLkTikQ6dzupoEsc7SnhN257DQpdCBaJfwa9=SVUKd4@mail.gmail.com> (raw)
In-Reply-To: <4D63FF55.5030901@mousecar.com>

2011/2/22 ken <gebser@mousecar.com>:
>
> 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 have one pair of parentheses too many.

Change:

((goto-char (- ptname 1))

to:

(goto-char (- ptname 1))

The error is telling you that "(goto-char (- ptname 1))" is an invalid
function, which could potentially be confusing, but it really makes
sense.  You call a function named `foo' like (foo ...), but if you do
"((foo ...))" you're trying to call a function named "(foo ...)" which
is not a valid function.

From the documentation of `if':

(if COND THEN ELSE...)
If COND yields non-nil, do THEN, else do ELSE...

This means that your THEN clause must be a single expression.
Everything starting with the third argument to `if' is considered part
of the ELSE clause.

If you want to multiple expressions in the THEN clause, use `progn' as
such:

(if (= x y)
    (progn
      (message "They're equal")
      (message "Hooray!"))
  (message "They're not equal.")
  (message "Too bad, bro."))

I hope that helps!

-- 
Deniz Dogan



  reply	other threads:[~2011-02-22 18:45 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 [this message]
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
     [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

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

  git send-email \
    --in-reply-to='AANLkTikQ6dzupoEsc7SnhN257DQpdCBaJfwa9=SVUKd4@mail.gmail.com' \
    --to=deniz.a.m.dogan@gmail.com \
    --cc=gebser@mousecar.com \
    --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.
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.