Gedit, spell check and PHP syntax
Par Cyril le vendredi 26 août 2011, vers 15:34 - Ubuntu - Lien permanent
I've been using for a few years Gedit as editor of all my scripts, including bash scripts and PHP scripts. So I use it a lot...
For a while, it seems that spell check is broken. I noticed that when I upgraded to Ubuntu Natty. Here is the issue : When you are editing a PHP script (and PHP syntax highlight is chosen), the only words that are underlined if mispelled are in single-quoted or double-quoted strings. All other words, especially those which are outside php code, aren't checked (nor in heredoc text).
A few bugs are open : on Ubuntu Launchpad, Redhat Bugzilla and Debian bugreport, but I found no ready-to-use solution after googling a moment.
The syntax files of Gedit are in /usr/share/gtksourceview-2.0/language-specs/ (at least for me). Each one defines what is every portion of code (type like string, attribute, keyword, number...) and its properties. "no-spell-check" is one of the properties.
The problem in php.lang is at the last lines : all is defined as "no-spell-check" class (line 321, id "php"), that is all the script, including what is outside php code. The solution is pretty simple : define as "no-spell-check" only what is actually php code, line 291, id "php-block" and erase the "no-spell-check" class on line 321.
As I prefer to check heredoc texts, I had to proceed :
sudo sed -i -e '/id="here-doc-string"/s/>/ class-disabled="no-spell-check">/' -e '/id="php-block"/s/>/ class="no-spell-check">/' -e '/id="php"/s/ class="no-spell-check"//' /usr/share/gtksourceview-2.0/language-specs/php.lang
Bonus : in HTML highlighting, values of attributes are checked. I don't think it's relevant, so I changed that :
sudo sed -i '/attrib-value/s/ class-disabled="no-spell-check"//' /usr/share/gtksourceview-2.0/language-specs/html.lang
This is not perfect yet, as we would like to see the HTML outside php code like in HTML syntax highlight.