First of all, I would like to correct my mistake in my earlier answer (now deleted).
When the point is in the source blocks, the org-src-mode-map is active.
Actually the org-src-mode-map
is active in the temporary buffer that pops up after you hit C-c '
(bound to org-edit-special
) when the point is in a source block like below.
#+BEGIN_SRC emacs-lisp
(message "Hi")
#+END_SRC
So please disregard my earlier answer.
Tested solution
The solution that might work for your case is to advise the org-ctrl-c-ctrl-c
function. This is the function bound to C-c C-c
by default in org-mode-map
.
The below advice will made the org-babel-execute-src-block-maybe
if the point is in an org source block when you hit C-c C-c
. Otherwise, the org-ctrl-c-ctrl-c
function will run as usual.
(defun my/advice-org-ctrl-c-ctrl-c (&rest args)
"Run `org-babel-execute-src-block-maybe' if point is in an org source block."
(let ((do-not-run-orig-fn (org-in-src-block-p)))
(when do-not-run-orig-fn
(call-interactively #'org-babel-execute-src-block-maybe))
do-not-run-orig-fn))
(advice-add 'org-ctrl-c-ctrl-c :before-until #'my/advice-org-ctrl-c-ctrl-c)
Above solution is tested using emacs -Q
(version 25.0.94) and latest build of org from its git master.
Warning!
By doing this, you will be overriding the default behavior of C-c C-c
in source blocks. Below is a snippet from the documentation we get on doing C-h f org-ctrl-c-ctrl-c
:
- If the cursor is on a code block, evaluate it. The variable
‘org-confirm-babel-evaluate’ can be used to control prompting
before code block evaluation, by default every code block
evaluation requires confirmation. Code block evaluation can be
inhibited by setting ‘org-babel-no-eval-on-ctrl-c-ctrl-c’.
C-h k C-c C-c
?org-ctrl-c-ctrl-c
in org mode buffers.