My company uses a version of Perl where you can define by binary number using something like my $var = 'b010110110;
etc. Problem is both perl-mode
and cperl-mode
interpret '
as the start of the string and will apply a string font lock to everything until the next '
. This causes large sections of code are to appear as a string when they are not.
I have looked into how Emacs defines strings, and it does not have a string start
or string end
syntax class. Rather it just has a string quote character
syntax class of which both "
and '
are members of in Perl modes.
I have modified the syntax table to changed the '
character from the string quote character
class to the punctuation character
class. This fixes the problems of stringifying blocks of code but normal strings quoted with '
are no longer recognized.
I need a really smart person who can show me some code to modify the syntax highlighting of Perl so that strings are recognized as strings and binary notation is recognized as binary notation. How can I accomplish this?
syntax-propertize-function
is a way to set up custom rules for applying text properties.0b
as a prefix, seeperldoc perlnumber
. I am not sure why you need to use a single quote instead of0b
?'b
as well (probably because it is really old) and all of our Perl files use'b
. So I have to find someone to correct for this. I can't go through all our repo's and change it.syntax-propertize-function
and I was able to add addition rule tosyntax-propertize-rules
that makes things work correctly. Now the question is, how do I add it to myperl-mode
? (I was hacking the source file directly) Is there a hook or something?perl-mode-hook
. Generally, every properly defined mode (read: viadefine-derived-mode
) offers a variable named as the mode with-hook
appended to it after its definition. Feel free to self-answer this question with the code involved!