Fork me on GitHub
#emacs
<
2022-11-05
>
Casey11:11:29

At the bottom of many namespaces I tend to have a "rich comment", one of the first forms in this comment is a do form pulling state out of the integrant repl system. I usually mark the end of this sexp with a ;; rcf comment. I'd like to bind a key in emacs/cider that jumps to that form, evals it, then puts the point back where i was editing. I've no idea how to go about this in elisp. Any pointers or prior work here?

tomd18:11:23

Something like this?

(defun eval-rcf ()
  (interactive) ;; you have to do this to be able to bind it to a key or M-x it
  (save-excursion ;; this is what returns the point to where you started
    (goto-char (point-max)) ;; go to end of buffer
    (if (re-search-backward " *;; rcf" nil t) ;; search backward, don't throw an error
        (cider-eval-last-sexp) ;; the cider fn which evals the last form
      (message "No rcf found!")))) ;; if the search fails, show a message in the echo area

(define-key cider-mode-map (kbd "<f8>") #'eval-rcf)
you may have to adjust the regexp to find the exact point where you want to execute the eval, and of course the keybinding to your liking

❤️ 1
Casey21:11:28

Wow yes, that worked right away. Thanks a bunch, especially for the comments. It's very readable and straightforward.

👍 1