Add "Indentation from Makefile" to docs
dch opened this issue · 4 comments
Indentation from a Makefile
This snippet as a make target will re-indent all src/*.?rl files for you.
reindent:
@# requires either vim 7.4, or github.com/vim-erlang/vim-erlang-runtime
@# add -c ':set runtimepath^=~/v/.vim/bundle/vim-erlang-runtime/' if less
vim -E -N --noplugin -u /dev/null -c ':filetype plugin indent on' \
-c ':args src/*.?rl' \
-c 'argdo silent execute "normal gg=G"' \
-c 'update' -c q
Thanks. What do you mean by "add -c ':set runtimepath^=~/v/.vim/bundle/vim-erlang-runtime/' if less"?
@hcs42 sorry!
I mean that if your vim is < 7.4, then IIRC it won't have the indenting rules that this repo includes, and therefore you'll need to include this repo into your vimpath, like so:
From the terminal you can then do (all in one go!):
vim -E -N --noplugin -u /dev/null -c ':filetype plugin indent on' \
-c ':set runtimepath^=~/v/.vim/bundle/vim-erlang-runtime/' if less
-c ':args src/*.?rl' \
-c 'argdo silent execute "normal gg=G"' \
-c 'update' -c q
@dch: This is my proposal to add to README:
Tip: indentation from the command line
The following snippet re-indents all
src/*.?rlfiles using the indentation shipped with Vim:vim -ENn -u NONE \ -c 'filetype plugin indent on' \ -c 'set expandtab shiftwidth=4' \ -c 'args src/*.?rl' \ -c 'argdo silent execute "normal gg=G" | update' \ -c qNotes:
This can be for example added to a Makefile as a "re-indent rule".
You can use the
expandtab,shiftwidthandtabstopoptions to customize
how to use space and tab characters. The command above uses only spaces, and
one level of indentation is 4 spaces.If you would like to use a different version of the indentation script from
that one shipped in Vim (e.g. because you have Vim 7.3), then also add the
following as the first command paramter:-c ':set runtimepath^=~/.vim/bundle/vim-erlang-runtime/'
Changes from the original one:
- I phrased it as a shell command instead of a Makefile rule. Since we don't use anything Makefile-specific, I think this gives a more clear first impression of what this command actually is (a shell call, as opposed to a Makefile rule). Also, I'm not sure I would encourage using it as a Makefile-rule, since the indentation is not perfect (see the type specs for example...)
:consistently skipped in-carguments.- Custom runtimepath moved into a note.
-nadded (no swap file).-u NONEinstead of--noplugin -u /dev/null. From:help -u: "When {vimrc} is equal to "NONE" (all uppercase), all initializations from files and environment variables are skipped, including reading the |gvimrc| file when the GUI starts. Loading plugins is also skipped."updatemoved into argdo. Otherwise for me it saved only the last file and complained that the others are not saved.- I added a command and a note about
expandtab,shiftwidthandtabstop.
What do you think?
