[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Replacing c-beginning/end-of-defun in a Major Mode
From: |
Tom Willemse |
Subject: |
Re: Replacing c-beginning/end-of-defun in a Major Mode |
Date: |
Thu, 18 Jul 2013 09:47:53 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
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.