From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Willemse Newsgroups: gmane.emacs.help Subject: Re: Replacing c-beginning/end-of-defun in a Major Mode Date: Thu, 18 Jul 2013 09:47:53 +0200 Message-ID: References: <51E79A05.90301@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1374133707 10495 80.91.229.3 (18 Jul 2013 07:48:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 18 Jul 2013 07:48:27 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Eric James Michael Ritz Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 18 09:48:30 2013 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 1Uziwu-0004Ep-If for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Jul 2013 09:48:28 +0200 Original-Received: from localhost ([::1]:49493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uziwu-00079B-8K for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Jul 2013 03:48:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uziwk-000785-2H for help-gnu-emacs@gnu.org; Thu, 18 Jul 2013 03:48:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uziwi-0005A7-Qf for help-gnu-emacs@gnu.org; Thu, 18 Jul 2013 03:48:17 -0400 Original-Received: from r0.smtpout1.alwaysdata.com ([176.31.58.0]:33310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uziwi-00059r-FU for help-gnu-emacs@gnu.org; Thu, 18 Jul 2013 03:48:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=alwaysdata.net; s=ryuslash; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From; bh=Ar77b1eoBU+pRjvsm0Gng6X6fLivLL98DxVlhj4OjzI=; b=tvLDPXba1fHRu6YScmtjVVItLAQVN4FXfbZ86uakVp/9ANM+l1njahYdMo13mdNM2byJxSuVYIka1YbyXwLcVnsa5n7BvGEQjltFbgTKQMzK3dJgYakEtfyzeshkWE0Sd2Wm71phf67+2hQlvRCRpSoiZOWHY8dgCwSJn/jl978=; Original-Received: from 78-21-108-183.access.telenet.be ([78.21.108.183] helo=localhost) by smtpout1.alwaysdata.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.77) (envelope-from ) id 1UziwM-0001aM-U8; Thu, 18 Jul 2013 09:47:54 +0200 In-Reply-To: <51E79A05.90301@gmail.com> (Eric James Michael Ritz's message of "Thu, 18 Jul 2013 03:32:21 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-alwaysdata-ID: 68194604 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 176.31.58.0 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:92220 Archived-At: Hey Eric, Eric James Michael Ritz writes: > I am trying to customize the behavior of some commands in a major mode > but I am running into a problem. I am referring to PHP Mode, and its > definition derives from `c-mode`, i.e. `(define-derived-mode php-mode > c-mode =E2=80=A6)`. Because of that PHP Mode inherits two key-bindings: > > 1. C-M-a for `c-beginning-of-defun` > > 2. C-M-e for `c-end-of-defun` > > I want PHP Mode to use the functions `php-beginning-of-defun` and > `php-end-of-defun`, respectively. I can rebind those two keys for PHP > Mode specifically. However, what I really want is for the two > `php-*-of-defun` functions to replace the `c-*-of-defun` functions no > matter what key-bindings the user has. For example, if a user > customizes =E2=80=98C-c f=E2=80=99 to execute `c-beginning-of-defun` then= I want those > same keys to execute `php-beginning-of-defun` when in PHP Mode. > > Is there a way I can tell Emacs to use those PHP-specific functions > only when in PHP Mode, regardless of what keys are set to the normal > CC Mode functions? I would appreciate any help on how to do this, or > to know if there is a better way overall that I am not seeing. I think this sounds like `(local-set-key [remap ...] ...)' should do the trick? (defun php-mode-remap-keys () (local-set-key [remap c-beginning-of-defun] 'php-beginning-of-defun) (local-set-key [remap c-end-of-defun] 'php-end-of-defun)) =20=20=20=20 (add-hook 'php-mode-hook 'php-mode-remap-keys) Or something similar might work? Or of course directly in the php-mode "on" function should work.