From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: How to bind a key locally to a buffer (not mode!) Date: Mon, 20 Oct 2014 13:36:12 +0200 Organization: Informatimago Message-ID: <87egu3vuqb.fsf@kuiper.lan.informatimago.com> References: <87iojfok99.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1413805235 6263 80.91.229.3 (20 Oct 2014 11:40:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 20 Oct 2014 11:40:35 +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 Oct 20 13:40:30 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XgBK9-0007Ex-1e for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Oct 2014 13:40:29 +0200 Original-Received: from localhost ([::1]:44084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgBK8-0004u1-8u for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Oct 2014 07:40:28 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 46 Original-X-Trace: individual.net 3LwSKDhV9EhrGZmAkturpAN7vXsYA8b87LHGMVHVj5HZbZi33V Cancel-Lock: sha1:YTAzOTkxMGFhMTgxY2VmNzEyYmJlMWVjYWU0NjhkMjE1MmNkYzA5Yg== sha1:2zMG+guPgw7zklwGRSd5Qof2s3s= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:208235 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100510 Archived-At: Artur Malabarba writes: >> Hi all, >> >> (global-set-key ...) >> >> binds a key globally. >> >> (local-set-key ...) >> >> binds a key locally, i.e., in the current major mode. >> >> I'd like to bind a key in /one buffer/ only, so that the rebinding does >> not affect other buffers in this mode. I could probably do it by >> defining a minor mode, which rebinds this key to a function, which runs >> a function set by a buffer-local variable, but this seems rather >> convoluted. Is there a simpler way to achieve this? > > There is, I used to do this in one of my org buffers. I forget the exact > code now, but I'll look for it. > > You essentially split the current buffer's keymap from its major mode, and > then call local set key. 1. C-h f local-set-key RET 2. the documentation of local-set-key tells you how to do it: The binding goes in the current buffer's local map, which in most cases is shared with all other buffers in the same major mode. Therefore you should create a buffer local map distinct from the major mode map. 3. M-x apropos RET local map RET 4. find a command that lets you create a local keymap. 5. use local-set-key with the new buffer local map. -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk