[Top][All Lists]

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

Re: Bugs caused by recent use of define-derived-mode

From: Stefan Monnier
Subject: Re: Bugs caused by recent use of define-derived-mode
Date: Mon, 02 Sep 2002 12:29:34 -0400

> There are two types of bugs related to define-derived-mode and its
> recent increased use, including uses for purposes it was not
> originally intended for.  The two types of bugs have similar symptoms,
> but different causes.  Both can easily be fixed, but the best way to
> fix the second one depends on some more general questions.  (Actually
> there are three kinds of bugs, but fixing the first automatically
> fixes the third.)
> To investigate these types of bug, I believe one has to start by
> temporarily "hiding" one's .abbrev_defs from emacs, for instance by
> temporarily renaming it.  Then do emacs-21.3.50 -q.  (The bugs do not
> occur in 21.2.90 or earlier versions.)  They are caused by recent new
> uses of define-derived-mode in emacs21.3.50.
> Do M-x list-abbrevs.
> What is paragraph-indent-text-mode-abbrev-table doing in this list?

Could please state clearly what are the bugs ?
I.e. a set of commands that shows a behavior you didn't expect ?

> It is not there in 21.2.90.

So what ?

> How could the expansion of an abbrev
> possibly depend on the details of paragraph indentation?  This is an
> example of the first type of bugs.

The only problem with it is that if you change text-mod-abbrev-table, it
will not be immediately propagated to paragraph-indent-text-mode-abbrev-table
because we don't have inheritance of abbrev-tables, so define-derived-mode
only simulates it by copying the abbrev-table of the parent.

> Now a new abbrev-table has appeared, mail-mode-abbrev-table.  There is
> no such abbrev-table.  Mail-mode uses the text-mode-abbrev-table.  Yet

That's a bug in mail-mode, then.  See appended patch.

> There is no way for the user to find out that the senseless
> paragraph-indent-text-mode-abbrev-table is "real" and the
> mail-mode-abbrev-table (which actually would make at least slightly
> more sense, though not enough) is a "fake", other than to read the
> source code or to start experimenting.

There is no fake abbrev-table.  It's just a bug.

> The user also has no way of
> knowing that abbrevs defined in the regular text-mode-abbrev-table may
> or may not expand in paragraph-indent-text-mode, depending on whether
> some other buffer using paragraph-indent-text-mode was created in the
> meantime or not.  (This dependency is clearly in itself yet another,
> third bug.)

That is a more serious problem, as mentioned earlier:
abbrev-tables should be able to inherit from each other.

> The second type of bugs could potentially also create similar problems
> for syntax-tables, because, with respect to this kind of bug, the code
> for syntax-tables is broken in exactly the same way as the one for
> abbrevs.  (See a later message.)  The first and third bugs are
> abbrev-specific.

Not at all.  Syntax-tables provide real inheritance (just like keymaps)
and thus do not suffer from the same problems.  Of course, there might
still be problems, but then I'd welcome a real bug-report.

> nearly identical.  Mail mode is about as far removed from text mode as
> any truly derived mode is going to be and it, correctly, uses the
> same abbrev table as text mode.

I'm not sure it's correct.  There has already been people on gnu.emacs.help
asking why they can't define abbrevs that are specific to their mail buffers.

> Instead of trying to copy the parent mode's abbrev-table (and
> producing bugs in the process) define-derived-mode should simply make
> the derived mode use the parent's abbrev-table.  This is trivial to
> do, it actually simplifies the current code.

We could do that indeed.  I don't have a preference either way, as long
as it's easy for the code-author to choose whether to create a new
abbrev-table or to use the parent's (it's pretty easy right now (see patch)
but it is biased towards creating new abbrev-tables).


--- sendmail.el.~1.256.~        Tue May 21 19:43:31 2002
+++ sendmail.el Mon Sep  2 12:22:47 2002
@@ -473,6 +473,7 @@
   :type 'hook
   :options '(footnote-mode))
+(defvar mail-mode-abbrev-table text-mode-abbrev-table)
 (define-derived-mode mail-mode text-mode "Mail"
   "Major mode for editing mail to be sent.
@@ -489,7 +490,6 @@
 \\[mail-sent-via]  mail-sent-via (add a Sent-via field for each To or CC).
 Turning on Mail mode runs the normal hooks `text-mode-hook' and
 `mail-mode-hook' (in that order)."
-  (setq local-abbrev-table text-mode-abbrev-table)
   (make-local-variable 'mail-reply-action)
   (make-local-variable 'mail-send-actions)
   (setq buffer-offer-save t)

reply via email to

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