Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
.info and .make files use a unique format, similar to the INI file type. I found a syntax for the INI type here: http://www.vim.org/scripts/script.php?script_id=2475
After installing that syntax, (move the ini.vim file to the ~/.vim/syntax/ directory) I added the following two lines to my .vimrc file within the area that sets the .module, .inc. etc file types:
autocmd BufRead,BufNewFile *.make set filetype=ini
autocmd BufRead,BufNewFile *.info set filetype=ini
Wow, cool. Now Comments actually look commented out, and values are colored differently than their sections.
Comment | File | Size | Author |
---|---|---|---|
#22 | ini-syntax-1303122-22.patch | 9.6 KB | benjifisher |
#22 | syntaxcomplete.patch | 1.57 KB | benjifisher |
#31 | ini-syntax-1303122-31.patch | 13.33 KB | benjifisher |
#28 | ini-syntax-1303122-28.patch | 9.85 KB | benjifisher |
#24 | ini-syntax-1303122-24.patch | 9.75 KB | benjifisher |
Comments
Comment #1
nielsonm CreditAttribution: nielsonm commentedI made some tweaks to the original file, added a TODO syntax and highlighting group.
Comment #2
nielsonm CreditAttribution: nielsonm commentedForgot to add a contains statement.
Comment #3
benjifisherYou should update the header. We want to use it for *.info and not *.ini nor the others. Peter Hosey does not want to maintain a Drupal-specific file.
Drupal info files only allow "=", not ":", I think, so these lines can be simplified:
Does Drupal allow "#" for comments or just ";"?
I agree that it makes sense to use "ini" as the name of the syntax, but we might prefer to use "info".
The autocommands can go in
.vim/ftdetect/drupal.vim
so the user does not need to edit his or her vimrc file. See #1140306-5: Play nicely with other uses of Vim.Comment #4
benjifisherDespite my dislike of DOS, a much simpler solution is to use the "dosini" syntax file that is part of the standard vim distribution.
Comment #5
benjifisherAccording to http://drupal.org/node/625094, drush make files may have extension .build as well as .make. (Did you have something else in mind for .make?) To be on the safe side, we can restrict the autocommands to recognize .info files only if they are under a modules/ directory. Is there any similar restriction for drush make files?
Comment #6
skottler CreditAttribution: skottler commentedThis has been committed as part of #1140306: Play nicely with other uses of Vim.
Thanks!
Comment #7
nielsonm CreditAttribution: nielsonm commentedThere's now a GitHib repo for the files. https://github.com/nielsonm/Vim-Drupal-7-.info-syn
Comment #8
benjifisherIs this an improvement over the
syntax/dosini.vim
file in the standard vim distribution?Comment #9
nielsonm CreditAttribution: nielsonm commentedIt's an improvement on a different vim file. The dosini.vim file would have been another starting point, but this file is based off of a more basic ini.vim syntax file.
Comment #10
jessehsAh, I did not know about the dosini syntax.
This would be good to incorporate into the project's .vimrc since the syntax is available in any Vim installation out of the box:
I would like to see some more readability improvements that would be nice for .info and .make files though.
Specifically, how about coloring the first word of a line before the first set of brackets or the "=" symbol. Ex:
color1[color2][color2] = "color3"
Or maybe even make the brackets and/or quotes a different color:
color1[color2][color2] =
"
color3"
Comment #11
benjifisherI did not know about the dosini syntax, either, until I looked for it.
I already added
to
ftdetect/drupal.vim
. That is why this issue was marked as closed in #6. (Notice that we are no longer putting everything in a single vimrc file.)I am changing the status to "needs work." If you want to make improvements such as the ones suggested in #10, we can certainly define a new filetype (drupal-info or maybe drini ...). Then we could include your syntax file. (That is one of the advantages of not putting everything in one file.)
Here is an offer. If you can think of any features you would like to see implemented in an ftplugin for .info files, then I will implement them. If we have both an ftplugin and a syntax file, then it makes more sense to define a new filetype. So far, the only content in the
ftplugin/dosini.vim
included in the standard vim distro isI generally shy away from syntax files, but I suggest you have a look at the one for dosini. IMHO, it has simpler regexp's than yours.
I would still like answers to my questions in #5.
Comment #12
benjifisherAnother suggestion: if you add some keywords to the syntax file, then I can add
to the ftplugin file, and we will have auto-completion of keywords.
In fact, adding keywords would be a big improvement, because then you could highlight "core" as a keyword but leave the misspelled "nmae" uncolored in
Comment #13
jessehsExcellent idea with the keywords. Take a look at the profiler module, which does some pretty cool stuff with .info files. Here's an example .info file.
Here's a list of keywords to be highlighted in .info files if they are first in the line:
base
description
name
distribution_name
dependencies
theme
core
for the profiler api:
users
variables
nodes
terms
and for .make files:
api
projects
libraries
Comment #14
benjifisherThis is a work in progress, but it already works pretty well.
Please test and let me know if anything is not working. Except for syntax-based autocomplete, which seems to be broken. :-( Let me know if that is working (and your version of vim).
The name of the filetype is still open for discussion. I am working with drini: the "dr" as in "drush" and the "ini" as in "dosini", for example.
The point of my first TODO item is that certain things should be flagged as errors according to the Drupal coding standards, such as a name that does not start with a capital or a description that is not a full sentence. Dependencies can include version restrictions.
Comment #15
benjifisherHere is an updated version of the patch in #14. I am marking it "needs review" in the hope that someone will give it a spin, even though it still needs work. Syntax-based omnicomplete is still broken.
I rearranged the code in the hope of making it easier to follow. I fixed it so that something illegal like "7.9" will get no color in a line like
I also fixed it so that a dependencies line like
will have the version restrictions get WarningMsg highlighting. Depending on your color scheme, this may or may not stand out.
One reference in addition to those in #14:
If anyone wants to help with this, I have some questions:
base theme = garland
. Is this right, or do we just use "base" instead of "base theme"?Comment #16
kostajh CreditAttribution: kostajh commentedMy two cents, I don't think we should try to add Profiler support. It is an edge case and probably not worth the time.
It should be "base theme". Thanks!
Comment #17
benjifisherWell, Profiler support was requested in #13 above and I already added it. It just defines a few extra keywords, so it should not hurt when editing other .info files.
Thanks for confirming that "base theme" is correct. The current version should work correctly.
Comment #18
benjifisherAs I said in #14, the syntax-based autocompletion is broken. I wrote to the author, and he sent me a new version for testing. As soon as he uploads version 8.0 (or later) to http://www.vim.org/scripts/script.php?script_id=3172 you can grab that version, put it in
~/.vim/autoload/
and thenwill auto-complete to "dependencies".
Don't you love how responsive open-source developers are?
Comment #19
benjifisherThis version improves handling keywords ("core", "dependencies", etc.) when they are not the first word in a line.
I am getting better at git. I now have a branch for this issue.
Question: Which takes precedence, that strings can span lines or that ';' in the first column starts a comment line? In other words,
Comment #20
benjifisherI think this version is ready to commit. I just need someone to review it.
Changes since the previous patch:
By experiment, the answer to my question in #19 is that ";' does not start a comment if it is inside a string. Luckily, that is the way it is highlighted. (No change from previous version.)
Try installing this and open up your favorite .info file: Bartik, Corolla, Views, http://drupalcode.org/project/profiler_example.git/blob_plain/HEAD:/prof... . IMHO it works great.
Comment #21
skottler CreditAttribution: skottler commentedThis is working wonderfully for me! Great work @benjifisher.
Comment #22
benjifisherThanks, skottler.
Would you mind testing one more version? This should work just the same. I rearranged the code and added some comments. I hope it makes the file more readable, thus easier to maintain. (Rearranging vim
:syntax
commands can be tricky. I think the changes I made are safe.) I also changed some whitespace, removing hard tabs and lining up keywords.I have also attached a patch to
autoload/syntaxcomplete.vim
. (Credit goes to David Fishburn, author of the script.) In order to test autocompletion as described in #18 above, get version 7.0 of the script from the URL in #18 and apply the patch withand put the patched script in
~/.vim/autoload/
. (If you have vim 7.3, then you already have version 7.0 of syntaxcomplete.vim in your distro autoload directory.)Update: As of late 2012, version 10.0 is available from the URL in #18.
Comment #23
benjifisherActually, do not test just yet.
I looked into it some more, and I see that drupal_parse_info_file() (D6) and drupal_parse_info_format() (D7, D8) will accept almost anything as a key name.
Other themes and modules can add their own keys. For example, both the Zen theme (at least the D6 version) and the Conditional style module add the keyword
conditional-stylesheets
. So I should allow almost anything.Putting the keywords into the syntax file (as I already did) does have two advantages. First, it allows auto-completion with
<C-X><C-O>
. Second, it allows special checking for certain keywords. For example, I was looking at the codefilter module and I wondered why "Filter" was not highlighted inThen I realized that the uppercase "F" violated coding standards. Boy, do I feel smug.
I realized another thing from looking at the functions that parse info files. A semicolon (";") starts a comment if it is the first non-blank in a line (and not inside a string). It does not have to be in column 1. The D6 version of zen.info has many lines that start
;
, so I think the documentation should be changed to match the code, not vice versa.Comment #24
benjifisherThe attached patch addresses the issues I raised in #23 above. Please test it.
Try using strings for the right-hand side. They can span multiple lines.
Try funky things line putting the "=" on a separate line.
Test autocompletion as described in #18 and #22 above.
In short, try to break it. If you cannot, then I will commit the patch. :)
Comment #25
benjifisherBy the way, here are some things I noticed.
First,
base theme
is a valid key. I believe thatbase theme
(two spaces) is also valid, but would not be recognized as the same. It would be real hard to catch such a mistake, so maybe the syntax file should help you out. I want to move on, though.Second,
"foo \" bar"
is a single string. Good. But so is"foo \\" bar"
. At least, I think that is how it will be parsed. I believe that my syntax file is just as lazy as the code base on this point.Comment #26
jessehsNice work! I did find an issue with the "dependencies" syntax highlighting.
Try:
For me, the highlighting toggles on and off for each line.
Comment #27
jessehsThe Features module looks through the .info file for the key "features". Ex: features[user_permission][] = "administer nodes"
Can this be added to the syntax highlighting?
This brings up the issue that any module could add any number of keys like this. It's nice to have highlighted keywords for core keys, but it would be cool if the basic syntax highlighting was active even if the keys aren't found. So when the key isn't found, you'd still have something like:
foobar[foo][bar][] = baz
(The brackets and equals signs are a different color.)
If the key is found, that word should change to a different color, like in PHP where a function name changes a different color when it's a core PHP function like include_once().
This would maintain a nice looking file even when a non-standard key is used, and still give validation for the standard keys.
Comment #28
benjifisher@jessehs, thanks for testing.
Here is a version that solves the problem with dependencies (#26). I also noticed some oddities with description, and it deals with them better. (If you see something odd, try redrawing the screen with
<C-L>
.)While I was working on it, I had the same idea you mentioned in #27. I think I had all keys, core or custom, highlighted the same. Now they are different. For example, features will be highlighted as core in a theme file and as custom in a module file. (If vim fails to decide whether it is a theme or module file, then it will be highlighted like core.) I also changed the color for brackets.
Did you try the autocomplete feature?
Feel free to suggest other highlight groups from the ones I chose.
Comment #29
jessehsBenji,
This looks good. I haven't seen any problems with the syntax highlighting so far. I did not, however test out any autocomplete features of the patch. Perhaps that part of the patch should be split into a separate issue and await further testing before being committed?
Thanks for your work on this! It's super nice to have this feature!
Comment #30
benjifisherJesse,
I am inclined to leave in the autocomplete feature. It is a single local option set in
ftplugin/drini.vim
:By itself, this is pretty harmless. The tricky part is patching
autoload/syntaxcomplete.vim
, which is part of the standard vim distribution. I do not intend to do that automatically, just make the patch available on this page.It may be several days before I have time to update the documentation and commit the patch, so there is still time to convince me otherwise.
Comment #31
benjifisherI updated README.txt and doc/drupal.txt. I also rearranged the comments in ftplugin/drini.vim. Other than that, this is the same as the patch in #28. In particular, I left in the
'omnifunc'
setting, as I said in #30. In a minute, I will commit this patch to the project.Comment #32
benjifisherI forgot to mark the issue as fixed.