unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Query Major Mode
@ 2005-07-21 18:33 Tim Johnson
  2005-07-21 18:45 ` Drew Adams
  2005-07-21 18:45 ` Peter Dyballa
  0 siblings, 2 replies; 10+ messages in thread
From: Tim Johnson @ 2005-07-21 18:33 UTC (permalink / raw)


Is there a way to query the major mode for a buffer?
Pointers to docs should suffice.
thnx
tj

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

* RE: Query Major Mode
  2005-07-21 18:33 Query Major Mode Tim Johnson
@ 2005-07-21 18:45 ` Drew Adams
  2005-07-21 19:32   ` Tim Johnson
       [not found]   ` <mailman.1216.1121974434.20277.help-gnu-emacs@gnu.org>
  2005-07-21 18:45 ` Peter Dyballa
  1 sibling, 2 replies; 10+ messages in thread
From: Drew Adams @ 2005-07-21 18:45 UTC (permalink / raw)


    Is there a way to query the major mode for a buffer?

There are lots of ways, depending on what you mean by query.  Does `C-h m'
do what you want?

    Pointers to docs should suffice.

`C-h i' Emacs

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

* Re: Query Major Mode
  2005-07-21 18:33 Query Major Mode Tim Johnson
  2005-07-21 18:45 ` Drew Adams
@ 2005-07-21 18:45 ` Peter Dyballa
  1 sibling, 0 replies; 10+ messages in thread
From: Peter Dyballa @ 2005-07-21 18:45 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 21.07.2005 um 20:33 schrieb Tim Johnson:

> Is there a way to query the major mode for a buffer?
>

C-h m or describe-mode.

--
Greetings

   Pete

   It's not the valleys in life I dread so much as the dips.
		-- 	Garfield

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

* Re: Query Major Mode
  2005-07-21 18:45 ` Drew Adams
@ 2005-07-21 19:32   ` Tim Johnson
  2005-07-21 19:46     ` Peter Dyballa
                       ` (2 more replies)
       [not found]   ` <mailman.1216.1121974434.20277.help-gnu-emacs@gnu.org>
  1 sibling, 3 replies; 10+ messages in thread
From: Tim Johnson @ 2005-07-21 19:32 UTC (permalink / raw)


> There are lots of ways, depending on what you mean by query.  Does `C-h m'
> do what you want?
 
  Oops! Poorly phrased question. My apologies. What I would like to
  do is perform this query programmatically. 

  Is that possible?

  Now perhaps I should elaborate in case I am barking up the wrong
  tree and there is a better way:

  Let's suppose I want to write a subroutine that first, queries
  the major mode, and then calls the appropriate subroutine for
  the mode.

  *pseudo-code* example:

(defun previous-subroutine ()
  (cond
    (eq major-mode "python")(previous-python-subroutine)
    (eq major-mode "C")(previous-C-subroutine)
    (eq major-mode "rebol")(previous-rebol-subroutine)
  ))

  ;; and then keymap of course.

  thanks
  tim

>     Pointers to docs should suffice.
> 
> `C-h i' Emacs
> 
> 
> 
> _______________________________________________
> Help-gnu-emacs mailing list
> Help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

* Re: Query Major Mode
  2005-07-21 19:32   ` Tim Johnson
@ 2005-07-21 19:46     ` Peter Dyballa
  2005-07-21 20:03       ` Tim Johnson
  2005-07-21 19:58     ` Drew Adams
  2005-07-21 22:55     ` Kevin Rodgers
  2 siblings, 1 reply; 10+ messages in thread
From: Peter Dyballa @ 2005-07-21 19:46 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 21.07.2005 um 21:32 schrieb Tim Johnson:

>   Oops! Poorly phrased question. My apologies. What I would like to
>   do is perform this query programmatically.
>
>   Is that possible?
>

Describe-mode returns a lot of text, listing all minor-modes too. Then 
there is the mode-line -- and it uses a variable `mode-name´ -- I think 
that's it!

--
Greetings

   Pete

                   Sorry my terrible English, my native language Lisp!

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

* RE: Query Major Mode
  2005-07-21 19:32   ` Tim Johnson
  2005-07-21 19:46     ` Peter Dyballa
@ 2005-07-21 19:58     ` Drew Adams
  2005-07-21 22:55     ` Kevin Rodgers
  2 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2005-07-21 19:58 UTC (permalink / raw)


      Let's suppose I want to write a subroutine that first, queries
      the major mode, and then calls the appropriate subroutine for
      the mode. *pseudo-code* example:

    (defun previous-subroutine ()
      (cond
        (eq major-mode "python")(previous-python-subroutine)
        (eq major-mode "C")(previous-C-subroutine)
        (eq major-mode "rebol")(previous-rebol-subroutine)
      ))

Wrap your conditions in parens, define your `previous-*' routines, and you
should be more or less good to go.

IOW, you query the major mode programmatically via variable `major-mode',
just as you have done - it's not pseudocode; it's code.

`M-x apropos RET major' shows you variable `major-mode'.

See node "Major Modes" in the Elisp manual (info: `C-h i') for lots of info
on major modes. (I wonder why they picked that name for the node?)

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

* Re: Query Major Mode
  2005-07-21 19:46     ` Peter Dyballa
@ 2005-07-21 20:03       ` Tim Johnson
  0 siblings, 0 replies; 10+ messages in thread
From: Tim Johnson @ 2005-07-21 20:03 UTC (permalink / raw)


* Peter Dyballa <Peter_Dyballa@Web.DE> [050721 11:48]:
> 
> Am 21.07.2005 um 21:32 schrieb Tim Johnson:
> 
> >  Oops! Poorly phrased question. My apologies. What I would like to
> >  do is perform this query programmatically.
> >
> >  Is that possible?
> >
> 
> Describe-mode returns a lot of text, listing all minor-modes too. Then 
> there is the mode-line -- and it uses a variable `mode-name´ -- I think 
> that's it!
 
  Hi Peter:

    <grin> That's too easy.
    thanks

  tim
  
> --
> Greetings
> 
>   Pete
> 
>                   Sorry my terrible English, my native language Lisp!
> 

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

* Re: Query Major Mode
  2005-07-21 19:32   ` Tim Johnson
  2005-07-21 19:46     ` Peter Dyballa
  2005-07-21 19:58     ` Drew Adams
@ 2005-07-21 22:55     ` Kevin Rodgers
  2 siblings, 0 replies; 10+ messages in thread
From: Kevin Rodgers @ 2005-07-21 22:55 UTC (permalink / raw)


Tim Johnson wrote:
> (defun previous-subroutine ()
>   (cond
>     (eq major-mode "python")(previous-python-subroutine)
>     (eq major-mode "C")(previous-C-subroutine)
>     (eq major-mode "rebol")(previous-rebol-subroutine)
>   ))

The value of major-mode is a symbol, e.g. python-mode.

The value of mode-name is a string, e.g. "Python".

-- 
Kevin Rodgers

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

* Re: Query Major Mode
       [not found]   ` <mailman.1216.1121974434.20277.help-gnu-emacs@gnu.org>
@ 2005-07-21 22:59     ` drkm
  2005-07-22  5:51     ` Tim X
  1 sibling, 0 replies; 10+ messages in thread
From: drkm @ 2005-07-21 22:59 UTC (permalink / raw)


Tim Johnson writes:

> (defun previous-subroutine ()
>   (cond
>     (eq major-mode "python")(previous-python-subroutine)
>     (eq major-mode "C")(previous-C-subroutine)
>     (eq major-mode "rebol")(previous-rebol-subroutine)
>   ))

  You can also use something like:

    (defvar previous-subroutine-function 'previous-subroutine-default
      "...")
    (make-variable-buffer-local 'previous-subroutine-function)

    (defun previous-subroutine ()
      "..."
      (funcall previous-subroutine-function ...))

    (defun previous-python-subroutine ()
      ...)
    (add-hook 'python-mode-hook (lambda ()
                                  (setq previous-subroutine-function
                                        previous-python-subroutine)))

    ;; ...

  You can be interested in the mechanism CEDET provides to
overload functions in a per-mode basis.  Cfr. the documentation:
(info "(semantic-langdev)Semantic Overload Mechanism").

--drkm

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

* Re: Query Major Mode
       [not found]   ` <mailman.1216.1121974434.20277.help-gnu-emacs@gnu.org>
  2005-07-21 22:59     ` drkm
@ 2005-07-22  5:51     ` Tim X
  1 sibling, 0 replies; 10+ messages in thread
From: Tim X @ 2005-07-22  5:51 UTC (permalink / raw)


Tim Johnson <tim@johnsons-web.com> writes:

> > There are lots of ways, depending on what you mean by query.  Does `C-h m'
> > do what you want?
>  
>   Oops! Poorly phrased question. My apologies. What I would like to
>   do is perform this query programmatically. 
> 
>   Is that possible?
> 
>   Now perhaps I should elaborate in case I am barking up the wrong
>   tree and there is a better way:
> 
>   Let's suppose I want to write a subroutine that first, queries
>   the major mode, and then calls the appropriate subroutine for
>   the mode.
> 
>   *pseudo-code* example:
> 
> (defun previous-subroutine ()
>   (cond
>     (eq major-mode "python")(previous-python-subroutine)
>     (eq major-mode "C")(previous-C-subroutine)
>     (eq major-mode "rebol")(previous-rebol-subroutine)
>   ))
> 
>   ;; and then keymap of course.
> 

You pseudo code pretty much has all the elements you need - there is a
variable called major-mode which you can use to do something based on
the mode you are in. However, I would suggest you check out using mode
hooks instead. Nearly all modes have a 'hook' you can set to do things
in a mode when it is loaded - this is the normal place to put mode
specific customizations. Many modes have multiple hooks that are run
at different times e.g. before loading the mode code, after loadinig
it etc. 

Tim


-- 
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you 
really need to send mail, you should be able to work it out!

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

end of thread, other threads:[~2005-07-22  5:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-21 18:33 Query Major Mode Tim Johnson
2005-07-21 18:45 ` Drew Adams
2005-07-21 19:32   ` Tim Johnson
2005-07-21 19:46     ` Peter Dyballa
2005-07-21 20:03       ` Tim Johnson
2005-07-21 19:58     ` Drew Adams
2005-07-21 22:55     ` Kevin Rodgers
     [not found]   ` <mailman.1216.1121974434.20277.help-gnu-emacs@gnu.org>
2005-07-21 22:59     ` drkm
2005-07-22  5:51     ` Tim X
2005-07-21 18:45 ` Peter Dyballa

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).