Path: utzoo!attcan!uunet!samsung!rex!uflorida!novavax!weiner From: weiner@novavax.UUCP (Bob &) Newsgroups: comp.emacs Subject: Re: text-mode-hook Summary: How to properly add to GNU Emacs hook variables Message-ID: Date: 12 Apr 90 03:37:48 GMT References: Sender: weiner@novavax.UUCP Organization: Motorola Inc., Boynton Beach, FL Lines: 60 In-reply-to: pd@ixi.uucp's message of 10 Apr 90 15:02:55 GMT pd@ixi.uucp (Paul Davey) writes: > > In article Damon.Lipparelli@CS.CMU.EDU writes: > Hello. I'm having trouble with the text-mode-hook feature. I'd like to > set things so that when I enter text mode, I'm automatically put into > auto-fill mode as well. I tried setting the variable text-mode-hook to > be auto-fill-mode (ie, "(setq text-mode-hook 'auto-fill-mode)"), but I > get the error "Wrong number of arguments" and then a lambda expression. > > I had some trouble working this out when I first started customising > emacs. One way is to use > > (setq text-mode-hook 'turn-on-auto-fill) > > but when I wanted abbrev mode in text as well I changed it to > > (setq text-mode-hook '(lambda () (abbrev-mode 1) (auto-fill-mode 1))) > A better solution to the above problem is one we have used on a heavily site customized version of GNU Emacs for two years. Emacs init files seldom have any knowledge of whether another init file has already set a hook variable to some value and they typically don't want to test for this either. Overwriting such a variable is a bad idea since one typically wants to add functionality to the hook, not replace it. The best tactic is then to simply append to the value of a hook variable when you want to change its behavior in an init file. Here is the needed Elisp: ;; Bob Weiner, Motorola Inc., 4/14/88 ;; ;; Function used anytime a hook variable value needs to be initially set ;; or further customized. ;; (defun append-to-var (var-symbol-name list-to-add) "If VAR-SYMBOL-NAME is bound, append LIST-TO-ADD (a list) to value of variable (a list) given by var-symbol-name. If unbound, variable is set to list-to-add. Often used to append to 'hook' variables." (set-variable var-symbol-name (append (and (boundp var-symbol-name) (symbol-value var-symbol-name)) list-to-add))) ;; ;; Examples ;; ;; Default to Auto-fill when in text mode (append-to-var 'text-mode-hook '(turn-on-auto-fill)) ;; Add personal behavior to rmail hook (append-to-var 'rmail-mode-hook '(rmail-personal-init)) (defun rmail-personal-init () "Function to run when rmail-mode is invoked." ) -- Bob Weiner, Motorola, Inc., Usenet: ...!gatech!uflorida!novavax!weiner Internet: novavax!weiner@uunet.uu.net (407) 364-2087