[Top][All Lists]

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

Re: comint-carriage-motion causes severe problems.

From: Luc Teirlinck
Subject: Re: comint-carriage-motion causes severe problems.
Date: Wed, 3 Jul 2002 20:18:55 -0500 (CDT)

Stefan Monnier wrote:

   Actually, there are some unclear semantics when you do things like

           (add-hook 'foo 'bar)
           (add-hook 'foo 'bar nil 'local)
           (remove-hook 'foo 'bar 'local)

   The current code removes `bar' from the local value of `foo' but
   leaves it in the global one.  My new code does the same and only a second
   (remove-hook 'foo 'bar 'local) will add a (not . bar) such that the
   global setting is overridden.  This decision was arbitrary (mostly
   trying to minimize the change in behavior for better compatibility).

I believe that in the given situation it is actually the only choice.
If bar occurs in both the global and the local value it will get
executed twice each time foo is ran.  This is very likely to be
unintended.  The user should be able to correct the situation with a

(remove-hook 'foo 'bar 'local)

rather than still having to re-add it to the global value.

However, I now believe that there is an even better solution which not
only removes the arbitrariness in the above example, but moreover
removes any danger of breaking existing code, which otherwise seems
to be a very real danger, and which also adds useful flexibility.

Indeed, I now start to get really weary about breaking existing code
where people rely on the fact that remove-hook "does no harm anyway"
if bar is not in the local value of foo and hence it does not matter

(remove-hook 'foo 'bar 'local) 

is executed several times if a file is accidentally loaded more than

I am starting to believe that it might be good to keep the present
behavior of remove-hook, unless the third argument is the symbol
'override, in which case it would override any function later in the
hook, including global functions.


(remove 'foo 'bar 'local) completely keeps the present behavior:

remove from local value if bar is in the local value.  Do nothing
otherwise.  Same if 'local is replaced by t or any value other than
nil or override.

(remove 'foo 'bar 'override) overrides any other occurrences of bar
further down the list, local or global.

Depending on peoples' style, current code may contain third non-nil
arguments of t or 'local, as you use, but I can not possibly see how
people would have used a third argument 'override anywhere.  (Unless
they were actually anticipating your code.)  Hence, all worries about
breaking existing code would be gone, the worry about arbitrariness in
cases of the type you describe is gone, the worry about bad things
happening if files get accidentally loaded more than once is totally
gone and we have, moreover, better flexibility.


Luc Teirlinck.

reply via email to

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