From: Tom Willemse <tom@ryuslash.org>
To: Eric James Michael Ritz <lobbyjones@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Replacing c-beginning/end-of-defun in a Major Mode
Date: Thu, 18 Jul 2013 09:47:53 +0200 [thread overview]
Message-ID: <m34nbse2c6.fsf@ryuslash.org> (raw)
In-Reply-To: <51E79A05.90301@gmail.com> (Eric James Michael Ritz's message of "Thu, 18 Jul 2013 03:32:21 -0400")
Hey Eric,
Eric James Michael Ritz <lobbyjones@gmail.com> 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 …)`. 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 ‘C-c f’ 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))
(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.
prev parent reply other threads:[~2013-07-18 7:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-18 7:32 Replacing c-beginning/end-of-defun in a Major Mode Eric James Michael Ritz
2013-07-18 7:47 ` Tom Willemse [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m34nbse2c6.fsf@ryuslash.org \
--to=tom@ryuslash.org \
--cc=help-gnu-emacs@gnu.org \
--cc=lobbyjones@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).