cider

A channel dedicated to the Clojure Interactive Development Environment that Rocks (aka CIDER). :cider:
2021-04-08T06:19:39.188700Z

I too use C-c C-e a lot, but I also don’t mind if it’s changed

yuhan 2021-04-08T10:36:18.190600Z

Is Cider supposed to font-lock local bindings any differently? I've noticed it scatters cider-local text properties everywhere, but doesn't seem to do anything in particular with them.

bozhidar 2021-04-08T11:02:23.190800Z

@qythium See cider--parse-and-apply-locals

bozhidar 2021-04-08T11:02:56.191500Z

I don't think we were ever doing font-locking for those, we were just marking them as locals.

yuhan 2021-04-08T11:06:10.192200Z

Yeah, I was looking at that section of code and couldn't figure out /what/ it was doing, besides marking them

bozhidar 2021-04-08T11:06:12.192300Z

Hmm, I see it's actually in the mode definition as well:

bozhidar 2021-04-08T11:06:15.192500Z

(setq-local font-lock-fontify-region-function
                    (cider--wrap-fontify-locals font-lock-fontify-region-function))

yuhan 2021-04-08T11:06:36.193200Z

for future tooling to take advantage of, perhaps?

bozhidar 2021-04-08T11:06:38.193300Z

Perhaps this was working at some point and we broke it. I don't remember already. I see the code hasn't been touched in 5 years.

yuhan 2021-04-08T11:08:32.194700Z

I see, thanks - also noticed that the locals it's picking up are almost always wrong and bleeding in from neighboring forms

yuhan 2021-04-08T11:10:09.195800Z

I was basically trying to hack together an eldoc extension to show something useful in a recur form by picking up the nearest target's binding names, and saw that the locals code had quite a bit of relevant logic written already.

πŸ‘ 1
yuhan 2021-04-08T11:49:30.197900Z

yuhan 2021-04-08T11:50:51.198800Z

Ah, looks like it doesn't handle destructured bindings - I'll have to figure that out another time

yuhan 2021-04-09T07:29:06.212900Z

That does seem a lot nicer and less brittle than the regex / point moving approaches that are currently implemented!

yuhan 2021-04-09T07:32:29.213100Z

Though I'd be worried about performance, right now I basically have to choose between aggressive-indent-mode or clojure-indent-use-backtracking, otherwise editing on my laptop slows to an crawl on large forms... the indentation logic starts taking up 50% of the CPU and triggering GC pauses every few seconds

Setzer22 2021-04-08T14:46:17.199800Z

Hi! πŸ˜„ Is there a way I can set some code to run on every buffer eval?

Setzer22 2021-04-08T14:46:30.200200Z

I'd like to re-run spec instrumentation on every file reload

Setzer22 2021-04-08T14:48:56.201Z

ok, I see there's cider-file-loaded-hook, I think that's exactly what I need. If anyone knows of some example code that'd be much appreciated

bozhidar 2021-04-08T15:13:31.201200Z

It's as simple as (add-hook 'cider-file-loaded-hook #'cider--test-silently).

πŸ‘ 1
bozhidar 2021-04-08T15:14:00.201600Z

In your case you'll be triggering some evaluation function of course, there are many of those.

bozhidar 2021-04-08T15:18:34.201700Z

Most likely it was the initial version of something that we didn't finish. Now with parse-clj it should be easier to do something like what you have in mind. This is one of the dream goal - file-level static analysis that's not depending on running external tools.

dpsutton 2021-04-08T15:32:49.203200Z

this will run on each file loaded. Not sure why you're loading the buffer so much, but i'd probably put a (comment (require 'this-ns :reload)) and inside of that comment form the instrument call as well. I think i remember a patch to add evaluation from a register and that comes to my mind

dpsutton 2021-04-08T15:33:34.203600Z

;; β€˜C-x r s <register-key>’ save to register
  ;; 'C-c C-j x <register-key' to send to repl
  (defun cider-insert-register-contents (register)
    (interactive (list (register-read-with-preview "From register")))
    (let ((form (get-register register)))
      ;; could put form into a buffer and check if its parens are
      ;; balanced
      (if form
          (cider-insert-in-repl form (not cider-invert-insert-eval-p))
        (user-error "No saved form in register"))))

  (define-key 'cider-insert-commands-map (kbd "x") #'cider-insert-register-contents)
  (define-key 'cider-insert-commands-map (kbd "C-x") #'cider-insert-register-contents)
  (define-key cider-repl-mode-map (kbd "C-c C-j") 'cider-insert-commands-map)
i'd save the instrument form in a register and then send it to the repl

Setzer22 2021-04-08T15:45:42.204100Z

thanks @bozhidar , I kina managed to get it working πŸ™‚