Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jack-in disables clojure-mode #1317

Closed
blueberry opened this issue Sep 11, 2015 · 22 comments
Closed

jack-in disables clojure-mode #1317

blueberry opened this issue Sep 11, 2015 · 22 comments

Comments

@blueberry
Copy link

After upgrade from 20150910 to 20150911 clojure-mode gets disabled each and every time something from a clojure buffer is evaluated in the repl. All clojure code loses syntax highlighting (for the clojure parts and parens).
After M-x clojure-mode, the highlihgting gets back. New evaluation disables it again.

Steps to reproduce:

  1. create a new project: lein new cider-bug
  2. Open project.clj in emacs
  3. C-c M-j
    result: no parens coloring in project.clj
@Malabarba
Copy link
Member

Could you verify your cider-nrepl version?

@blueberry
Copy link
Author

Yes. 0.10.0-SNAPSHOT
Also tried 0.9.1 - the problem stays
The bug appeared after emacs restart (and I suppose an automatic update) with no change in setup and projects that worked this morning

@expez
Copy link
Member

expez commented Sep 11, 2015

@blueberry I can't reproduce this.

Can you clone this repo and run make run-cider and see if you can reproduce the issue without your configuration?

That Make task implicitly depends on Cask (dependency management for emacs) already being installed. If you don't have cask installed you can install it with

curl -fsSkL https://gist.github.com/rejeep/7736123/raw > travis.sh && source ./travis.sh

@Malabarba
Copy link
Member

Do you get any messages indicating what might have happened?

@blueberry
Copy link
Author

I have tried make run-cider, but it shows plain vanilla emacs that shows all parens in black anyway. That's why this can't be reproduced, or can, but cannot be seen on the screen.

My emacs is basically emacs 24.5.1 with prelude and very minimal personal setings (literally a few lines setting a few keybindings unrelated to clojure). I commented out everything from the personal configuration and the problem is still there after restarting emacs.

@blueberry
Copy link
Author

As for messages, this is the contents of Messages buffer after starting the REPL (seems normal to me):

Making nrepl-create-client-buffer-function local to nrepl-server cider-bug while let-bound!
Making nrepl-use-this-as-repl-buffer local to nrepl-server cider-bug while let-bound!
Starting nREPL server via lein repl :headless...
nREPL server started on 53108
nREPL: Establishing direct connection to localhost:53108 ...
nREPL: Direct connection established
Connected. Controlling complexity is the essence of computer programming. -Brian Kernighan

@expez
Copy link
Member

expez commented Sep 11, 2015

I have tried make run-cider, but it shows plain vanilla emacs that shows all parens in black anyway. That's why this can't be reproduced, or can, but cannot be seen on the screen.

Aight, then this is a problem with your config and not a bug related to CIDER. CIDER isn't involved in coloring parenthesis, and neither is clojure-mode. Likely you have something like rainbow-delimiters-mode which is applied in the clojure-mode-hook. Something goes wrong when your custom hook code runs, sometimes, causing it to not get to the rainbow delimiters part. When you do M-x clojure-mode the hook is run again, but this time it works.

@expez
Copy link
Member

expez commented Sep 11, 2015

You can do do C-h v clojure-mode-hook <RET> to inspect the value of that hook if you need further assistance debugging this.

@blueberry
Copy link
Author

But I have coloring and everything with my PLAIN VANILLA emacs. My hook code (and the whole custom.el) is literally only this:
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes
(quote
( default))))

(load-theme 'cyberpunk)
(scroll-bar-mode -1)
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
(add-hook 'prog-mode-hook 'paredit-everywhere-mode)
(add-hook 'clojure-mode-hook 'smartparens-strict-mode)
;display line numbers in all frames
(global-set-key (kbd "C-x n RET") 'linum-mode)

;;recognize OpenCL *.cl files as c source code
(setq auto-mode-alist (cons '(".cl$" . c-mode) auto-mode-alist))

(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.

)

I identified that this option from cider is the problem, and everything works fine if I set:
(setq cider-font-lock-dynamically '())

Of course, then there is a problem of font locking not working...

@blueberry
Copy link
Author

And to add about the clojure-mode-hook:

  1. If i disable cider-font-lock-dynamically, it is:
    (cider-mode
    #[nil "\300\301!\207"
    [run-hooks prelude-clojure-mode-hook]
    2]
    er/add-clojure-mode-expansions smartparens-strict-mode)
  2. When I enable it, it is:
    (cider-mode
    #[nil "\300\301!\207"
    [run-hooks prelude-clojure-mode-hook]
    2]
    er/add-clojure-mode-expansions smartparens-strict-mode)

So, that value is the same.

@Malabarba
Copy link
Member

It's possible we're doing something incompatible with rainbow-delimiters-mode, the question is whose bug is it.

@blueberry
Copy link
Author

I do not insist on rainbow-delimiters-mode - any alternative that works for you is fine for me. Can you please share a relevant part of your own configuration that works?

@bbatsov
Copy link
Member

bbatsov commented Sep 11, 2015

Perhaps it's something similar to #749?

@Malabarba
Copy link
Member

@blueberry This whole conversation was slightly confusing. Could you show us a screenshot of the problem? I just want to see what your clojure buffers look like when this issue happens.

@blueberry
Copy link
Author

To sum it up:
Problem: after jack-in, code such as this:
[[[[[[]]]]]]
loses rainbow coloring in the clj file

Why I think it is not due to my custom configuration:
I REINSTALLED PRELUDE from scratch, enabled clojure language support, have absolutely no custom config, and the problem is still there. Plus, everything worked fine until cider 20150911.253

Since I have found a (clunky) workaround, It is not something urgent. Thank you for providing such an excellent tool with prompt support. It seems to me I have to find time to read the elisp book, so I can investigate such problems in more detail when they arise.

You can close the issue if you think it does not affect other users, although I'd be surprised if it is so since I've tried a fresh prelude install and the problem is still here...

@expez
Copy link
Member

expez commented Sep 12, 2015

@blueberry prelude is several thousand lines of "custom config"...

It's likely that other users are affected by this. Both prelude and rainbow-delimiters-mode are popular packages.

What was your workaround? Perhaps that gives some indication as what went wrong.

@blueberry
Copy link
Author

The workaround is adding this line to the custom config:

(setq cider-font-lock-dynamically '())

Of course, it is clunky because it disables font locking for macros and core...

@corymickelson
Copy link

I am having this same issue with rainbow-delimiters-mode, after connecting to cider some other modes no longer seem to work. Thanks for the workaround for now though.....

@Malabarba
Copy link
Member

I just installed rainbow-delimiters and can verify this happens as well.
I can only assume this happens because we change the value of clojure-font-lock-keywords, and rainbow delimiters somehow depends on that(?).

(setq-local cider-font-lock-keywords
            (append clojure-font-lock-keywords
                    (cider--compile-font-lock-keywords)))
(font-lock-refresh-defaults)

@Fanael Do you think that could be the cause? Is there an appropriate way to change a buffer's font-lock-keywords without screwing with rainbow-delimiters?

@Malabarba
Copy link
Member

Hm, I think I see the problem. Rainbow-delimiters sets the syntax-begin-function, and (font-lock-refresh-defaults) probably resets this variable to the default value.

I'm not sure, but it's the only thing I can think of.

@Malabarba
Copy link
Member

That was it. Should be fixed now.

@blueberry
Copy link
Author

it works ok now. thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants