From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: netawater Newsgroups: gmane.emacs.help Subject: Re: How to get current keymap Date: Mon, 08 Dec 2008 22:39:28 +0800 Organization: A noiseless patient Spider Message-ID: <87skoy3f4v.fsf@emacs.Arch.net> References: <878wqtcqt6.fsf@emacs.Arch.net> <003b01c95837$ee8b1e30$0200a8c0@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1228747261 10033 80.91.229.12 (8 Dec 2008 14:41:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Dec 2008 14:41:01 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 08 15:42:06 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L9hJA-0005q1-99 for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Dec 2008 15:42:00 +0100 Original-Received: from localhost ([127.0.0.1]:46278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L9hHy-00031r-Vn for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Dec 2008 09:40:47 -0500 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed01.sul.t-online.de!t-online.de!feeder.erje.net!news.motzarella.org!motzarella.org!reader.motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 48 Original-X-Trace: reader.motzarella.org U2FsdGVkX1/QvAzhm2WnU6txELb+yOyIv/m9jkoKfwfz1tvOHFqktSRSMVfjYcc7PEHODd88fnDfOhuyHQaWd8Y7hdoM4zUQPIObdVciqclVeBdz7VSg9UqkV+0tb8/O9hefF7ZN89Y= Original-X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers Original-NNTP-Posting-Date: Mon, 8 Dec 2008 14:39:22 +0000 (UTC) X-Auth-Sender: U2FsdGVkX1/VLSoYvJeLjV/hrFJwtnnIj0Z8oNJoyyptdfdS1DgKhw== Cancel-Lock: sha1:uze+kCZNdDeGKt0F0eYt6vfjMl8= sha1:jAHv6YU0euZ9UHrntpupBxw7iqQ= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:165131 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:60457 Archived-At: "Drew Adams" 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!