/usr/share/doc/vile-common/modes.html is in vile-common 9.8s-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
$Id: modes.html,v 1.11 2013/12/27 21:02:05 tom Exp $
-->
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
<title>Major (and minor) modes in Vile</title>
<meta http-equiv="Content-Type" content=
"text/html; charset=us-ascii">
<link rev="made" href="mailto:dickey@invisible-island.net">
<link rel="SHORTCUT ICON" href="/img/icons/vile.ico" type=
"image/x-icon">
<link rel="stylesheet" href="/css/simplestyle.css" type=
"text/css">
</head>
<body>
<hr>
<a href="/">http://invisible-island.net/</a><a href=
"/vile/">vile/</a><a href="/vile/vile-toc.html">vile-toc</a><br>
<hr>
<h1 id="toplevel-toc"><a name="toplevel" id="toplevel">Major (and
minor) modes in Vile</a></h1>
<p>This document was originally written in May, 1998, and has
been updated periodically to reflect the proposed implementation
of and use of major modes in vile.</p>
<p>My goal was to extend the notion of the C mode (cmode) to
allow runtime definable major modes.</p>
<p>Originally, vile supported a C mode that included a collection
of modes useful for editing C program source:</p>
<ul>
<li>c-suffixes</li>
<li>c-tabstop</li>
<li>c-shiftwidth</li>
</ul>
<p>as well as this builtin functionality:</p>
<ul>
<li>autoindention of C statements taking into account curly
braces</li>
<li>fence matching for /*...*/ comments and C preprocessor
statements</li>
<li>comment formatting</li>
</ul>
<p>Both the modes and functionality are extensions of other
features in vile. It would be useful to combine modes to support
other languages in a similar fashion. Likewise, the
autoindention, etc., could be parameterized and made reusable to
support other languages. For an initial implementation, I focused
on the combining of modes, providing a structure for the
parameterization.</p>
<p>One thing that was not clear to many users was the manner in
which the C mode was attached to a buffer. It was set as a
boolean - if active before a buffer was loaded, then vile checked
the file suffix to see if it matched the c-suffixes mode, and if
so, set the C mode for the buffer. C mode could also be
explicitly set by a ":setl cmode", and unset by ":setl nocmode".
In the new scheme,</p>
<ul>
<li>vile searches the list of all active majormodes, first
testing if any match with the majormode's suffixes, then if any
preamble (first line regular expression) matches.
<p>The search is in normally alphabetic order, by majormode
name. The first match each, of suffixes and preamble
terminate the search, but a match of suffixes overrides a
match of preamble. Use "after" and "before" qualifiers to
handle special cases.</p>
<p>In rare circumstances, both suffixes and preamble are
needed to distinguish a given mode from another. Use
<!--{{atr2html--></p>
<p style="font-family: monospace;">
qualifiers=all<br>
<!--atr2html}}--></p>to specify this. The default,
"qualifiers=any", allows either suffixes or preamble to
determine the majormode.
<p>The suffixes and preamble rules can be overridden
altogether by specifying $majormode-hook to a script which
sets the majormode for the current buffer.</p>
</li>
<li>majormodes can be disabled (e.g., ":set nocmode"), as
before. However, there is no global sense of majormode;
unsetting a buffer's local value of a majormode simply makes it
not have a majormode associated with it.</li>
</ul>
<h2 id="neededcommands-toc"><a name="neededcommands" id=
"neededcommands">Commands</a></h2>
<p>These are the commands which I originally thought
necessary:</p>
<ul>
<li>define-majormode {majormode}</li>
<li>define-submode {majormode} {minormode}[={value}]</li>
<li>remove-majormode {majormode}</li>
<li>remove-submode {majormode} {minormode}</li>
<li>setl {majormode}</li>
<li>setl no{majormode}</li>
</ul>
<p>The {majormode} is a new symbol.</p>
<p>The {minormode} can be any one of the existing buffer modes,
except for a {majormode}. To make name-completion simple, we use
the term 'submode'.</p>
<p>Later, I added features to make majormodes simpler to
configure:</p>
<ul>
<li>"~with" in the scripting language prefixes text.</li>
<li>derive-majormode {newmode} {oldmode}</li>
</ul>
<h3 id="example-toc"><a name="example" id=
"example">Example</a></h3><!--{{atr2html-->
<p style="font-family: monospace;">
<strong><font color=
"#000080">define-majormode</font></strong> <strong><font color="#000080">c</font></strong><br>
<font color=
"#800000">; Declares a mode 'c', and corresponding symbol 'cmode'</font><br>
<br>
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">c</font></strong> <strong><font color="#000080">suffixes</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"\\.\\(\\([Cchisyl]\\)\\|CC\\|cc|cpp\\|cxx\\|hxx\\|scm\\)$"</font><br>
<font color=
"#800000">; Specifies the filename suffixes which control whether a newly-loaded</font><br>
<font color=
"#800000">; buffer is set to 'c' mode.</font><br>
<br>
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">c</font></strong> <strong><font color="#000080">tabstop</font></strong><strong><font color="#800000">=</font></strong><strong><font color="#008080">4</font></strong><br>
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">c</font></strong> <strong><font color="#000080">shiftwidth</font></strong><strong><font color="#800000">=</font></strong><strong><font color="#008080">4</font></strong><br>
<font color=
"#800000">; Defines the 'c' tabstop and shiftwidth. If no "define-submode"</font><br>
<font color=
"#800000">; command is given, no separate symbol is defined.</font><br>
<!--atr2html}}--></p>As an example, to define a new major mode
for perl programming, you might include the following in your
.vilerc file: <!--{{atr2html-->
<p style="font-family: monospace;">
<strong><font color=
"#000080">define-majormode</font></strong> <strong><font color="#000080">perl</font></strong><br>
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">perl</font></strong> <strong><font color="#000080">preamble</font></strong> <font color="#800080">"^#.*perl\\>"</font><br>
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">perl</font></strong> <strong><font color="#000080">suffixes</font></strong> <font color="#800080">'\.\(pm\|t\)$'</font><br>
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">perl</font></strong> <strong><font color="#000080">shiftwidth</font></strong> <strong><font color="#008080">4</font></strong><br>
<!--atr2html}}--></p>To avoid the tediousness of this syntax, use
the ~with and ~endwidth keywords, like so: <!--{{atr2html-->
<p style="font-family: monospace;">
<strong><font color=
"#000080">define-majormode</font></strong> <strong><font color="#000080">perl</font></strong><br>
<font color=
"#008000">~with</font> <strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">perl</font></strong><br>
<strong><font color="#000080">preamble</font></strong> <font color="#800080">"^#.*perl\\>"</font><br>
<strong><font color="#000080">suffixes</font></strong> <font color="#800080">'\.\(pm\|t\)$'</font><br>
<strong><font color="#000080">shiftwidth</font></strong> <strong><font color="#008080">4</font></strong><br>
<font color=
"#008000">~endwith</font><br>
<!--atr2html}}--></p>You can define several regions using ~with
and (after the first) ~elsewith blocks. Each block specifies a
set of tokens which are substituted at the beginning of each
line. Each ~elsewith block should have a group identifier to
distinguish it from the others. The reason for providing multiple
blocks is to implement complex fence-matching for different
language features.
<p>For example, in the definition of cshmode, the symbols
"fence-XXX" give patterns which vile can use to move the cursor
from one if/elif/else/fi marker to the next as you press "%". The
other settings such as "suf" in the first block are settings that
apply to the majormode itself: <!--{{atr2html--></p>
<p style="font-family: monospace;">
<strong><font color=
"#000080">define-mode</font></strong> <em>csh</em><br>
<font color=
"#008000">~with</font> <strong><font color=
"#000080">define-submode</font></strong> <em>csh</em><br>
<strong><font color="#000080">suf</font></strong> <font color="#800080">'\.\(csh[^/]*\|login\|logout\)$'</font><br>
<strong><font color="#000080">pre</font></strong> <font color="#800080">'^#!\s*\/.*csh\>\(\s*-[a-z]\+\)*\s*$'</font><br>
<strong><font color="#000080">filtername</font></strong> <font color="#800080">'vile-sh-filt -k csh'</font><br>
<strong><font color="#000080">comment-prefix</font></strong> <font color="#800080">'^\s*#'</font><br>
<strong><font color="#000080">comments</font></strong> <font color="#800080">'^\s*#\s*$'</font><br>
<strong><font color="#000080">fence-if</font></strong> <font color="#800080">'^\s*\<if\>.*\<then\>'</font><br>
<strong><font color="#000080">fence-elif</font></strong> <font color="#800080">'^\s*\<else\s*if\>'</font><br>
<strong><font color="#000080">fence-else</font></strong> <font color="#800080">'^\s*\<else\>'</font><br>
<strong><font color="#000080">fence-fi</font></strong> <font color="#800080">'^\s*\<endif\>'</font><br>
<font color=
"#008000">~elsewith</font> <strong><font color=
"#000080">define-submode</font></strong> <em>csh</em> <strong><font color="#000080">group</font></strong> <font color="#800080">'case'</font><br>
<strong><font color="#000080">fence-if</font></strong> <font color="#800080">'^\s*\<switch\>\s*(.*)'</font><br>
<strong><font color="#000080">fence-elif</font></strong> <font color="#800080">'^\s*\<case\>.*:'</font><br>
<strong><font color="#000080">fence-else</font></strong> <font color="#800080">'^\s*\<default\>\s*:'</font><br>
<strong><font color="#000080">fence-fi</font></strong> <font color="#800080">'^\s*\<endsw\>'</font><br>
<font color=
"#008000">~elsewith</font> <strong><font color=
"#000080">define-submode</font></strong> <em>csh</em> <strong><font color="#000080">group</font></strong> <font color="#800080">'loop'</font><br>
<strong><font color="#000080">fence-if</font></strong> <font color="#800080">'^\s*\<foreach\s\+.*\|while\>\s*(.*)'</font><br>
<strong><font color="#000080">fence-fi</font></strong> <font color="#800080">'^\s*\<end\>'</font><br>
<font color=
"#008000">~endwith</font><br>
<!--atr2html}}--></p>
<h3 id="definemajormode-toc"><a name="definemajormode" id=
"definemajormode">The "define-majormode" command</a></h3>
<p>This takes a single argument, a majormode name. To follow
existing convention, the string "mode" is automatically appended
to the given name. Associated modes are defined or modified with
the define-submode command. Vile maintains a list of majormodes.
Only one majormode can be associated with a buffer (none need be
associated). After definition, a majormode can be set or unset
just like any other buffer mode: <!--{{atr2html--></p>
<p style="font-family: monospace;">
<strong><font color=
"#000080">define-majormode</font></strong> <strong><font color="#000080">c</font></strong><br>
<font color=
"#800000">; defines "cmode"</font><br>
<br>
<strong><font color=
"#000080">setl</font></strong> <strong><font color=
"#000080">cmode</font></strong><br>
<font color=
"#800000">; sets the mode for the current buffer</font><br>
<br>
<strong><font color=
"#000080">setl</font></strong> <strong><font color=
"#000080">nocmode</font></strong><br>
<font color=
"#800000">; clear c mode (existing implementation)</font><br>
<br>
<strong><font color=
"#000080">unsetl</font></strong> <strong><font color=
"#000080">cmode</font></strong><br>
<font color=
"#800000">; clear c mode</font><br>
<!--atr2html}}--></p>The restriction to a single majormode is
because mode values are internally represented as structures with
a pointer. The pointer denotes which value (currently local or
global) is used. The majormode implementation adds a level to
this, e.g.,
<pre>
value -> self (local)
value -> global (global)
value -> major (majormode)
</pre>
<p>When a majormode is defined, an array of the existing minor
mode values is allocated, all pointing to the global modes. The
define-submode command modifies these to make them local
pointers. When a buffer is associated with a majormode, all of
its buffer mode values are pointed to the majormode's values. (To
keep the bookkeeping straight, modifying a global buffer mode
must also modify the copies of non-local buffer mode values).</p>
<h3 id="derivemajormode-toc"><a name="derivemajormode" id=
"derivemajormode">The "derive-majormode" command</a></h3>
<p>This is used to clone an existing majormode, using a new name.
The command takes two parameters:</p>
<ol>
<li>the new majormode name</li>
<li>the old majormode name, used as a source of settings</li>
</ol>
<p>If the new majormode already exists, it is not removed.
Instead, settings are copied from the old majormode into the
existing majormode. In principle, a series of these commands
could be used to merge several different majormodes.</p>
<h3 id="definesubmode-toc"><a name="definesubmode" id=
"definesubmode">The "define-submode" command</a></h3>
<p>This command sets local values of buffer modes for the given
majormode, e.g., <!--{{atr2html--></p>
<p style="font-family: monospace;">
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">c</font></strong> <strong><font color="#000080">autoindent</font></strong><br>
<!--atr2html}}--></p>The majormode name is required. The names
after the majormode name are names of buffer modes with a
corresponding value. Any number of modes can be specified in a
single command, e.g., <!--{{atr2html-->
<p style="font-family: monospace;">
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">c</font></strong> <strong><font color="#000080">autoindent</font></strong> <strong><font color="#000080">tabstop</font></strong><strong><font color="#800000">=</font></strong><strong><font color="#008080">4</font></strong><br>
<!--atr2html}}--></p>For each mode given, vile defines
corresponding names by which they can be referenced, e.g.,
"c-autoindent" (from the long mode name "autoindent") and "cai"
(from the short mode name "ai" for autoindent). The long mode
name is always appended with a hyphen, and the short mode name is
appended without a hyphen.
<p>The term "submode" is used in the command rather than the more
natural "minor mode" to simplify name-completion.</p>
<p>The following are keywords that aren't minor modes, but are
recognized solely by the define-submode command:</p>
<dl>
<dt>mode-pathname</dt>
<dd>The full pathname which is tested to trigger association
with a majormode, e.g., "RCS/*,v".</dd>
<dt>mode-filename</dt>
<dd>The filename which is tested to trigger association with a
majormode, e.g., "Makefile".</dd>
<dt>suffixes</dt>
<dd>The filename suffix which is tested to trigger association
with a majormode (e.g., c-suffixes) Note that since the default
value for the c-suffixes mode is a regular expression that will
match some other file types (C++ files, for instance), if you
define a new major mode for one of those suffixes you may want
to reset c-suffixes to something less inclusive.</dd>
<dt>preamble</dt>
<dd>Regular expression, matched against the beginning of a file
(the first line) used to trigger association with a majormode
(e.g., "^!#.*\/perl[^a-z]").</dd>
<dt>filtername</dt>
<dd>
A shell command telling which filter to call, and how to do
that. The form of the command is limited, since it is
interpreted for internal calls:
<pre>
{filter} {options}
</pre>
<p>where {filter} is the filename for the filter, e.g.,</p>
<pre>
vile-c-filt
</pre>
<p>and options include:</p>
<dl>
<dt>-k mode</dt>
<dd>The keyword filename, omitting ".keywords". For
instance, the C filter vile-c-filt is used for C, C++,
JavaScript and Java by changing the keyword file.</dd>
<dt>-q</dt>
<dd>Quit after loading the keyword definitions.</dd>
<dt>-t tabs</dt>
<dd>Set the tabstops, used in the imake filter to check for
coincidental matches between a tab and spaces that are the
same number of columns.</dd>
<dt>-v</dt>
<dt>-vv</dt>
<dd>Debug traces, mainly to show which keyword files are
loaded, and what information is parsed from them.</dd>
</dl>
<p>Other options may be implemented that are specific to a
filter program. For instance, vile-c-filt recognizes a -p
option to mark preprocessor lines with an error (used for
Java).</p>
</dd>
<dt>before</dt>
<dt>after</dt>
<dd>A string that tells vile how to rank the majormode.
Normally vile checks each mode in order by name, but there are
special cases where you may want to check one mode before
another. For example, the C++ majormode cppmode would be
checked after cmode, but that uses suffixes which are a subset
of the built-in cmode's suffixes and would not be found. So
cppmode is qualified before="c".</dd>
<dt>group</dt>
<dd>
followed by a name, defines an alternative set of submode
values.
<p>Currently used only for complex fences, this could be
applied to simple fences, and (with new flags not yet
defined) extend both styles of fences for indentation and
formatting.</p>
</dd>
<dt>fences</dt>
<dd>
These are "complex" fences, which are matched one expression
per line. The names are "fence-" followed by any of the
following keywords with a regular expression:
<pre>
if, elif, else, fi
</pre>
<p>Vile searches through all groups of complex fences for a
match before trying simple fences.</p>
</dd>
<dt>comments</dt>
<dd>These are "simple" fences, which can be matched any number
of times per line. The pairs need not appear on the same line.
Like complex fences, they have an implied order. The default
values support C-style comments, with the '%' going between
"/*" and "*/". The names use "fence-" followed any of the
following keywords with a regular expression: begin, end.</dd>
<dt>indent (not implemented)</dt>
<dd>The keyword "cstyle", or any of the following keywords with
a regular expression: begin, end, if, then, else, elif,
endif.</dd>
</dl>
<p>Other features which should be controlled by majormodes
include limiting the scope of the entab and detab commands.</p>
<h3 id="removemajormode-toc"><a name="removemajormode" id=
"removemajormode">The "remove-majormode" command</a></h3>
<p>This command has two forms:</p>
<dl>
<dt>remove-majormode {majormode}</dt>
<dd>This removes the definition of the majormode. Buffers that
were associated with the mode revert to no majormode.</dd>
</dl>
<p>or</p>
<dl>
<dt>remove-majormode {majormode} {name}</dt>
<dd>This removes the value of {name} from {majormode}, leaving
it set to the global value, if any.</dd>
</dl>
<h3 id="removesubmode-toc"><a name="removesubmode" id=
"removesubmode">The "remove-submode" command</a></h3>
<p>Remove the special association of a submode from a
majormode.</p>
<h3 id="example2-toc"><a name="example2" id=
"example2">Example</a></h3>
<p>The original builtin C/C++ majormode description is equivalent
to <!--{{atr2html--></p>
<p style="font-family: monospace;">
<strong><font color=
"#000080">define-mode</font></strong> <strong><font color=
"#000080">c</font></strong><br>
<font color=
"#008000">~with</font> <strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">c</font></strong><br>
<strong><font color="#000080">suffix</font></strong> <font color="#800080">"\\.\\(\\([Cchisyl]\\)\\|CC\\|cc|cpp\\|cxx\\|hxx\\|scm\\)$"</font><br>
<strong><font color="#000080">comment-prefix</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"^\\s*\\(\\s*[#*>]\\)\\+"</font><br>
<strong><font color="#000080">comments</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"^\\s*/\\?\\(\\s*[#*>]\\)\\+/\\?\\s*$"</font><br>
<strong><font color="#000080">fence-begin</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"/\\*"</font><br>
<strong><font color="#000080">fence-end</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"\\*/"</font><br>
<strong><font color="#000080">fence-if</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"^\\s*#\\s*if"</font><br>
<strong><font color="#000080">fence-elif</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"^\\s*#\\s*elif\\>"</font><br>
<strong><font color="#000080">fence-else</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"^\\s*#\\s*else\\>"</font><br>
<strong><font color="#000080">fence-fi</font></strong><strong><font color="#800000">=</font></strong><font color="#800080">"^\\s*#\\s*endif\\>"</font><br>
<strong><font color="#000080">cindent</font></strong><br>
<font color=
"#008000">~endwith</font><br>
<!--atr2html}}--></p>Note that the following are equivalent once
you have defined the majormode "c": <!--{{atr2html-->
<p style="font-family: monospace;">
<strong><font color=
"#000080">set</font></strong> <strong><font color=
"#000080">cts</font></strong><strong><font color=
"#800000">=</font></strong><strong><font color=
"#008080">8</font></strong><br>
<strong><font color=
"#000080">set</font></strong> <strong><font color=
"#000080">c-tabstop</font></strong><strong><font color=
"#800000">=</font></strong><strong><font color=
"#008080">8</font></strong><br>
<strong><font color=
"#000080">define-submode</font></strong> <strong><font color="#000080">c</font></strong> <strong><font color="#000080">tabstop</font></strong><strong><font color="#800000">=</font></strong><strong><font color="#008080">8</font></strong><br>
<!--atr2html}}--></p>
<h2 id="credits-toc"><a name="credits" id=
"credits">Credits</a></h2>Most of this was written by Thomas
Dickey, with fixes from Clark Morgan and Steven Lembark.
</body>
</html>
|