* Evaluation of hooks
@ 2005-12-24 19:22 Sebastian Tennant
0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Tennant @ 2005-12-24 19:22 UTC (permalink / raw)
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
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))))
Needless to say the hook doesn't work, i.e., view-mode is not enabled when I
visit files whose full name begins /usr/share/emacs/.
The condition itself works fine, but just not as a hook. I have tried quoting
the function (buffer-file-name) but this did not improve things.
Any help much appreciated.
TIA
sdt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Evaluation of hooks
[not found] <mailman.20359.1135455656.20277.help-gnu-emacs@gnu.org>
@ 2005-12-25 2:36 ` Tom Breton
2005-12-25 22:26 ` Sebastian Tennant
0 siblings, 1 reply; 6+ messages in thread
From: Tom Breton @ 2005-12-25 2:36 UTC (permalink / raw)
Sebastian Tennant <sebyte@smolny.plus.com> writes:
> 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.
> 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.
Try it in a few different buffers - especially those like *Article*
that aren't visiting a file. The result is different depending on
what buffer you try it in.
The bug seems to be that when `buffer-file-name' does not return a
string, `compare-strings' justifiably barfs.
--
Tom Breton, the calm-eyed visionary
Ho ho ho, Merry Whatever!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Evaluation of hooks
2005-12-25 2:36 ` Evaluation of hooks Tom Breton
@ 2005-12-25 22:26 ` Sebastian Tennant
2005-12-26 22:07 ` Sebastian Tennant
0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Tennant @ 2005-12-25 22:26 UTC (permalink / raw)
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).
sdt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Evaluation of hooks
2005-12-25 22:26 ` Sebastian Tennant
@ 2005-12-26 22:07 ` Sebastian Tennant
2005-12-26 22:32 ` Cameron Desautels
0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Tennant @ 2005-12-26 22:07 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Evaluation of hooks
2005-12-26 22:07 ` Sebastian Tennant
@ 2005-12-26 22:32 ` Cameron Desautels
2005-12-26 22:41 ` Sebastian Tennant
0 siblings, 1 reply; 6+ messages in thread
From: Cameron Desautels @ 2005-12-26 22:32 UTC (permalink / raw)
On Mon, Dec 26, 2005 at 10:07:16PM +0000, Sebastian Tennant wrote:
> Adding the following line before the (when ...) condition fixes this and the
> hook is now functioning perfectly.
>
> (unless (not (buffer-file-name))
> ...)
I suppose this is a bit nit-picky, but you may as well make it
(if (buffer-file-name)
...)
instead of using both ``unless'' and ``not''.
--
Cameron Desautels <cam@apt2324.com>
Someday, we'll look back on this, laugh nervously, and change the
subject.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Evaluation of hooks
2005-12-26 22:32 ` Cameron Desautels
@ 2005-12-26 22:41 ` Sebastian Tennant
0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Tennant @ 2005-12-26 22:41 UTC (permalink / raw)
Cameron Desautels <cam@apt2324.com> wrote:
> On Mon, Dec 26, 2005 at 10:07:16PM +0000, Sebastian Tennant wrote:
>> Adding the following line before the (when ...) condition fixes this and the
>> hook is now functioning perfectly.
>>
>> (unless (not (buffer-file-name))
>> ...)
>
> I suppose this is a bit nit-picky, but you may as well make it
>
> (if (buffer-file-name)
> ...)
>
> instead of using both ``unless'' and ``not''.
I suppose so, but should code be compact or human readable?
In this context, where the hook is written with file visiting buffers in mind,
I think it is clearer to say "unless the buffer is not visiting a file..."
sdt
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-12-26 22:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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
2005-12-26 22:32 ` Cameron Desautels
2005-12-26 22:41 ` Sebastian Tennant
2005-12-24 19:22 Sebastian Tennant
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).