Add an error check for correct formatting in Deflate uncompressed
[sgt/halibut] / misc / halibut.sl
CommitLineData
d7482997 1% Halibut mode for Jed.
2
3$1 = "Halibut";
4create_syntax_table ($1);
5
6define_syntax ("\#", "", '%', $1); % Comment Syntax
7define_syntax ('\\', '\\', $1); % Quote character
8define_syntax ("{", "}", '(', $1); % are all these needed?
9define_syntax ("a-zA-Z0-9", 'w', $1);
10set_syntax_flags ($1, 8);
11
12#ifdef HAS_DFA_SYNTAX
13%enable_highlight_cache ("halibut.dfa", $1);
14
15% A braced comment in Halibut is \#{ ... }, where ... may contain
16% any correctly nested sequence of braces. Of course we can't match
17% that in a DFA rule, so we'll go down to a reasonable depth of 3
18% instead.
19#ifexists dfa_define_highlight_rule
20dfa_define_highlight_rule ("\\\\#{[^{}]*({[^{}]*({[^}]*}[^{}]*)*}[^{}]*)*}",
21 "Qcomment", $1);
22
23dfa_define_highlight_rule ("\\\\#.*$", "comment", $1);
24dfa_define_highlight_rule ("^\\\\c([ \t].*)?$", "string", $1);
25dfa_define_highlight_rule ("\\\\[\\\\{}\\-_]", "keyword0", $1);
26dfa_define_highlight_rule ("\\\\[A-Za-tv-z][A-Za-z0-9]*", "keyword0", $1);
27dfa_define_highlight_rule ("\\\\u[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]",
28 "keyword0", $1);
29dfa_define_highlight_rule ("\\\\u[A-Fa-f0-9]?[A-Fa-f0-9]?[A-Fa-f0-9]?[A-Fa-f0-9]",
30 "keyword1", $1);
31dfa_define_highlight_rule ("[{}]", "delimiter", $1);
32dfa_define_highlight_rule (".", "normal", $1);
33dfa_build_highlight_table ($1);
34#else
35define_highlight_rule ("\\\\#{[^{}]*({[^{}]*({[^}]*}[^{}]*)*}[^{}]*)*}",
36 "Qcomment", $1);
37
38define_highlight_rule ("\\\\#.*$", "comment", $1);
39define_highlight_rule ("^\\\\c([ \t].*)?$", "string", $1);
40define_highlight_rule ("\\\\[\\\\{}\\-_]", "keyword0", $1);
41define_highlight_rule ("\\\\[A-Za-tv-z][A-Za-z0-9]*", "keyword0", $1);
42define_highlight_rule ("\\\\u[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]",
43 "keyword0", $1);
44define_highlight_rule ("\\\\u[A-Fa-f0-9]?[A-Fa-f0-9]?[A-Fa-f0-9]?[A-Fa-f0-9]",
45 "keyword1", $1);
46define_highlight_rule ("[{}]", "delimiter", $1);
47define_highlight_rule (".", "normal", $1);
48build_highlight_table ($1);
49#endif
50#endif
51
52% This hook identifies lines containing comments as paragraph separator
53define halibut_is_comment() {
54 bol ();
55 while (ffind ("\\\\#")) go_right (3);
56 ffind ("\\#"); % return value on stack
57}
58
59variable Halibut_Ignore_Comment = 0; % if true, line containing a comment
60 % does not delimit a paragraph
61
62define halibut_paragraph_separator() {
63 bol();
64 skip_white();
65 if (eolp())
66 return 1;
67 if (looking_at("\\c ") or looking_at("\\c\t") or
68 looking_at("\\c\n"))
69 return 1;
70 return not (Halibut_Ignore_Comment) and halibut_is_comment();
71}
72
73define halibut_wrap_hook() {
74 variable yep;
75 push_spot ();
76 yep = up_1 () and halibut_is_comment ();
77 pop_spot ();
78 if (yep) {
79 push_spot ();
80 bol_skip_white ();
81 insert ("\\# ");
82 pop_spot ();
83 }
84}
85
86#ifexists mode_set_mode_info
87mode_set_mode_info("Halibut", "fold_info", "\\# {{{\r\\# }}}\r\r");
88#endif
89
90define halibut_mode() {
91 variable mode = "Halibut";
92 % use_keymap (mode);
93 set_mode (mode, 0x1 | 0x20);
94 set_buffer_hook ("par_sep", "halibut_paragraph_separator");
95 set_buffer_hook ("wrap_hook", "halibut_wrap_hook");
96 use_syntax_table (mode);
97 runhooks ("halibut_mode_hook");
98}