Fork me on GitHub
#cider
<
2021-04-08
>
yuhan10:04:18

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.

bozhidar11:04:23

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

bozhidar11:04:56

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

yuhan11:04:10

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

bozhidar11:04:12

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

bozhidar11:04:15

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

yuhan11:04:36

for future tooling to take advantage of, perhaps?

bozhidar11:04:38

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.

yuhan11:04:32

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

yuhan11:04:09

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
yuhan11:04:51

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

bozhidar15:04:34

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.

yuhan07:04:06

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

yuhan07:04:29

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

Setzer2214:04:17

Hi! 😄 Is there a way I can set some code to run on every buffer eval?

Setzer2214:04:30

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

Setzer2214:04:56

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

bozhidar15:04:31

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

👍 1
bozhidar15:04:00

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

dpsutton15:04:49

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

dpsutton15:04:34

;; ‘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

Setzer2215:04:42

thanks @bozhidar , I kina managed to get it working 🙂