Skip to content

Instantly share code, notes, and snippets.

@jimmyhmiller
Created December 6, 2021 19:52
Show Gist options
  • Save jimmyhmiller/38522a6f3b2e2c1f1e5ce1dc24fa42ad to your computer and use it in GitHub Desktop.
Save jimmyhmiller/38522a6f3b2e2c1f1e5ce1dc24fa42ad to your computer and use it in GitHub Desktop.
(defun always-nil (&args)
nil)
;; Still some weird things with non-pprint eval going on
(advice-add 'cider-pprint-eval-last-sexp :filter-return #'always-nil)
(advice-add 'cider-pprint-eval-defun-at-point :filter-return #'always-nil)
(advice-add 'cider-pprint-eval-last-sexp-to-comment :filter-return #'always-nil)
(advice-add 'cider-pprint-eval-defun-to-comment :filter-return #'always-nil)
(advice-add 'cider-eval-last-sexp-and-replace :filter-return #'always-nil)
(advice-add 'cider-eval-region :filter-return #'always-nil)
(advice-add 'cider-eval-ns-form :filter-return #'always-nil)
(advice-add 'cider-eval-defun-at-point :filter-return #'always-nil)
(advice-add 'cider-eval-last-sexp :filter-return #'always-nil)
(advice-add 'cider-eval-list-at-point :filter-return #'always-nil)
(advice-add 'cider-eval-sexp-at-point :filter-return #'always-nil)
(advice-add 'cider-eval-sexp-up-to-point :filter-return #'always-nil)
(advice-add 'cider-read-and-eval-defun-at-point :filter-return #'always-nil)
(advice-add 'cider-eval-defun-up-to-point :filter-return #'always-nil)
(advice-add 'cider-eval-last-sexp-in-context :filter-return #'always-nil)
(advice-add 'cider-eval-sexp-at-point-in-context :filter-return #'always-nil)
;; Monkey patch cider to play nice with crdt
;; Erases before killing modes
(defun cider-make-popup-buffer (name &optional mode ancillary)
"Create a temporary buffer called NAME using major MODE (if specified).
If ANCILLARY is non-nil, the buffer is added to `cider-ancillary-buffers'
and automatically removed when killed."
(with-current-buffer (get-buffer-create name)
(setq buffer-read-only nil)
(erase-buffer)
(kill-all-local-variables)
(setq buffer-read-only nil)
(when mode
(funcall mode))
(cider-popup-buffer-mode 1)
(setq cider-popup-output-marker (point-marker))
(setq buffer-read-only t)
(when ancillary
(add-to-list 'cider-ancillary-buffers name)
(add-hook 'kill-buffer-hook
(lambda ()
(setq cider-ancillary-buffers
(remove name cider-ancillary-buffers)))
nil 'local))
(current-buffer)))
;; Monkey patch crdt adds some whens
(cl-defun crdt--send-process-mark-maybe (&optional (lazy t))
(let ((buffer-process (get-buffer-process (current-buffer))))
(when buffer-process
(let* ((mark (process-mark buffer-process)))
(when mark
(let* ((mark-pos (marker-position mark)))
(when mark-pos
(let* ((current-id (crdt--get-id mark-pos)))
(unless (and lazy (string-equal crdt--last-process-mark-id current-id))
(setq crdt--last-process-mark-id current-id)
(crdt--broadcast-maybe
(crdt--format-message
`(process-mark ,crdt--buffer-network-name
,current-id ,mark-pos))))))))))))
(defvar pairing-commands
'((save-buffer)
(cider-pprint-eval-defun-at-point)
(cider-pprint-eval-last-sexp)
(cider-pprint-eval-defun-at-point)
(cider-pprint-eval-last-sexp-to-comment)
(cider-pprint-eval-defun-to-comment)
(cider-eval-last-sexp-and-replace)
(cider-eval-region)
(cider-eval-ns-form)
(cider-eval-defun-at-point)
(cider-eval-last-sexp)
(cider-eval-list-at-point)
(cider-eval-sexp-at-point)
(cider-eval-sexp-up-to-point)
(cider-read-and-eval-defun-at-point)
(cider-eval-defun-up-to-point)
(cider-eval-last-sexp-in-context)
(cider-eval-sexp-at-point-in-context)))
(crdt-register-remote-commands pairing-commands)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment