[comp.emacs] Need help with hook in init file

templon@silver.bacs.indiana.edu (jeffrey templon) (06/22/89)

I want to have the variable find-file-hooks set so that when I find a
file, the buffer automatically gets set to truncate-line mode.  I tried
something like

(setq find-file-hooks 'set-variable truncate-lines t)

and various other permutations with more quotes and parens, but i just
got weird erros (sequencep error, or error in init file, or wrong 
argument type.)  is it obvious that i know no lisp?

Can somebody give me the magic incantation?

			jt

mesard@bbn.com (Wayne Mesard) (06/22/89)

In article <22487@iuvax.cs.indiana.edu> templon@silver.bacs.indiana.edu (jeffrey templon) writes:
>
>I want to have the variable find-file-hooks set so that when I find a
>file, the buffer automatically gets set to truncate-line mode.  I tried
>something like
>
>(setq find-file-hooks 'set-variable truncate-lines t)

Find-file-hook's documentation (available via Ctrl-H V) says that it is
a "list of functions..."  So the syntax would be:

  (setq find-file-hooks '(func1 func2))

Where func1 and func2 are functions (written by you or someone else)
which take no arguments.  So you could do:

  (defun set-truncate-lines ()
    (setq truncate-lines t))

and sub "set-truncate-lines" for "func1 func2" above.  Or to really wow
you're friends, define an "anonymous" function using a lambda
expression:

  (setq find-file-hooks '((lambda () (setq truncate-lines t))))

[For more information on lambda expressions, see _Practical_Jokes_Played
on_the_LISP_Community_ by Guy Steele.]

But I don't think this is what you want.  This hook is for >making
something happen< each time a file is loaded.  What you want is >for
something to be true< all the time.  (Right?)

The setq-default function is designed for this porpoise.  (See the
documentation available via Ctrl-H F.)  Put the following in your .emacs
file:

  (setq-default truncate-lines t)

Thus all buffers which don't explicitly have the value of truncate-lines
set will use the default value.


Disclaimer:  All code in this article is untested.

-- 
unsigned *Wayne_Mesard();     "I have to go.  My cat has a hard-on."
MESARD@BBN.COM     
BBN, Cambridge, MA                                       -Patty