Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

shell-script-mode-hook?

35 views
Skip to first unread message

Samir Barjoud

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
Chris Majewski <maje...@cascade.cs.ubc.ca> writes:

> It looks like shell-script-mode never calls my shell-script-mode-hook.
>[...]
> But putting (message "hello") in this
> hook does nothing so I suppose the hook is never called. -chris
>
Hooks don't work like that. A hook is a list of functions to call.

So what you need is:

(defun my-shell-script-mode-hook ()
;; insert code here
)

(add-hook 'shell-script-mode-hook 'my-shell-script-mode-hook)

--
Samir Barjoud
sa...@mindspring.com

Chris Majewski

unread,
Sep 10, 1999, 3:00:00 AM9/10/99
to
It looks like shell-script-mode never calls my shell-script-mode-hook.
Is this a feature (20.4)? The main reason I want the hook is because
shell-script-mode disobeys
(global-unset-key "\C-\C-c")
(global-set-key "\C-c\C-c" 'server-edit)))
forcing me to type \C-x # to terminate the editing of a shell script
(as opposed to \C-c\C-c for all my other modes).
So I thought I'd be clever by putting
(local-unset-key "\C-c\C-c")
(local-set-key "\C-c\C-c" 'server-edit)))
in my shell-script-mode-hook. But putting (message "hello") in this

Philip Lijnzaad

unread,
Sep 10, 1999, 3:00:00 AM9/10/99
to

> Chris Majewski <maje...@cascade.cs.ubc.ca> writes:
>> It looks like shell-script-mode never calls my shell-script-mode-hook.
>> [...]

>> But putting (message "hello") in this
>> hook does nothing so I suppose the hook is never called. -chris
>>

> Hooks don't work like that. A hook is a list of functions to call.

yes, and those functions must be functions of zero arguments.

> So what you need is:

> (defun my-shell-script-mode-hook ()
> ;; insert code here
> )
> (add-hook 'shell-script-mode-hook 'my-shell-script-mode-hook)

The name is very confusing: you don't put hooks into hooks (apart from the
fact that hooks are lists of functions rather than functions). Rather, call
it differently:

(defun do-my-stuff-for-shell-scripts ()
;; insert code here
)
(add-hook 'shell-script-mode-hook 'do-my-stuff-for-shell-scripts)

This solution works, but forces you to write a function for every thing you
may want to stuff into a hook, which can become cumbersome. If you're
bothered by this, use functions that have no name: lambda-forms. Works as
follows:

(add-hook 'shell-script-mode-hook
#'(lamdba ()
;; insert code here
))

The lambda-form just 'creates' a function and returns it; in fact, (defun
...) uses lambda to create the function body internally, and then binds it to
a name.

Philip

--
The cause of the millenium bug is Homo Sapiens having 10 fingers
-----------------------------------------------------------------------------
Philip Lijnzaad, lijn...@ebi.ac.uk | European Bioinformatics Institute,rm A2-24
+44 (0)1223 49 4639 | Wellcome Trust Genome Campus, Hinxton
+44 (0)1223 49 4468 (fax) | Cambridgeshire CB10 1SD, GREAT BRITAIN
PGP fingerprint: E1 03 BF 80 94 61 B6 FC 50 3D 1F 64 40 75 FB 53

Chris Majewski

unread,
Sep 10, 1999, 3:00:00 AM9/10/99
to
To clarify, this is what I have currently:

(add-hook 'shell-script-mode-hook
'(lambda()
(message "hello")


(local-unset-key "\C-c\C-c")
(local-set-key "\C-c\C-c" 'server-edit)))

-chris

Chris Majewski <maje...@cascade.cs.ubc.ca> wrote:
> It looks like shell-script-mode never calls my shell-script-mode-hook.

> Is this a feature (20.4)? The main reason I want the hook is because
> shell-script-mode disobeys
> (global-unset-key "\C-\C-c")
> (global-set-key "\C-c\C-c" 'server-edit)))
> forcing me to type \C-x # to terminate the editing of a shell script
> (as opposed to \C-c\C-c for all my other modes).
> So I thought I'd be clever by putting
> (local-unset-key "\C-c\C-c")
> (local-set-key "\C-c\C-c" 'server-edit)))

> in my shell-script-mode-hook. But putting (message "hello") in this

Kai Großjohann

unread,
Sep 11, 1999, 3:00:00 AM9/11/99
to
Chris Majewski <maje...@cascade.cs.ubc.ca> writes:

> It looks like shell-script-mode never calls my shell-script-mode-hook.

C-h f shell-script-mode RET tells you that this is an alias for
sh-mode. Does it work to use sh-mode-hook instead?

kai
--
I like BOTH kinds of music.

Chris Majewski

unread,
Sep 12, 1999, 3:00:00 AM9/12/99
to
Ah yes. Thank you Kai. -chris
0 new messages