all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Emacs-Lisp Q: Minor mode keymap
@ 2007-04-27  1:18 Mark Elston
  2007-04-27  7:25 ` Sebastian Meisel
       [not found] ` <mailman.2580.1177659117.7795.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Mark Elston @ 2007-04-27  1:18 UTC (permalink / raw)
  To: help-gnu-emacs

I have read the relevant chapters (Keymaps and Modes) in the
Emacs Lisp Ref Manual a few times but I am still a little fuzzy
on how to do what I would like to do.  And that is, I have
a collection of Emacs Lisp functions that I have written to
support editing of a particular set of LaTeX files that I am
putting together.  Until now I have either been invoking them
through M-x or binding them with local-set-key whenever I visit
a buffer that I want to use them in.

What I would like to do is package these functions as a minor
mode with its own keymap and use \C-b in the LaTeX-mode-map
used in AucTeX.  Creating the minor mode map is pretty easy.
I assume that from there I do something like:

   (define-prefix-command my-mode-map)

or something similar.

But from there, I don't see what to do.  Do I have to modify my
.emacs to get the binding correct?  Can't I do it in the minor
mode file?

Thanks for any help.

Mark

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

* Re: Emacs-Lisp Q: Minor mode keymap
  2007-04-27  1:18 Emacs-Lisp Q: Minor mode keymap Mark Elston
@ 2007-04-27  7:25 ` Sebastian Meisel
  2007-04-27  7:48   ` Lennart Borgman (gmail)
       [not found] ` <mailman.2580.1177659117.7795.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Sebastian Meisel @ 2007-04-27  7:25 UTC (permalink / raw)
  To: Emacs Mailing List

Mark Elston schrieb:
>
> What I would like to do is package these functions as a minor
> mode with its own keymap and use \C-b in the LaTeX-mode-map
> used in AucTeX.  Creating the minor mode map is pretty easy.
> I assume that from there I do something like:
>
>   (define-prefix-command my-mode-map)
>
> or something similar.
>
> But from there, I don't see what to do.  Do I have to modify my
> .emacs to get the binding correct?  Can't I do it in the minor
> mode file?
Put something like that in your mode file:

(defvar YOUR-mode-map
  (let ((map  (make-sparse-keymap)))
    (define-key map "YOURKEYS"  'YOURFUN)
    ...
   map)
  "Keymap for YOUR-mode.")

(define-YOUR-mode
  "MY mode DOESSOMETHING.
Basic Commands
===== ========
\\[YOURFUN]\tDOESSOMETHING.
...
"
:lighter  "THISSHALLFILLMYENTIREMODELINETOSHOWMYMODEISON"
:keymap  YOUR-mode-map)
<----

Replace the uppercase parts ;-)

Sebastian Meisel

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

* Re: Emacs-Lisp Q: Minor mode keymap
  2007-04-27  7:25 ` Sebastian Meisel
@ 2007-04-27  7:48   ` Lennart Borgman (gmail)
  0 siblings, 0 replies; 5+ messages in thread
From: Lennart Borgman (gmail) @ 2007-04-27  7:48 UTC (permalink / raw)
  To: Sebastian Meisel; +Cc: Emacs Mailing List

Sebastian Meisel wrote:

> (define-YOUR-mode

(define-minor-mode YOUR-mode

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

* Re: Emacs-Lisp Q: Minor mode keymap
       [not found] ` <mailman.2580.1177659117.7795.help-gnu-emacs@gnu.org>
@ 2007-04-27 17:49   ` Mark Elston
  2007-04-27 20:15     ` Mark Elston
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Elston @ 2007-04-27 17:49 UTC (permalink / raw)
  To: help-gnu-emacs

* Sebastian Meisel wrote (on 4/27/2007 12:25 AM):
> Mark Elston schrieb:
>>
>> What I would like to do is package these functions as a minor
>> mode with its own keymap and use \C-b in the LaTeX-mode-map
>> used in AucTeX.  Creating the minor mode map is pretty easy.
>> I assume that from there I do something like:
>>
>>   (define-prefix-command my-mode-map)
>>
>> or something similar.
>>
>> But from there, I don't see what to do.  Do I have to modify my
>> .emacs to get the binding correct?  Can't I do it in the minor
>> mode file?
> Put something like that in your mode file:
> 
> (defvar YOUR-mode-map
>  (let ((map  (make-sparse-keymap)))
>    (define-key map "YOURKEYS"  'YOURFUN)
>    ...
>   map)
>  "Keymap for YOUR-mode.")
> 
> (define-YOUR-mode
>  "MY mode DOESSOMETHING.
> Basic Commands
> ===== ========
> \\[YOURFUN]\tDOESSOMETHING.
> ...
> "
> :lighter  "THISSHALLFILLMYENTIREMODELINETOSHOWMYMODEISON"
> :keymap  YOUR-mode-map)
> <----
> 
> Replace the uppercase parts ;-)

Let me be a little more clear about what I am trying to accomplish.

I understand how to create a keymap and how to use define-minor-mode
to create a mode that makes use of my keymap.

What I wanted to do was to assign my keymap to the \C-b key in the
LaTeX-mode-map in AucTeX.  Is there a way of doing that in my minor
mode package or do I need to add something to my .emacs to accomplish
this?

This is what I have so far but I haven't found a way of getting
what I am looking for yet.

------------------------------------------------------------------------

(defvar bibs-map nil "\
Keymap containing bindings to the Bibs functions.")

(define-prefix-command 'bibs-map)           ;;; <---Is this necessary?

(define-key bs-map "g" 'bibs-get-ref)
(define-key bs-map "v" 'bibs-find-v-num)
(define-key bs-map "f" 'bibs-fix-quotes)

(define-minor-mode bibs-mode
   ""
   ;; Initial Value
   nil
   ;; The indicator for the mode line
   " Bibs"
   ;; The minor mode bindings
   'bs-map
   (...)           ;;; <------ Is there something I can put here
                   ;;; to associate the (unused) \C-b key in AucTeX
                   ;;; LaTeX-mode-map as a prefix key for bibs-map?
   )


------------------------------------------------------------------------

Alternatively, I could (if necessary) put something in my .emacs that
associates bibs-map with the \C-b in LaTeX-mode-map.  I just don't know
how to do that.

Also, when I toggle off bibs-mode it should remove the keymap from the
\C-b prefix key in LaTeX-mode-map, right?  Again, how do I do that?

Mark

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

* Re: Emacs-Lisp Q: Minor mode keymap
  2007-04-27 17:49   ` Mark Elston
@ 2007-04-27 20:15     ` Mark Elston
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Elston @ 2007-04-27 20:15 UTC (permalink / raw)
  To: help-gnu-emacs

Never mind.

I just noticed in abbrev.el the following 2 lines:

     (define-key map "\C-x\C-s" 'edit-abbrevs-redefine)
     (define-key map "\C-c\C-c" 'edit-abbrevs-redefine)

So I changed my define-key calls like so:

   (define-key bibs-map "\C-cbg" 'bibs-get-bible-ref)
   (define-key bibs-map "\C-cbv" 'bibs-find-vrs-num)
   (define-key bibs-map "\C-cbf" 'bibs-fix-quotes)

and it works like I wanted it to.  Simple, really, when
you know the 'trick'.  :)

Mark

* Mark Elston wrote (on 4/27/2007 10:49 AM):
> * Sebastian Meisel wrote (on 4/27/2007 12:25 AM):
>> Mark Elston schrieb:
>>>
>>> What I would like to do is package these functions as a minor
>>> mode with its own keymap and use \C-b in the LaTeX-mode-map
>>> used in AucTeX.  Creating the minor mode map is pretty easy.
>>> I assume that from there I do something like:
>>>
>>>   (define-prefix-command my-mode-map)
>>>
>>> or something similar.
>>>
>>> But from there, I don't see what to do.  Do I have to modify my
>>> .emacs to get the binding correct?  Can't I do it in the minor
>>> mode file?
>> Put something like that in your mode file:
>>
>> (defvar YOUR-mode-map
>>  (let ((map  (make-sparse-keymap)))
>>    (define-key map "YOURKEYS"  'YOURFUN)
>>    ...
>>   map)
>>  "Keymap for YOUR-mode.")
>>
>> (define-YOUR-mode
>>  "MY mode DOESSOMETHING.
>> Basic Commands
>> ===== ========
>> \\[YOURFUN]\tDOESSOMETHING.
>> ...
>> "
>> :lighter  "THISSHALLFILLMYENTIREMODELINETOSHOWMYMODEISON"
>> :keymap  YOUR-mode-map)
>> <----
>>
>> Replace the uppercase parts ;-)
> 
> Let me be a little more clear about what I am trying to accomplish.
> 
> I understand how to create a keymap and how to use define-minor-mode
> to create a mode that makes use of my keymap.
> 
> What I wanted to do was to assign my keymap to the \C-b key in the
> LaTeX-mode-map in AucTeX.  Is there a way of doing that in my minor
> mode package or do I need to add something to my .emacs to accomplish
> this?
> 
> This is what I have so far but I haven't found a way of getting
> what I am looking for yet.
> 
> ------------------------------------------------------------------------
> 
> (defvar bibs-map nil "\
> Keymap containing bindings to the Bibs functions.")
> 
> (define-prefix-command 'bibs-map)           ;;; <---Is this necessary?
> 
> (define-key bs-map "g" 'bibs-get-ref)
> (define-key bs-map "v" 'bibs-find-v-num)
> (define-key bs-map "f" 'bibs-fix-quotes)
> 
> (define-minor-mode bibs-mode
>   ""
>   ;; Initial Value
>   nil
>   ;; The indicator for the mode line
>   " Bibs"
>   ;; The minor mode bindings
>   'bs-map
>   (...)           ;;; <------ Is there something I can put here
>                   ;;; to associate the (unused) \C-b key in AucTeX
>                   ;;; LaTeX-mode-map as a prefix key for bibs-map?
>   )
> 
> 
> ------------------------------------------------------------------------
> 
> Alternatively, I could (if necessary) put something in my .emacs that
> associates bibs-map with the \C-b in LaTeX-mode-map.  I just don't know
> how to do that.
> 
> Also, when I toggle off bibs-mode it should remove the keymap from the
> \C-b prefix key in LaTeX-mode-map, right?  Again, how do I do that?
> 
> Mark

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

end of thread, other threads:[~2007-04-27 20:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-27  1:18 Emacs-Lisp Q: Minor mode keymap Mark Elston
2007-04-27  7:25 ` Sebastian Meisel
2007-04-27  7:48   ` Lennart Borgman (gmail)
     [not found] ` <mailman.2580.1177659117.7795.help-gnu-emacs@gnu.org>
2007-04-27 17:49   ` Mark Elston
2007-04-27 20:15     ` Mark Elston

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.