guns/vim-clojure-static

ClojureScript keywords?

noprompt opened this issue · 9 comments

I'm not sure where this should go, if anywhere, but I thought it might be worth adding the special ClojureScript builtins when working with *.cljs files. I've added this to ftplugin/clojure.vim in my personal clone:

au BufEnter,BufNewFile, *.cljs syntax keyword clojureSpecial js-obj array clj->js js->clj

I'm not sure if that's the right place or even if it's the right way to go about doing this sort of thing. Any thoughts?

guns commented

Yes, we should create a separate clojurescript filetype, then source the relevant clojure runtime files, just like cpp does with the c runtime files.

The thornier issue is that ClojureScript is not a superset of Clojure, so various things are unsupported (JVM number literals, macro stuff, certain special forms, etc). This implies that we should implement the clojure and clojurescript filetypes on top of a base set of common runtime scripts, or branch the differences in the clojure runtime files using if…else…endif

I'm pretty sure Bram doesn't want phony filetypes like clojurebase, so we would need some state to detect that we are defining a syntax for clojurescript while syntax/clojure.vim is being sourced. Perhaps a buffer local variable called "b:clojure_platform", set to "jvm" (default) or "js"? I don't think this is problematic, but it would be worth looking for precedents in other inter-related filetypes that ship with Vim.

Anyway, this is definitely overdue. I would happily accept any patches on this front, and I'm sure everyone else would enjoy the improvements. If this sounds boring, I can also put the time in later this week.

Either way, thanks!

It doesn't sound boring at all. It's a great way to for me to level up my Vim scripting skills and benefit the community at the same time. I'll have a look at the cpp runtime files and try to come up with something.

guns commented

Great! I look forward to seeing your implementation.

WRT noprompt-regexp, I didn't really get to spend the time I wanted on code tonight, but I do have the basic clojure-vim communication done, and I'm working on the test macros now. I'll push up whatever I have done tonight and continue to work on it tomorrow.

Hi, I wrote a quick generator for ClojureScript that might be helpful. Unfortunately, it's written in AppleScript instead of clj/cljs because I didn't have much time to work on it. I posted the code for the generator and an output file with all the ClojureScript keywords. Maybe this will help with writing the cljs implementation?

guns commented

Hi @greenyouse,

Thank you for your work. The generators so far have actually pulled keywords and pattern definitions straight out of clojure.core and the JVM. If we were to move forward on this, I would prefer something similar for CLJS; i.e. information directly from the CLJS compiler.

I believe this is possible and not too difficult, but I haven't moved on this personally because I haven't seen any vim plugins for interacting with a CLJS REPL. Until that appears, I don't think there is a pressing need for a separate CLJS filetype just yet.

Plus, I believe @noprompt has since fallen to the dark side, so he may not feel as strongly about this issue as once did. :) (j/k I like evil-mode too)

Plus, I believe @noprompt has since fallen to the dark side, so he may not feel as strongly about this issue as once did. :) (j/k I like evil-mode too)

Ha! Although Emacs certainly provides a more hospitable environment for working with Clojure IMHO, clojure-mode's syntax highlighting doesn't hold a candle to these fine runtime files! :) I can attest these are the most accurate and of the highest quality - they're even tested. I really miss the experience in Emacs. Part of me wonders if the same technique would be worth applying to the clojure-mode (I think so).

FWIW I've actually been meaning to address this issue because, as mentioned, it wouldn't be terribly difficult. Unfortunately I have been a bit busy with other projects. If @greenyouse has the time to look at the code responsible for the code generation and put something together that'd be awesome.

I believe this is possible and not too difficult, but I haven't moved on this personally because I haven't seen any >vim plugins for interacting with a CLJS REPL. Until that appears, I don't think there is a pressing need for a >separate CLJS filetype just yet.

Man, I wish there was an nREPL client or something so vim could do a CLJS REPL. Doing copy/paste from vim clipboard to a REPL in another shell definitely leaves a little to be desired. I haven't tried switching over to emacs + evil but, I'm not gonna lie, that's pretty tempting.

Right now I'm working on something else, so it might be a few weeks or more before I can try writing a better CLJS generator in Clojure. I really appreciate this project though! Vim needs more clj/cljs plugins to help keep up with the growing Emacs environment.

@greenyouse, try this technique to send commands straight from vim to the REPL. No copy-paste required!

guns commented

Enhanced CLJS support is still on the table, but closing this ancient issue for housekeeping. Anyway, @noprompt has long migrated to greener pastures.

:)