greglook / cljstyle

A tool for formatting Clojure code
Eclipse Public License 1.0
293 stars 39 forks source link

Vim instructions don't seem to work #74

Closed martinklepsch closed 6 months ago

martinklepsch commented 3 years ago
Error executing vim.schedule lua callback: ~.vim/plugged/conjure/lua/conjure/buffer.lua:88: Vim(function):E746: Function name does not match script file name: cljstyle#fix

Maybe this is related to Conjure, I'll dig in a bit and try to find a way to make it work but just wanted to flag this.

I added the following to ~/.config/nvim/after/ftplugin/clojure.vim as described in the integrations doc.

" Add to file for vim or neovim:
" ~/.vim/after/ftplugin/clojure.vim
" ~/.config/nvim/after/ftplugin/clojure.vim

" NOTE: typically you'd set these to use a formatter, but in this case it fails
" since cljstyle usually can't run on partial forms.
"setlocal equalprg=cljstyle\ pipe
"setlocal formatprg=cljstyle\ pipe

" This can also go in autoload/cljstyle.vim
function cljstyle#fix()
    let cwd = getcwd()
    let winsave = winsaveview()
    execute "cd" . expand('%:p:h')

    :%!cljstyle pipe

    execute "cd" . cwd
    call winrestview(winsave)
endfunction

" Example shortcut to fix the current file
nnoremap <leader>cs :call cljstyle#fix()<cr>
martinklepsch commented 3 years ago

I ended up getting this to work by adding it to ~/.config/nvim/autoload/cljstyle.vim. I found the instructions not super clear, would you be open for a PR improving them?

greglook commented 3 years ago

Ah, good to know - I use it in the autoload fashion, so maybe there's something special about the function hash name syntax? 🤔 Definitely open to a PR to clarify the instructions!

martinklepsch commented 3 years ago

I think my suggested edit would be something similar to the below but maybe that's just because I don't really understand what any of the above is about 😅


Place the following in ~/.config/nvim/autoload/cljstyle.vim

function cljstyle#fix()
    let cwd = getcwd()
    let winsave = winsaveview()
    execute "cd" . expand('%:p:h')

    :%!cljstyle pipe

    execute "cd" . cwd
    call winrestview(winsave)
endfunction

" Example shortcut to fix the current file
nnoremap <leader>cs :call cljstyle#fix()<cr>
greglook commented 6 months ago

Huh, this does appear to be an issue with the hash-separated function name. https://neovim.io/doc/user/userfunc.html#autoload