From: Sebastian Tennant <sebyte@smolny.plus.com>
Subject: Re: Evaluation of hooks
Date: Mon, 26 Dec 2005 22:07:16 +0000 [thread overview]
Message-ID: <87slsf4inf.fsf@smolny.plus.com> (raw)
In-Reply-To: 87zmmoreyj.fsf@smolny.plus.com
Sebastian Tennant <sebyte@smolny.plus.com> wrote:
> Tom Breton <tehom@REMOVEpanNOSPAMix.com> wrote:
>
>> Sebastian Tennant <sebyte@smolny.plus.com> wrote:
>>
>>> Hi all,
>>>
>>> I would like to add a function to my emacs-lisp-mode-hook so that whenever
>>> I visit emacs source files, view-mode minor mode is enabled.
>>>
>>> (add-hook 'emacs-lisp-mode-hook
>>> (lambda ()
>>> (when (>= (compare-strings
>>> (buffer-file-name) 1 nil "/usr/share/emacs/" 1 nil) 17)
>>> (view-mode-enable))))
>>>
>>> With the above code in my ~/.emacs, I get the following message at startup:
>>>
>>> >=: Wrong type argument: stringp, nil
>>
>> I doubt that has anything to do with hooks.
>
> It's odd though, don't you think? I'm wondering if I should fie a bug report.
>
>>> but apart from this the startup process is unaffected, and the function is
>>> successfully added to my emacs-lisp-mode-hook, as you can see:
>>>
>>> ((lambda nil
>>> (when
>>> (>
>>> (compare-strings
>>> (buffer-file-name)
>>> 0 nil "/usr/share/emacs/" 0 nil)
>>> 18)
>>> (view-mode-enable))))
>>
>> Nope, that doesn't work either ... sometimes.
>
> I've got it working (despite the aforementioned error at startup). The problem
> was that (view-mode-enable) is only defined as a function *after* view-mode is
> loaded. The fix was to replace this with (view-mode 1).
And I've now realised why I'm getting the error at startup. As we all know, a
*scratch* buffer is created by default at startup and is by definition not
visitng a file. This is what was causing the problem.
Adding the following line before the (when ...) condition fixes this and the
hook is now functioning perfectly.
(unless (not (buffer-file-name))
...)
sdt
next prev parent reply other threads:[~2005-12-26 22:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.20359.1135455656.20277.help-gnu-emacs@gnu.org>
2005-12-25 2:36 ` Evaluation of hooks Tom Breton
2005-12-25 22:26 ` Sebastian Tennant
2005-12-26 22:07 ` Sebastian Tennant [this message]
2005-12-26 22:32 ` Cameron Desautels
2005-12-26 22:41 ` Sebastian Tennant
2005-12-24 19:22 Sebastian Tennant
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=87slsf4inf.fsf@smolny.plus.com \
--to=sebyte@smolny.plus.com \
/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).