2

In org mode, i can not use the Ctrl+c Ctrl+c I have try to rebind it in my .emacs

(define-key org-mode-map (kbd "C-c C-c") 'org-babel-execute-src-block-maybe)

I have also try

(add-hook 'org-mode-hook
    (define (kbd "C-c C-c") 'org-babel-execute-src-block-maybe))

But when i hit the keys in a code block in org mode, nothing (the keybind is not bind to anything).

When i hit Alt+x org-babel-execute-src-block-maybe, everything works fine.

Thank you :)

EDIT: All the Ctrl+c Ctrl+c are unbind in org-mode I simply would like to rebind it to its original function.

  • What does Emacs say (both in org mode and in general) when you use C-h k C-c C-c? – Drew May 22 '16 at 17:50
  • Nothing because it is not assigned to anything. – hanoo May 22 '16 at 22:50
  • @hanoo By default it should it assigned to org-ctrl-c-ctrl-c in org mode buffers. – Kaushal Modi May 25 '16 at 15:45
3

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’.
  • I finally did find the problem/solution, give you +1 for the help :) – hanoo May 25 '16 at 23:04
1

The problem was that in my .emacs I had

(use-package ace-jump-mode
   :ensure t
   :defer t
   :bind* (("C-c SPC" . ace-jump-mode)
           ("C-c C-c SPC" . ace-jump-mode-pop-mark))
   :config (ace-jump-mode-enable-mark-sync))

The "C-c C-c" default behaviour was overridden by "C-c C-c SPC". I changed it and the default behaviour Is BACK :D. Thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.