0

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)))

#+END_SRC

But it doesn't print out anything now.

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.

| improve this answer | |

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.