* How to get current keymap
@ 2008-12-06 14:37 netawater
2008-12-06 18:24 ` Xah Lee
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: netawater @ 2008-12-06 14:37 UTC (permalink / raw)
To: help-gnu-emacs
I used (concat (symbol-name major-mode) "-map") to get current keymap, but it
failed for LaTeX mode. Are there other methode to get current keymap. Thank you
very much!.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get current keymap
2008-12-06 14:37 How to get current keymap netawater
@ 2008-12-06 18:24 ` Xah Lee
2008-12-06 21:37 ` Rupert Swarbrick
2008-12-07 6:49 ` Drew Adams
2 siblings, 0 replies; 9+ messages in thread
From: Xah Lee @ 2008-12-06 18:24 UTC (permalink / raw)
To: help-gnu-emacs
On Dec 6, 6:37 am, netawater <netstandin-...@yahoo.com.cn> wrote:
> I used (concat (symbol-name major-mode) "-map") to get current keymap, but it
> failed for LaTeX mode. Are there other methode to get current keymap. Thank you
> very much!.
there are these:
current-active-maps
Function: Return a list of the currently active keymaps.
current-global-map
Function: Return the current global keymap.
current-local-map
Function: Return current buffer's local keymap, or nil if it has
none.
current-minor-mode-maps
Function: Return a list of keymaps for the minor modes of the
current buffer.
these are gotten by “Ctrl+u Ctrl+h a -maps”. In short, give a empty
arg to apropos-command then look for function names ending in “-maps”.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get current keymap
2008-12-06 14:37 How to get current keymap netawater
2008-12-06 18:24 ` Xah Lee
@ 2008-12-06 21:37 ` Rupert Swarbrick
2008-12-07 5:28 ` netawater
2008-12-07 6:49 ` Drew Adams
2 siblings, 1 reply; 9+ messages in thread
From: Rupert Swarbrick @ 2008-12-06 21:37 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
netawater <netstandin-003@yahoo.com.cn> writes:
> I used (concat (symbol-name major-mode) "-map") to get current keymap,
> but it failed for LaTeX mode. Are there other methode to get current
> keymap. Thank you very much!.
Maybe (current-active-maps) does what you need? See
(info "(elisp) Active Keymaps")
Rupert
[-- Attachment #2: Type: application/pgp-signature, Size: 314 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get current keymap
2008-12-06 21:37 ` Rupert Swarbrick
@ 2008-12-07 5:28 ` netawater
2008-12-07 6:35 ` Drew Adams
0 siblings, 1 reply; 9+ messages in thread
From: netawater @ 2008-12-07 5:28 UTC (permalink / raw)
To: help-gnu-emacs
Rupert Swarbrick <rswarbrick@gmail.com> writes:
> netawater <netstandin-003@yahoo.com.cn> writes:
>
>> I used (concat (symbol-name major-mode) "-map") to get current keymap,
>> but it failed for LaTeX mode. Are there other methode to get current
>> keymap. Thank you very much!.
>
> Maybe (current-active-maps) does what you need? See
>
> (info "(elisp) Active Keymaps")
>
>
> Rupert
Thank you both.
I'm very sorry my description is not accurate, :(.
I want to get current mode's keymap, some modes do not have keymap, but current
keymap always exists. I need define a key for my function in it and my function
can be always active for that mode.
Thank you very much for replying.
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: How to get current keymap
2008-12-07 5:28 ` netawater
@ 2008-12-07 6:35 ` Drew Adams
0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2008-12-07 6:35 UTC (permalink / raw)
To: 'netawater', help-gnu-emacs
> I want to get current mode's keymap, some modes do not have
> keymap, but current keymap always exists. I need define a
> key for my function in it and my function
> can be always active for that mode.
If you want to define a key for only a specific (major or minor) mode, then use
that mode's keymap.
If that mode doesn't have a keymap, then it is less straightforward to define a
key for only that mode. You can define a key in some map that is accessible from
that keymap, so the key will be active in that mode, but then that key binding
will also hold outside that mode - unless you take pains to bind and unbind the
key when, say, the mode is entered and exited.
To see all maps accessible currently, you can use functions
`current-active-maps' and `accessible-keymaps'. See the Elisp manual, nodes
Active Keymaps and Scanning Keymaps.
Remember that there are several levels of priority for keymaps: minor mode maps
(in order), then (major mode) local map, then global map (and there are some
more levels). If you define a key in a local map, it's possible it gets shadowed
by a minor-mode binding.
To make sense of what's happening, before you try to bind a key examine the
existing bindings in the current minor modes and major mode, as well as the
global bindings. Command `describe-keymap' (bound to `C-h M-k') in library
help-fns+.el shows you the bindings for a given map.
http://www.emacswiki.org/emacs/HelpPlus
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: How to get current keymap
2008-12-06 14:37 How to get current keymap netawater
2008-12-06 18:24 ` Xah Lee
2008-12-06 21:37 ` Rupert Swarbrick
@ 2008-12-07 6:49 ` Drew Adams
2008-12-07 15:09 ` Kevin Rodgers
2 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2008-12-07 6:49 UTC (permalink / raw)
To: 'netawater', help-gnu-emacs
> I used (concat (symbol-name major-mode) "-map") to get
> current keymap, but it failed for LaTeX mode. Are there
> other methode to get current keymap.
If I enter a buffer, do `M-x latex-mode',
then M-: (concat (symbol-name major-mode) "-map")
it returns "latex-mode-map". What did you want?
That's the name of a symbol whose value is the latex mode keymap. If you want
the keymap itself, then you want this:
(symbol-value ; Value of
(intern ; Symbol whose name is
(concat (symbol-name major-mode) "-map")))
However, (current-local-map) gives you the same thing, and it works regardless
of the name of the symbol.
(eq (symbol-value
(intern
(concat (symbol-name major-mode) "-map")))
(current-local-map))
=> t
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get current keymap
2008-12-07 6:49 ` Drew Adams
@ 2008-12-07 15:09 ` Kevin Rodgers
2008-12-07 17:33 ` Drew Adams
[not found] ` <mailman.2157.1228671183.26697.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 9+ messages in thread
From: Kevin Rodgers @ 2008-12-07 15:09 UTC (permalink / raw)
To: help-gnu-emacs
Drew Adams wrote:
>> I used (concat (symbol-name major-mode) "-map") to get
>> current keymap, but it failed for LaTeX mode. Are there
>> other methode to get current keymap.
>
> If I enter a buffer, do `M-x latex-mode',
> then M-: (concat (symbol-name major-mode) "-map")
> it returns "latex-mode-map". What did you want?
>
> That's the name of a symbol whose value is the latex mode keymap. If you want
> the keymap itself, then you want this:
>
> (symbol-value ; Value of
> (intern ; Symbol whose name is
> (concat (symbol-name major-mode) "-map")))
>
> However, (current-local-map) gives you the same thing, and it works regardless
> of the name of the symbol.
>
> (eq (symbol-value
> (intern
> (concat (symbol-name major-mode) "-map")))
> (current-local-map))
>
> => t
A different way to find the symbol, instead of relying on its name:
(when (current-local-map)
(let ((result nil))
(mapatoms (function (lambda (symbol)
(when (and (boundp symbol)
(eq (symbol-value symbol)
(current-local-map)))
(push symbol result)))))
result))
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: How to get current keymap
2008-12-07 15:09 ` Kevin Rodgers
@ 2008-12-07 17:33 ` Drew Adams
[not found] ` <mailman.2157.1228671183.26697.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 9+ messages in thread
From: Drew Adams @ 2008-12-07 17:33 UTC (permalink / raw)
To: 'Kevin Rodgers', help-gnu-emacs
> >> I used (concat (symbol-name major-mode) "-map") to get
> >> current keymap, but it failed for LaTeX mode. Are there
> >> other methode to get current keymap.
> >
> > If I enter a buffer, do `M-x latex-mode',
> > then M-: (concat (symbol-name major-mode) "-map")
> > it returns "latex-mode-map". What did you want?
> >
> > That's the name of a symbol whose value is the latex mode
> > keymap. If you want the keymap itself, then you want this:
> >
> > (symbol-value ; Value of
> > (intern ; Symbol whose name is
> > (concat (symbol-name major-mode) "-map")))
> >
> > However, (current-local-map) gives you the same thing, and
> > it works regardless of the name of the symbol.
> >
> > (eq (symbol-value
> > (intern
> > (concat (symbol-name major-mode) "-map")))
> > (current-local-map))
> >
> > => t
>
> A different way to find the symbol, instead of relying on its name:
>
> (when (current-local-map)
> (let ((result nil))
> (mapatoms (function (lambda (symbol)
> (when (and (boundp symbol)
> (eq (symbol-value symbol)
> (current-local-map)))
> (push symbol result)))))
> result))
Yes. To be clear, I didn't mean to suggest that one should use the
map-variable's name, or that the above `eq' sexp would always return t. What I
meant was that, for _LaTeX_ mode, the two expressions are `eq'. I should have
made that clear. My point was to _not_ rely on the name, but to use
`current-local-map' instead.
Most uses of keymaps never require knowing the map variable itself; its value
can be used directly. But if for some reason one needs the map variable, then
the code you provided is the way to go.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get current keymap
[not found] ` <mailman.2157.1228671183.26697.help-gnu-emacs@gnu.org>
@ 2008-12-08 14:39 ` netawater
0 siblings, 0 replies; 9+ messages in thread
From: netawater @ 2008-12-08 14:39 UTC (permalink / raw)
To: help-gnu-emacs
"Drew Adams" <drew.adams@oracle.com> writes:
>> >> I used (concat (symbol-name major-mode) "-map") to get
>> >> current keymap, but it failed for LaTeX mode. Are there
>> >> other methode to get current keymap.
>> >
>> > If I enter a buffer, do `M-x latex-mode',
>> > then M-: (concat (symbol-name major-mode) "-map")
>> > it returns "latex-mode-map". What did you want?
>> >
>> > That's the name of a symbol whose value is the latex mode
>> > keymap. If you want the keymap itself, then you want this:
>> >
>> > (symbol-value ; Value of
>> > (intern ; Symbol whose name is
>> > (concat (symbol-name major-mode) "-map")))
>> >
>> > However, (current-local-map) gives you the same thing, and
>> > it works regardless of the name of the symbol.
>> >
>> > (eq (symbol-value
>> > (intern
>> > (concat (symbol-name major-mode) "-map")))
>> > (current-local-map))
>> >
>> > => t
>>
>> A different way to find the symbol, instead of relying on its name:
>>
>> (when (current-local-map)
>> (let ((result nil))
>> (mapatoms (function (lambda (symbol)
>> (when (and (boundp symbol)
>> (eq (symbol-value symbol)
>> (current-local-map)))
>> (push symbol result)))))
>> result))
>
> Yes. To be clear, I didn't mean to suggest that one should use the
> map-variable's name, or that the above `eq' sexp would always return t. What I
> meant was that, for _LaTeX_ mode, the two expressions are `eq'. I should have
> made that clear. My point was to _not_ rely on the name, but to use
> `current-local-map' instead.
>
> Most uses of keymaps never require knowing the map variable itself; its value
> can be used directly. But if for some reason one needs the map variable, then
> the code you provided is the way to go.
Thank you very much for repling, I have resolved my problem. thanks very much!
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-12-08 14:39 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-06 14:37 How to get current keymap netawater
2008-12-06 18:24 ` Xah Lee
2008-12-06 21:37 ` Rupert Swarbrick
2008-12-07 5:28 ` netawater
2008-12-07 6:35 ` Drew Adams
2008-12-07 6:49 ` Drew Adams
2008-12-07 15:09 ` Kevin Rodgers
2008-12-07 17:33 ` Drew Adams
[not found] ` <mailman.2157.1228671183.26697.help-gnu-emacs@gnu.org>
2008-12-08 14:39 ` netawater
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).