unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* List of major modes?
@ 2005-11-09  9:40 David Reitter
  2005-11-09 18:02 ` Edward O'Connor
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: David Reitter @ 2005-11-09  9:40 UTC (permalink / raw)


How would I go about compiling a list of all major modes available in  
the current emacs session?
(Both loaded ones and autoloadable ones.)

My first thought was doing something like

  (apropos-internal ".*-mode$")

which works, but doesn't distinguish between major and minor modes,  
which would be important.

I cannot actually run any of the mode functions (would take way too  
long).

 From looking at the elisp level code, there is very little  
programmatic distinction between minor and major modes, at least  
nothing that could be easily detected.

thanks...

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
       [not found] <mailman.14537.1131532545.20277.help-gnu-emacs@gnu.org>
@ 2005-11-09 17:05 ` rgb
  0 siblings, 0 replies; 20+ messages in thread
From: rgb @ 2005-11-09 17:05 UTC (permalink / raw)


>  From looking at the elisp level code, there is very little
> programmatic distinction between minor and major modes

(kill-all-local-variables)

Should be part of major modes but not minor ones.
Derived modes won't contain a kill-all statement.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-09  9:40 David Reitter
@ 2005-11-09 18:02 ` Edward O'Connor
  2005-11-09 19:03 ` Kevin Rodgers
       [not found] ` <mailman.14613.1131563363.20277.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 20+ messages in thread
From: Edward O'Connor @ 2005-11-09 18:02 UTC (permalink / raw)


David Reitter wrote:

> How would I go about compiling a list of all major modes available in
> the current emacs session?

>From my .emacs; originally from Kevin Rodgers:

(defun kr-major-mode-p (symbol)
  "Return non-nil if SYMBOL is a major mode.
Used in `interactive' forms to read major mode names from the user."
  (and (fboundp symbol)
       (let ((function-name (symbol-name symbol)))
         (and (string-match "-mode\\'" function-name)
              (not (string-match "\\`turn-\\(on\\|off\\)-"
                                 function-name))))
       (not (assq symbol minor-mode-alist))))

You could use this together with `mapatoms' to find all major modes.


Ted

-- 
Edward O'Connor
hober0@gmail.com

Ense petit placidam sub libertate quietem.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-09  9:40 David Reitter
  2005-11-09 18:02 ` Edward O'Connor
@ 2005-11-09 19:03 ` Kevin Rodgers
       [not found] ` <mailman.14613.1131563363.20277.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 20+ messages in thread
From: Kevin Rodgers @ 2005-11-09 19:03 UTC (permalink / raw)


David Reitter wrote:
 > How would I go about compiling a list of all major modes available in
 > the current emacs session?
 > (Both loaded ones and autoloadable ones.)
 >
 > My first thought was doing something like
 >
 >  (apropos-internal ".*-mode$")
 >
 > which works, but doesn't distinguish between major and minor modes,
 > which would be important.
 >
 > I cannot actually run any of the mode functions (would take way too 
long).
 >
 >  From looking at the elisp level code, there is very little
 > programmatic distinction between minor and major modes, at least
 > nothing that could be easily detected.

Here's the best I could come up with:

(apropos-internal "-mode\\'"
                   (lambda (mode)
                     (and (commandp mode)
                          (string-match "\\`Major mode\\>"
                                        (documentation mode)))))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
       [not found] ` <mailman.14613.1131563363.20277.help-gnu-emacs@gnu.org>
@ 2005-11-10  1:04   ` rgb
  2005-11-10  1:15     ` Lennart Borgman
       [not found]     ` <mailman.14670.1131585340.20277.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 20+ messages in thread
From: rgb @ 2005-11-10  1:04 UTC (permalink / raw)


> Here's the best I could come up with:
>
> (apropos-internal "-mode\\'"
>                    (lambda (mode)
>                      (and (commandp mode)
>                           (string-match "\\`Major mode\\>"
>                                         (documentation mode)))))

Slick.
It needed a slight tweek on my machine running CVS Emacs.
(documentation mode) would sometimes return nil and blow up
string-match.  tooltip-mode was one that returned nil.  I don't
understand why though.  It does seem to be documented.... hmm.

(apropos-internal "-mode\\'"
                   (lambda (mode)
                     (and (commandp mode) (message "%s" mode)
                          (string-match "\\`Major mode\\>"
                                        (concat "" (documentation
mode))))))

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-10  1:04   ` rgb
@ 2005-11-10  1:15     ` Lennart Borgman
       [not found]     ` <mailman.14670.1131585340.20277.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 20+ messages in thread
From: Lennart Borgman @ 2005-11-10  1:15 UTC (permalink / raw)
  Cc: help-gnu-emacs

rgb wrote:

>>Here's the best I could come up with:
>>
>>(apropos-internal "-mode\\'"
>>                   (lambda (mode)
>>                     (and (commandp mode)
>>                          (string-match "\\`Major mode\\>"
>>                                        (documentation mode)))))
>>    
>>
>
>Slick.
>It needed a slight tweek on my machine running CVS Emacs.
>(documentation mode) would sometimes return nil and blow up
>string-match.  tooltip-mode was one that returned nil.  I don't
>understand why though.  It does seem to be documented.... hmm.
>  
>
C-h f tooltip-mode RET gives a default help string. This actually says 
that tooltip-mode is not documented.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
       [not found]     ` <mailman.14670.1131585340.20277.help-gnu-emacs@gnu.org>
@ 2005-11-10  1:34       ` rgb
  0 siblings, 0 replies; 20+ messages in thread
From: rgb @ 2005-11-10  1:34 UTC (permalink / raw)


> C-h f tooltip-mode RET gives a default help string. This actually says
> that tooltip-mode is not documented.

I was hoping you were right but C-h f tooltip-mode gives me this:

tooltip-mode is an interactive compiled Lisp function in `tooltip.el'.
It is bound to <menu-bar> <options> <showhide> <showhide-tooltip-mode>.
(tooltip-mode &optional arg)

Not documented.

[back]

Popping into tooltip.el shows this:

(define-minor-mode tooltip-mode
  "Toggle Tooltip display.
With ARG, turn tooltip mode on if and only if ARG is positive."
  :global t
...

The reason for the help string not showing up makes me doubt
the reliability of the results returned by Kevin's routine.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
@ 2005-11-11 17:56 David Reitter
  2005-11-11 18:35 ` Henrik Enberg
  0 siblings, 1 reply; 20+ messages in thread
From: David Reitter @ 2005-11-11 17:56 UTC (permalink / raw)
  Cc: Edward O'Connor

>        (not (assq symbol minor-mode-alist))))

Good idea, but unfortunately minor-mode-alist contains stuff to be  
shown in the mode-line, so we're not excluding minor modes that don't  
display anything in the mode line (mouse-wheel-mode for example).

Searching the documentation string (Kevin's idea) won't be reliable,  
obviously.

Looking for (kill-all-local-variables) in the definition would be  
another possibility, but who guarantees that this will occur in the  
mode function definition directly, and not in some function called  
from there.

The only solution I can see is to patch define-minor-mode - as a last  
resort.

- D

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-11 17:56 List of major modes? David Reitter
@ 2005-11-11 18:35 ` Henrik Enberg
  2005-11-11 18:51   ` Drew Adams
  0 siblings, 1 reply; 20+ messages in thread
From: Henrik Enberg @ 2005-11-11 18:35 UTC (permalink / raw)
  Cc: Help-gnu-emacs, hober0

> From: David Reitter <david.reitter@gmail.com>
> Date: Fri, 11 Nov 2005 17:56:14 +0000
> 
> >        (not (assq symbol minor-mode-alist))))
> 
> Good idea, but unfortunately minor-mode-alist contains stuff to be  
> shown in the mode-line, so we're not excluding minor modes that don't  
> display anything in the mode line (mouse-wheel-mode for example).

[...]

> The only solution I can see is to patch define-minor-mode - as a last  
> resort.

Not all minor-modes use define-minor-mode.  One way or another, some
stuff will slip through.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: List of major modes?
  2005-11-11 18:35 ` Henrik Enberg
@ 2005-11-11 18:51   ` Drew Adams
  2005-11-11 19:12     ` Lennart Borgman
  0 siblings, 1 reply; 20+ messages in thread
From: Drew Adams @ 2005-11-11 18:51 UTC (permalink / raw)


    > unfortunately minor-mode-alist contains stuff to be
    > shown in the mode-line, so we're not excluding minor modes
    > that don't display anything in the mode line

    > The only solution I can see is to patch define-minor-mode -
    > as a last resort.

    Not all minor-modes use define-minor-mode.  One way or another, some
    stuff will slip through.

I agree - some stuff will slip through. I don't think you'll find a 100%
solution for excluding minor modes. There is too much overlap between the
conventions of defining major and minor modes, and too many ways to define
each.

Recent Emacs versions have `minor-mode-list' (not alist), a list of all
minor mode functions. There is no guarantee that it will be complete,
however. It is fed by `add-minor-mode'.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-11 18:51   ` Drew Adams
@ 2005-11-11 19:12     ` Lennart Borgman
  2005-11-11 21:51       ` David Reitter
  0 siblings, 1 reply; 20+ messages in thread
From: Lennart Borgman @ 2005-11-11 19:12 UTC (permalink / raw)
  Cc: Help-gnu-emacs, Emacs Devel

Drew Adams wrote:

>Recent Emacs versions have `minor-mode-list' (not alist), a list of all
>minor mode functions. There is no guarantee that it will be complete,
>however. It is fed by `add-minor-mode'.
>  
>
Would it not be best to make something similar for major modes? There 
are some requirements for what major modes should do and why not add a 
new requirement? It will not be very difficult to add it and many users 
would surely like it.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-11 19:12     ` Lennart Borgman
@ 2005-11-11 21:51       ` David Reitter
  2005-11-11 22:18         ` Lennart Borgman
  2005-11-14 16:26         ` Kevin Rodgers
  0 siblings, 2 replies; 20+ messages in thread
From: David Reitter @ 2005-11-11 21:51 UTC (permalink / raw)
  Cc: Help-gnu-emacs, Drew Adams, Emacs Devel

On 11 Nov 2005, at 19:12, Lennart Borgman wrote:

> Drew Adams wrote:
>
>> Recent Emacs versions have `minor-mode-list' (not alist), a list  
>> of all
>> minor mode functions. There is no guarantee that it will be complete,
>> however. It is fed by `add-minor-mode'.
>>
> Would it not be best to make something similar for major modes?  
> There are some requirements for what major modes should do and why  
> not add a new requirement? It will not be very difficult to add it  
> and many users would surely like it.

Changing the conventions for major modes wouldn't work that well,  
since that would basically create an incompatibility.

The following dynamic definition seems to "sort of" work.

(defun major-modes ()
  (apropos-internal "-mode\\'"
    (lambda (mode)
      (and (commandp mode)
	  (not (string-match "\\`turn-\\(on\\|off\\)-"
	  		     (symbol-name mode)))
   	  (not (assq mode minor-mode-list))))))


I don't know, however, whether minor-mode-list is complete, i.e.  
whether it contains the not-yet-auto-loaded minor modes. From what I  
see in easy-mmode.el, it doesn't look like it. 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-11 21:51       ` David Reitter
@ 2005-11-11 22:18         ` Lennart Borgman
  2005-11-14 16:26         ` Kevin Rodgers
  1 sibling, 0 replies; 20+ messages in thread
From: Lennart Borgman @ 2005-11-11 22:18 UTC (permalink / raw)
  Cc: Help-gnu-emacs, Emacs Devel

David Reitter wrote:

> The following dynamic definition seems to "sort of" work.
>
> (defun major-modes ()
>  (apropos-internal "-mode\\'"
>    (lambda (mode)
>      (and (commandp mode)
>       (not (string-match "\\`turn-\\(on\\|off\\)-"
>                    (symbol-name mode)))
>         (not (assq mode minor-mode-list))))))
>
>
> I don't know, however, whether minor-mode-list is complete, i.e.  
> whether it contains the not-yet-auto-loaded minor modes. From what I  
> see in easy-mmode.el, it doesn't look like it.


Maybe I should change my mind. It looks good. If you marry this with the 
code in describe-mode you can perhaps populate minor-mode-list first 
with all minor modes. At least it seems so in that code. (Older minor 
modes seems to be in minor-mode-alist.)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-11 21:51       ` David Reitter
  2005-11-11 22:18         ` Lennart Borgman
@ 2005-11-14 16:26         ` Kevin Rodgers
  2005-11-14 16:40           ` Lennart Borgman
                             ` (2 more replies)
  1 sibling, 3 replies; 20+ messages in thread
From: Kevin Rodgers @ 2005-11-14 16:26 UTC (permalink / raw)
  Cc: help-gnu-emacs

David Reitter wrote:
 > The following dynamic definition seems to "sort of" work.
 >
 > (defun major-modes ()
 >  (apropos-internal "-mode\\'"
 >    (lambda (mode)
 >      (and (commandp mode)
 >       (not (string-match "\\`turn-\\(on\\|off\\)-"
 >                    (symbol-name mode)))
 >         (not (assq mode minor-mode-list))))))
 >
 >
 > I don't know, however, whether minor-mode-list is complete, i.e.
 > whether it contains the not-yet-auto-loaded minor modes. From what I
 > see in easy-mmode.el, it doesn't look like it.

I still think it would be better to include functions that follow the
major mode conventions than to exclude functions that don't follow the
minor mode conventions.  The Emacs Lisp manual has nodes describing both
sets of conventions.

For example:

    * The major mode should usually have its own keymap, which is used
      as the local keymap in all buffers in that mode.  The major mode
      command should call `use-local-map' to install this local map.
      *Note Active Keymaps::, for more information.

      This keymap should be stored permanently in a global variable named
      `MODENAME-mode-map'.  Normally the library that defines the mode
      sets this variable.

So you could check (keymapp (intern-soft (concat mode "-map"))) in the
apropos-internal PREDICATE.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-14 16:26         ` Kevin Rodgers
@ 2005-11-14 16:40           ` Lennart Borgman
  2005-11-14 19:32             ` Stefan Monnier
  2005-11-15  5:43           ` Richard M. Stallman
  2005-11-15 10:22           ` Alan Mackenzie
  2 siblings, 1 reply; 20+ messages in thread
From: Lennart Borgman @ 2005-11-14 16:40 UTC (permalink / raw)
  Cc: help-gnu-emacs, emacs-devel

Kevin Rodgers wrote:

>
> For example:
>
>    * The major mode should usually have its own keymap, which is used
>      as the local keymap in all buffers in that mode.  The major mode
>      command should call `use-local-map' to install this local map.
>      *Note Active Keymaps::, for more information.
>
>      This keymap should be stored permanently in a global variable named
>      `MODENAME-mode-map'.  Normally the library that defines the mode
>      sets this variable.
>
> So you could check (keymapp (intern-soft (concat mode "-map"))) in the
> apropos-internal PREDICATE.
>
What about autoloading?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-14 16:40           ` Lennart Borgman
@ 2005-11-14 19:32             ` Stefan Monnier
  0 siblings, 0 replies; 20+ messages in thread
From: Stefan Monnier @ 2005-11-14 19:32 UTC (permalink / raw)
  Cc: Kevin Rodgers, help-gnu-emacs, emacs-devel

>> * The major mode should usually have its own keymap, which is used
>> as the local keymap in all buffers in that mode.  The major mode
>> command should call `use-local-map' to install this local map.
>> *Note Active Keymaps::, for more information.
>> 
>> This keymap should be stored permanently in a global variable named
>> `MODENAME-mode-map'.  Normally the library that defines the mode
>> sets this variable.
>> 
>> So you could check (keymapp (intern-soft (concat mode "-map"))) in the
>> apropos-internal PREDICATE.
>> 
> What about autoloading?

Indeed, it's very difficult to tell the difference between an autoloaded
major mode and some other autoloaded function whose name ends in `-mode'.

If the autoload is complete (i.e. generated by a recent autoload.el), then
it'll include the arg list, in which case we can check whether the arglist
is empty (as the convention says).

This said, I'm still not sure why you'd want a list of major modes.


        Stefan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-14 16:26         ` Kevin Rodgers
  2005-11-14 16:40           ` Lennart Borgman
@ 2005-11-15  5:43           ` Richard M. Stallman
  2005-11-15 10:22           ` Alan Mackenzie
  2 siblings, 0 replies; 20+ messages in thread
From: Richard M. Stallman @ 2005-11-15  5:43 UTC (permalink / raw)
  Cc: help-gnu-emacs, emacs-devel

It is not correct to assume that every major mode has a keymap named
after it.  However, major mode commands take no arguments, whereas
every minor mode command takes an argument.  There may be one or two
exceptions, major mode commands that take arguments, but it would be
easy to put them on a list of exceptions.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-14 16:26         ` Kevin Rodgers
  2005-11-14 16:40           ` Lennart Borgman
  2005-11-15  5:43           ` Richard M. Stallman
@ 2005-11-15 10:22           ` Alan Mackenzie
  2005-11-15 18:21             ` Kevin Rodgers
  2005-11-15 23:22             ` Richard M. Stallman
  2 siblings, 2 replies; 20+ messages in thread
From: Alan Mackenzie @ 2005-11-15 10:22 UTC (permalink / raw)
  Cc: help-gnu-emacs, emacs-devel



On Mon, 14 Nov 2005, Kevin Rodgers wrote:

>David Reitter wrote:
> > The following dynamic definition seems to "sort of" work.

> > (defun major-modes ()
> >  (apropos-internal "-mode\\'"
> >    (lambda (mode)
> >      (and (commandp mode)
> >       (not (string-match "\\`turn-\\(on\\|off\\)-"
> >                    (symbol-name mode)))
> >         (not (assq mode minor-mode-list))))))


> > I don't know, however, whether minor-mode-list is complete, i.e.
> > whether it contains the not-yet-auto-loaded minor modes. From what I
> > see in easy-mmode.el, it doesn't look like it.

>I still think it would be better to include functions that follow the
>major mode conventions than to exclude functions that don't follow the
>minor mode conventions.  The Emacs Lisp manual has nodes describing both
>sets of conventions.

It is impossible to create a list of major modes, because a major mode is
simply a lisp function, with nothing definitive to distinguish it from
any other lisp function.

So how about having a property `emacs-mode' on symbols, with valid values
(major minor major-minor nil)?  Getting a list of major modes would then
be trivial.  (OK, for Emacs 23. ;-)

>-- 
>Kevin Rodgers

-- 
Alan Mackenzie (Munich, Germany)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-15 10:22           ` Alan Mackenzie
@ 2005-11-15 18:21             ` Kevin Rodgers
  2005-11-15 23:22             ` Richard M. Stallman
  1 sibling, 0 replies; 20+ messages in thread
From: Kevin Rodgers @ 2005-11-15 18:21 UTC (permalink / raw)
  Cc: emacs-devel

Alan Mackenzie wrote:
 > On Mon, 14 Nov 2005, Kevin Rodgers wrote:
 > > I still think it would be better to include functions that follow the
 > > major mode conventions than to exclude functions that don't follow the
 > > minor mode conventions.  The Emacs Lisp manual has nodes describing 
both
 > > sets of conventions.
 >
 > It is impossible to create a list of major modes, because a major mode is
 > simply a lisp function, with nothing definitive to distinguish it from
 > any other lisp function.

Yes.  We have been discussing heuristics that could be used in the
absence of a definitive test.

 > So how about having a property `emacs-mode' on symbols, with valid values
 > (major minor major-minor nil)?  Getting a list of major modes would then
 > be trivial.  (OK, for Emacs 23. ;-)

Did you mean (major minor global-minor nil)?

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: List of major modes?
  2005-11-15 10:22           ` Alan Mackenzie
  2005-11-15 18:21             ` Kevin Rodgers
@ 2005-11-15 23:22             ` Richard M. Stallman
  1 sibling, 0 replies; 20+ messages in thread
From: Richard M. Stallman @ 2005-11-15 23:22 UTC (permalink / raw)
  Cc: ihs_4664, help-gnu-emacs, emacs-devel

    So how about having a property `emacs-mode' on symbols, with valid values
    (major minor major-minor nil)?  Getting a list of major modes would then
    be trivial.  (OK, for Emacs 23. ;-)

That is straightforward, but it would be substantial trouble.
Is it worth the trouble?

What benefit would it provide?  What was the reason for asking
for this?

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2005-11-15 23:22 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-11 17:56 List of major modes? David Reitter
2005-11-11 18:35 ` Henrik Enberg
2005-11-11 18:51   ` Drew Adams
2005-11-11 19:12     ` Lennart Borgman
2005-11-11 21:51       ` David Reitter
2005-11-11 22:18         ` Lennart Borgman
2005-11-14 16:26         ` Kevin Rodgers
2005-11-14 16:40           ` Lennart Borgman
2005-11-14 19:32             ` Stefan Monnier
2005-11-15  5:43           ` Richard M. Stallman
2005-11-15 10:22           ` Alan Mackenzie
2005-11-15 18:21             ` Kevin Rodgers
2005-11-15 23:22             ` Richard M. Stallman
     [not found] <mailman.14537.1131532545.20277.help-gnu-emacs@gnu.org>
2005-11-09 17:05 ` rgb
  -- strict thread matches above, loose matches on Subject: below --
2005-11-09  9:40 David Reitter
2005-11-09 18:02 ` Edward O'Connor
2005-11-09 19:03 ` Kevin Rodgers
     [not found] ` <mailman.14613.1131563363.20277.help-gnu-emacs@gnu.org>
2005-11-10  1:04   ` rgb
2005-11-10  1:15     ` Lennart Borgman
     [not found]     ` <mailman.14670.1131585340.20277.help-gnu-emacs@gnu.org>
2005-11-10  1:34       ` rgb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).