I wish to run C-c C-c, then click any code line to trigger my code (print "clicked" in this demo)

#+BEGIN_SRC elisp :results output
(defun myclick(n)
  (interactive "p")
  (print "clicked")

(add-hook 'org-mode-hook
             '(lambda ()
                (local-set-key (kbd "<mouse-1>") #'myclick)))


But it doesn't print out anything now.

1 Answer 1


C-c C-c evaluates the code which adds the function to the hook, but the hook is not run: you need to close the file and reopen it in order for the hook to run. Or you can add this to the code block:

(run-hooks 'org-mode-hook)

That will run the hook, which will do the local-set-key to set the mouse click to your function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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