Reputation: 12138
I want to remap forward-sexp
to matlab-forward-sexp
in matlab-mode
.
Currently I do this:
(define-key matlab-mode-map [remap forward-sexp] 'matlab-forward-sexp-safe)
but when I type M-x forward-sexp
in matlab-mode I still get the old behaviour. Why? Does it only work when I call forward-sexp
through a keyboard shortcut?
when I type C-h f forward-sexp
everything seems ok:
forward-sexp is an interactive compiled Lisp function in `lisp.el'.
It is remapped to `matlab-forward-sexp-safe', which is bound to C-M-f,
<C-M-right>, ESC <C-right>.
(forward-sexp &optional ARG)
For more information check the manuals.
Move forward across one balanced expression (sexp).
With ARG, do it that many times. Negative arg -N means
move backward across N balanced expressions.
This command assumes point is not in a string or comment.
This function is advised.
After-advice `ctx-flash'.
[back]
Upvotes: 2
Views: 1320
Reputation: 101
If you really want to change the behavior of the function, you can use forward-sexp-function
.
Also you may like to check out Emacs-24's octave-mode, which uses SMIE for parsing, making forward-sexp automatically jump over actual Octave syntactic elements rather than only parens/brackets/braces.
Upvotes: 2
Reputation: 73390
Yes, the [remap]
syntax is explicitly for key bindings. When a binding would have invoked the old function, the remapping causes it to invoke the new one instead. That does not alter the definitions of either function, however -- they can still be called directly.
For details, see M-: (info "(elisp) Remapping Commands")
RET
A recent change in Emacs 24 has clarified this help text, so it would now read as follows:
forward-sexp is an interactive compiled Lisp function in `lisp.el'.
Its keys are remapped to `matlab-forward-sexp-safe'. Without this remapping, it would be bound to C-M-f, <C-M-right>, ESC <C-right>. .
Upvotes: 3