Say, the C-M-j
is bound to c-indent-new-comment-line
for c-mode (and c++-mode) and indent-new-comment-line
for other modes, but I want to define a function that will execute C-M-j
to c-indent-new-comment-line
in c-mode (and c++-mode) and indent-new-comment-line
in other modes.
Is there any simple way that I can just embed the shortcut but not check the current major mode and then execute the different functions in defun...
?
Example:
(defun example-fn ()
(interactive)
(beginning-of-line)
(execute-C-M-j)
(next-line))
The (execute-C-M-j)
is what I want, execute the key not the command it is bound to, but I don't know how to implement this?
(defun example-fn () (interactive) (if (eq major-mode 'c-mode) (message "Hello-world!") (message "Happy birthday!"))) (define-key global-map [f5] 'example-fn)
– lawlist Jan 18 '15 at 7:58C-M-j
to doX
mean? After executing the function, you would want the desired shortcuts to be bound? – Pradhan Jan 18 '15 at 8:08