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

Make vim respect the tab width settings #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions indent/dune.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@
" Language: dune
" Maintainers: Markus Mottl <[email protected]>
" URL: https://github.com/ocaml/vim-ocaml
" Last Change: 2020 Dec 31
" Last Change: 2024 Nov 8 - Make vim respect the tab width settings (Stephen Sherratt)
" 2020 Dec 31

if exists("b:did_indent")
finish
endif
let b:did_indent = 1

" A rough approximation of the indentation behaviour implemented by
" `dune format-dune-file`.
function! DuneIndent()
let prev_line = getline(v:lnum - 1)
let prev_indent = indent(v:lnum - 1)
let current_indent = prev_indent
for i in range(len(prev_line))
if prev_line[i] == '('
let current_indent += &shiftwidth
endif
if prev_line[i] == ')'
let current_indent -= &shiftwidth
endif
endfor
return current_indent
endfunction

" dune format-dune-file uses 1 space to indent
setlocal softtabstop=1 shiftwidth=1 expandtab
" Explicitly set "lisp" since without this setting vim will not auto indent
" sexp files like dune files at all. When "lisp" is enabled, vim doesn't
" respect softtabstop or shiftwidth by default, so a custom indentexpr is
" needed.
setlocal softtabstop=1 shiftwidth=1 expandtab lisp indentexpr=DuneIndent() lispoptions=expr:1

let b:undo_indent = "setl et< sts< sw<"