[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (goto-char ...) error
From: |
Deniz Dogan |
Subject: |
Re: (goto-char ...) error |
Date: |
Tue, 22 Feb 2011 20:45:25 +0100 |
2011/2/22 ken <gebser@mousecar.com>:
>
> On 02/22/2011 01:45 PM Deniz Dogan wrote:
>> 2011/2/22 ken <gebser@mousecar.com>:
>>> On 02/22/2011 12:31 PM Deniz Dogan wrote:
>>>> 2011/2/22 ken <gebser@mousecar.com>:
>>>>> ....
>>>>
>>> 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!
>
> Yeah, I think it should. Thanks.
>
> Just to be clear about one more thing I'll be addressing subsequently,
> i.e., another "if" nested inside the first:
>
> (if (= x y)
> (progn
> (message "They're equal")
> (message "Hooray!")
> (if (= x z)
> (progn
> (message "The next one's equal too.")
> (message "Hooray++!")))) ; enuf )s to match up to 1st progn
> (message "They're not equal.")
> (message "Too bad, bro."))
>
This is fine, but when you don't need the ELSE clause, it's usually
better to use `when', which is like `if', except it doesn't have an
ELSE and you don't need to use `progn'.
(if (= x y)
(progn
(message "They're equal")
(message "Hooray!")
(when (= x z)
(message "The next one's equal too.")
(message "Hooray++!")))
(message "They're not equal.")
(message "Too bad, bro."))
There is also `unless' which you can use when you find yourself doing
"when (not (whatever))".
(unless (= x y)
(message "OMG they differ!")
(if (> x y)
(message "OMG X BEATS Y!!!")
(message "OMG Y BEATS X")))
I encourage you to read the Elisp manual which should come with your
Emacs. Hit "C-h i d m Elisp RET" in Emacs. What I told you just now
is covered in chapter 10 "(elisp) Control Structures".
--
Deniz Dogan
Message not available