clojure-vim / clojure.vim Goto Github PK
View Code? Open in Web Editor NEWClojure syntax highlighting for Vim and Neovim.
License: Other
Clojure syntax highlighting for Vim and Neovim.
License: Other
Hey.
I use CIDER in Spacemacs and they do this:
How can I achieve that in vim/nvim?
The default behavior in nvim gives me this:
When I try to do define my own syntax for highlighting part of a keyword I can't understand how to do it (copied from this project) and I end up highlighting the whole keyword or nothing at all:
syntax match clojureKeywordMine "\v<:{1,2}([^ \n\r\t()\[\]{}";@^`~\\/]+/)*<!>"
highlight clojureKeywordMine ctermbg=darkred
Regarding Neovim, until Vim9 script support is added, the "New (legacy)" code will be used. If anyone would like to volunteer to write a Lua implementation of this code for Neovim please open an issue and we can discuss how to integrate it.
Originally posted by @axvr in #31 (comment)
I'd be willing to try my hand at it.
Hello,
Currently indent/clojure.vim
indents subforms of (ns ...)
with 2-spaces, like this:
(ns ncr.nsql.simple
(:require
[clojure.string :as str]
[clojure.core.match :refer [match]]
while the style guide seemingly recommends, and cljfmt
indents, the same subforms with 1-space (paren-aligned), like this:
(ns ncr.nsql.simple
(:require
[clojure.string :as str]
[clojure.core.match :refer [match]]
Would you consider accepting a patch that adds optional, off-by-default ability to format those like cljfmt
does it?
Note
Currently waiting on #31 to be completed and merged.
Create a Vim 9 script variant of the new indentation algorithm to get significant performance improves during indentation.
This will be a fairly quick task, the only difficult part is figuring out how to integrate it in a clean way.
(Provide a secret config option to turn off Vim9 script version for testing.)
Neovim equivalent: #32
Some plugins use set lisp?
to determine if the file is Lisp or not. It would be cool if you had lisp
option set just so that outside plugins may detect Clojure as Lisp. It's possible for outside plugins to hardcode Clojure as Lisp, but I don't think that's the best approach.
When typing, indentation is correct, but when indenting using something like gg=G
, the indentation becomes incorrect. The following example is in Fennel, but the idea is the same.
Correct indentation:
{1 :gbprod/cutlass.nvim
:opts {:cut_key :x
:exclude [:ns :nS]
:registers {:change :c :delete :d :select :s}}}
After gg=G
:
{1 :gbprod/cutlass.nvim
:opts {:cut_key :x
:exclude [:ns :nS]
:registers {:change :c :delete :d :select :s}}}
Also see neovim/neovim#24080
Hey friends,
The indentation system is built on the syntax highlighting to know how to interpret things like \{
. If I use nvim-treesitter (which relies on this grammar) and disable nvim's syntax highlighting, indentation is completely broken.
I don't want to lose the nice indentation provided by this plugin (as there is no indentation information for Clojure in nvim-treesitter), but enabling both vimscript syntax highlighting and treesitter highlighting is bad and slow.
Any suggestions on how to handle this?
https://github.com/krisajenkins/vim-clojure-sql
But we might be able to detect next.jdbc and clojure.java.jdbc calls and highlight parameters for those using SQL syntax.
Unit tests could help especially with the indent fn. There are probably a few cases broken currently: guns/vim-clojure-static#83
Not sure how these are usually done with Vimscript.
We could probably copy test cases from some other project for a start:
https://github.com/clojure-emacs/clojure-mode/blob/master/test/clojure-mode-indentation-test.el
https://github.com/weavejester/cljfmt/blob/master/cljfmt/test/cljfmt/core_test.cljc#L11
I import them frequently and probably everyone does. It would probably be a good idea.
I think this should work but I don't know why it doesn't work (also you use a generator and probably don't even need this):
syntax keyword clojureTestMacro deftest is
highlight link clojureTestMacro clojureMacro
Was wondering if it is possible to target the doc strings that are in a defn form separately from normal Strings?
(defn my-function "This is the doc string I am talking about. It would be great if this can be highlighted differently from regular Strings" [arg 1 arg2] ...
I probably need a syntax region, but I am lost with the syntax file format. Thanks
Currently the syntax generation code only works on Java 8 (and below) as the latest JDK versions no longer contain some classes we used for reflection.
These missing classes are:
java.util.regex.Pattern$CharPropertyNames
java.util.regex.UnicodeProp
To fix this the reflection code needs replacing as there are no straightforward replacements for these classes.
I have already done some work on building the new reflection code.
There are several Vim plugins for other Clojure-like Lisps that were forked from Clojure.vim or Vim-clojure-static that could benefit from the upcoming indentation improvements.
Either open an issue letting the maintainers know, or open a PR porting them to the new algorithm.
We should consider submitting the latest changes for inclusion in Vim soon (preferably sometime before Vim 9 is released).
For this we will need to:
generate.clj
on how to do this),NOTE: apparently it is now possible to open a pull request in the Vim GitHub repository instead of sending an email as that will automatically send the email and run the CI tests.
Open questions:
With the new indentation test mechanism (#26) it should be possible to run the indentation tests in Neovim too.
Context: https://tonsky.me/blog/clojurefmt/
Clojure.vim is missing syntax highlighting for new functions and special forms added to "clojure.main" in Clojure versions 1.9 and 1.10.
This is related to guns/vim-clojure-static/issues/80 and some work was already done in guns/vim-clojure-static/pull/91.
This is a proposal/request for comments for a possible future change. No change will be made/merged without feedback or demand.
It is possible to make Clojure.vim automatically mark specific Clojure files as Clojure sub-types by using a lesser known Vim feature detailed under :h 'filetype'
. This may improve configurabilty and allow other plugins to run specific code for each sub-filetype.
This can be done by changing the filetype detection code to something like this:
" ftdetect/clojure.vim
autocmd BufNewFile,BufRead *.clj,*.cljc,*.cljs setlocal filetype=clojure " Maybe even separate out cljs?
autocmd BufNewFile,BufRead *.edn setlocal filetype=clojure.edn
autocmd BufNewFile,BufRead {build,profile}.boot setlocal filetype=clojure.boot
autocmd BufNewFile,BufRead project.clj setlocal filetype=clojure.lein
This would also make it possible to add additional syntax keywords per sub-filetype, such as highlighting defproject
only in project.clj
files.
There may be better ways of achieving the same goals without having to add lots of new filetypes (which may conflict with other filetypes included in Vim). If you can think of any or have any thoughts on this, please leave a comment below.
WIth performance fixes, maybe default could be larger than 100 lines?
With 6b18b4e test script, master:
FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
29646 4.656598 <SNR>35_syn_id_name()
1532 5.261001 0.407066 <SNR>35_match_pairs()
29028 4.712738 0.186393 <SNR>35_ignored_region()
28332 4.856748 0.155025 <SNR>35_is_paren()
30068 0.059254 <SNR>35_current_char()
417 5.570994 0.033857 GetClojureIndent()
417 5.439542 0.032423 <SNR>35_clojure_indent_pos()
315 1.959061 0.012072 <SNR>35_clojure_is_method_special_case_worker()
416 0.112460 0.006156 <SNR>35_clojure_check_for_string_worker()
416 0.116510 0.004050 <SNR>35_check_for_string()
581 0.003795 <SNR>35_strip_namespace_and_macro_chars()
130 0.003790 <SNR>35_match_one()
581 0.003502 <SNR>35_current_word()
315 1.962500 0.003439 <SNR>35_is_method_special_case()
1395 0.002532 <SNR>35_bracket_type()
315 0.001042 <SNR>35_is_reader_conditional_special_case()
Because indent uses the syntax rules, #5 branch already improves this a quite bit:
FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
29646 1.478719 <SNR>35_syn_id_name()
1532 2.199816 0.404030 <SNR>35_match_pairs()
29028 1.617763 0.185423 <SNR>35_ignored_region()
28332 1.798798 0.156209 <SNR>35_is_paren()
30068 0.059659 <SNR>35_current_char()
417 2.391534 0.034190 GetClojureIndent()
417 2.312287 0.032532 <SNR>35_clojure_indent_pos()
315 0.809202 0.011783 <SNR>35_clojure_is_method_special_case_worker()
416 0.046043 0.006287 <SNR>35_clojure_check_for_string_worker()
130 0.004105 <SNR>35_match_one()
581 0.004033 <SNR>35_strip_namespace_and_macro_chars()
416 0.050047 0.004003 <SNR>35_check_for_string()
581 0.003524 <SNR>35_current_word()
315 0.812542 0.003340 <SNR>35_is_method_special_case()
1395 0.002603 <SNR>35_bracket_type()
315 0.001093 <SNR>35_is_reader_conditional_special_case()
Testing against Reagent src/reagent/impl/component.cljs
.
There are several Vim plugins for other Clojure-like Lisps that were forked from Clojure.vim or Vim-clojure-static that could benefit from the upcoming indentation improvements.
Either open an issue letting the maintainers know, or open a PR porting them to the new algorithm.
I have a custom syntax regex for highlighting symbols that are in function position in a list. I've added it to clojureTop before the built-in functions list so they can be highlighted distinctly if desired. Would y'all be interested in a PR for this?
Currently the syntax highlighting support for the discard reader macro (#_
) is limited to a single form, however Clojure supports stacking them which comments out subsequent forms.
;; Correctly highlighted:
(defn foo [x]
{:bar (+ x 1)
#_:biz #_(* x 2)})
;; Incorrectly highlighted:
(defn foo [x]
{:bar (+ x 1)
#_#_:biz (* x 2)})
It may not be possible to implement this behaviour, but is worth trying. If it isn't possible (to do efficiently) we may just disable the existing comment reader macro highlighting support by default for consistency.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.