Wednesday, April 18, 2018

modeline: syntax or filetype?

Hei hei,

in the ptxdist project [1] we have files of type kconfig and make,
where the filetype is not detected by default, so since the very first
commits in the project vim modelines were used. Over time the options
used there evolved and are not consistent anymore:

% grep -h 'vim:' rules/*.make | sort | uniq
# vim: ft=make noet
# vim: ft=make noet ts=8 sw=8
# vim: ft=make ts=8 noet tw=80
# vim: ft=make ts=8 tw=80
# vim: syntax=make
# vim: syntax=make tabstop=8

% grep -h 'vim:' rules/*.in | sort | uniq
# vim: ft=kconfig noet tw=72
# vim: ft=kconfig ts=8 noet tw=80
# vim: set ft=kconfig:
# vim: set ft=kconfig sw=8 ts=8 noet:
# vim: set sw=8 ts=8 noet ft=kconfig:
# vim: set ts=8 sw=8 noet ft=kconfig:
# vim: syntax=kconfig

Before taking some effort to make this consistent again over existing
files and templates for new files, I wanted to ask about the
difference between 'syntax' and 'filetype'? From the documentation I
understood, filetype sets syntax and additional options. Also from
digging around I learned there is one set of definition files
distributed with Vim for filetype and another set for syntax, not
necessarily both for a given type of file? Can that cause problems,
e.g. if the modeline tries to set a filetype for which no definition
exists in the distributed Vim?

My problem with the current files: I have expandtab set in my personal
vimrc as a default. When I open a file called 'Makefile' Vim
recognizes it as filetype=make and automatically sets 'noexpandtab'
which you need in a makefile to not produce non working files.

Now with makefiles not automatically recognized by Vim (different
name/extension) this happens:

* Without modeline: ft=conf, expandtab can be anything: bad
* With modeline 'syntax=make': syntax highlighting correct, but
expandtab set, while noexpandtab would be needed: bad
* With modeline 'syntax=make noet': fine
* With modeline 'ft=make': fine

Now it seems to me, setting ft in the modeline would be better, but
can it have undesired side effects? Perhaps with options I did not
consider?

What would you recommend to set in the modeline in general? Does it
make sense to set 'syntax' instead of 'filetype'? Or should 'filetype'
be preferred, because the options would set things right, which are
maybe set unfavorable by e.g. vimrc?

Should 'noet' be set additionally to 'ft' or 'syntax' in case some
definition files for syntax and/or filetype are missing? Or rely on ft
only?

Thanks for reading and in the hope of some helpful reply
Alex

[1] https://www.ptxdist.org/

--
/"\ ASCII RIBBON | »With the first link, the chain is forged. The first
\ / CAMPAIGN | speech censured, the first thought forbidden, the
X AGAINST | first freedom denied, chains us all irrevocably.«
/ \ HTML MAIL | (Jean-Luc Picard, quoting Judge Aaron Satie)

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: