[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re[2]: Multiple major modes
From: |
Eric M. Ludlam |
Subject: |
Re[2]: Multiple major modes |
Date: |
Sun, 8 Jul 2007 20:49:41 -0400 |
>>> Richard Stallman <address@hidden> seems to think that:
> The use syntax of an overloadable function is similar to programs that
> call `indent-for-tab-command', or `indent-according-to-mode', but
> there is no restriction forcing `according-to-mode' as part of the
> function name.
>
>I understand the similarity, but I see the difference too.
>The source code of `indent-according-to-mode' shows that it
>calls something that can be set differently by different modes.
>
>That's why I prefer using a variable.
>
>However, you didn't show precisely what this feature looks like.
>Perhaps I got the wrong idea of the feature. Can you show me
>what it looks like?
Hi,
Here is a use case from semantic, my parsing tool. This is a
function that would take a name as found in sources, and split it so
that namespaces (if any) and the name are returned. In many
languages there is nothing special to do, but in C++, it needs to do
something special. Instead of putting c++ code in the first file, it
is instead placed in a C specific file that contains many C specific
differences. Of course, the doc string talks about C++, but only as
an example.
I picked this case because it's very short.
semantic-analyze.el:
--------------------
(define-overload semantic-analyze-split-name (name)
"Split a tag NAME into a sequence.
Sometimes NAMES are gathered from the parser that are compounded,
such as in C++ where foo::bar means:
\"The class BAR in the namespace FOO.\"
Return the string NAME for no change, or a list if it needs to be split.")
(defun semantic-analyze-split-name-default (name)
"Don't split up NAME by default."
name)
--------------------
As you can see, there is no implementation at the initial
declaration. In this example, the `-default' is a separate function,
because a body could be given to the original that would wrap either
the `-default' of a mode specific implementation.
semantic-c.el:
--------------
(define-mode-local-override semantic-analyze-split-name c-mode (name)
"Split up tag names on colon (:) boundaries."
(let ((ans (split-string name ":")))
(if (= (length ans) 1)
name
(delete "" ans))))
--------------
If you use "C-h f semantic-analyze-split-name RET" you get:
---------------
semantic-analyze-split-name is a compiled Lisp function in
`semantic-analyze.el'.
(semantic-analyze-split-name name)
This function can be overloaded (see `define-mode-local-override' for details).
Split a tag name into a sequence.
Sometimes NAMES are gathered from the parser that are compounded,
such as in C++ where foo::bar means:
"The class BAR in the namespace FOO."
Return the string name for no change, or a list if it needs to be split.
[back]
---------------
which would be improved if the doc for individual overloads could be
specified, though I haven't done that yet. Doing so would make it
much easier to find the implementation actually being run in a
particular case.
I hope this helps.
Eric
--
Eric Ludlam: address@hidden, address@hidden
Home: http://www.ludlam.net Siege: www.siege-engine.com
Emacs: http://cedet.sourceforge.net GNU: www.gnu.org
- Re: Multiple major modes, (continued)
- Re: Multiple major modes, Stefan Monnier, 2007/07/06
- RE: Multiple major modes, Drew Adams, 2007/07/06
- Re: Multiple major modes, Richard Stallman, 2007/07/07
- Re: Multiple major modes, Stephen J. Turnbull, 2007/07/07
- Re: Multiple major modes, Richard Stallman, 2007/07/08
- Re: Multiple major modes, Stephen J. Turnbull, 2007/07/09
- Re: Multiple major modes, Richard Stallman, 2007/07/09
- Re: Multiple major modes, Johan Bockgård, 2007/07/06
Re[2]: Multiple major modes, Eric M. Ludlam, 2007/07/04
Re: Multiple major modes, Richard Stallman, 2007/07/01