[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cc-mode adds newlines

From: Stefan Monnier
Subject: Re: cc-mode adds newlines
Date: Mon, 22 Nov 2004 15:06:20 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

> I agree, but I would like to see it implemented outside of customize.
> Custom would of course provide an interface to it, but wouldn't be the
> only way to specify a mode-specific value.

I think `add-hook' is perfectly fine for non-custom uses.
People have used it for years without any problems.

> (put 'require-final-newline 'c-mode t)

> would be equivalent to

> (add-hook 'c-mode-hook
>         (lambda ()
>           (set (make-local-variable 'require-final-newline) t))

I recommend

   (defun my-c-mode-hook ()
     (set (make-local-variable 'require-final-newline) t))
   (add-hook 'c-mode-hook 'my-c-mode-hook)

It's better behaved when you reload your .emacs.

If you think the above is too scary, we can provide functions/macros to make
it less so.  E.g. a macro `setq-local'.

> Ah, we're talking about almost exactly the same thing.  You've collected
> all the mode-specific values into an association list keyed by the mode
> symbol, and put that on the variable's custom-per-mode property; whereas
> I put each value on a separate property.

I actually dislike this property in my sample code because it duplicate
some info.  A better way would be to hard-code the result of `assq'
inthe definition of the functions we put on the hooks, and then in
custom-get-per-mode we'd rebuild the alist by looking at the hooks and
extracting the value from the body of the function.  But that's pretty ugly.

The reason for doing that would be that if a user does
(remove-hook 'foo-mode-hook 'custom-set-foo-some-var) it should properly
update the corresponding value returned by custom-get-per-mode.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]