purescript-contrib / purescript-vim

Syntax highlighting and indentation for PureScript
BSD 2-Clause "Simplified" License
154 stars 35 forks source link

Indent using spaces instead of tabs #76

Open hank-der-hafenarbeiter opened 3 years ago

hank-der-hafenarbeiter commented 3 years ago

Hey everyone,

I don't know if this is an issue particular to my neovim setup but my editor indents using tabs and these are not legal characters in purescript. So purescript-vim should probably make sure that tabs aren't used for indentation. I mostly c+p my vimrc/init.vim together so I'm not sure what the best way to implement this is, but it should probably just say:

" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab

Somewhere

nilp0inter commented 3 years ago

I have the exact same issue using Vim 8. Is there any workaround?

hank-der-hafenarbeiter commented 3 years ago

Well, my workaround is learning functional programming using haskell instead. For me it was about learning functional programming and I got haskell to work. I'll probably come back to this later. So for now: No, haven't found a workaround.

mkohlhaas commented 2 years ago

Had the same issue. I use a Lua init file and it works nicely. Lua has its own namespace. You should try something like this:

local set = vim.opt    -- acts like the :set command in vimscript; set global, window and buffer settings
set.shiftwidth = 2     -- set shift width to 4 spaces.
set.tabstop    = 2     -- set tab width to 4 columns.
set.expandtab  = true  -- Use space characters instead of tabs.
toastal commented 1 year ago

Tabs are great! But yes, the PureScript compiler doesn't support it... yet.

EditorConfig: https://editorconfig.org/ purescript-tidy: https://github.com/natefaubion/purescript-tidy

This are two great options for your projects to help as well. EditorConfig will make sure your whole team's editors are using the same white space across projects. Tidy will make sure your PureScript code is formatted similarly across the project and team--including configurable indentation. With the tab support being an open discussion and the popularity of Tidy in the community allowing users to configure the number of spaces, I don't think it's in the best interest for the Vim project here to be dictating these settings on users, and instead users can differ to other tools like the ones mentioned or changing their local vimrc.

FredTheDino commented 1 year ago

Maybe it would be a good idea to enable just expandtab in the purescript.vim config? since the current situation is that tabs is not allowed in purescript, That would still allow users to use what ever shiftwidth and tabstop they like. It's particularly frustrating if users switch to Haskell because of this.

toastal commented 1 year ago

Agreed that we should not enforce the shiftwidth and tabstop given tools like purescript-tidy allow users to configure this value. With the tab support issue having interest and being unresolved (with a community member saying they were going to investigate it), I think that this may be a bit hasty. I will double check with that member.

@FredTheDino is there an issue with setting up EditorConfig + editorconfig-vim while I get some confirmations?

FredTheDino commented 1 year ago

I haven't used editorconfig in the purescript projects I'm working on - it looks to work. I lean heavily on the formatter. I was mostly trying to be solve the problem practically.

I have no problems with NeoVim 0.8.1 atleast.

klarkc commented 1 year ago

Workaround for vim:

"{{ ~/.vimrc
function! PurescriptIndent()
  setlocal expandtab
  setlocal shiftwidth=2
  setlocal tabstop=2
endfunction

au BufRead,BufNewFile *.purs call PurescriptIndent()