unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Replacing c-beginning/end-of-defun in a Major Mode
@ 2013-07-18  7:32 Eric James Michael Ritz
  2013-07-18  7:47 ` Tom Willemse
  0 siblings, 1 reply; 2+ messages in thread
From: Eric James Michael Ritz @ 2013-07-18  7:32 UTC (permalink / raw)
  To: help-gnu-emacs

Hello everyone,

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.

Thanks in advanced for any help.

-- 
ejmr :: http://ericjmritz.wordpress.com/
南無妙法蓮華經



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Replacing c-beginning/end-of-defun in a Major Mode
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Willemse @ 2013-07-18  7:47 UTC (permalink / raw)
  To: Eric James Michael Ritz; +Cc: help-gnu-emacs

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.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-07-18  7:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).