diff options
| author | Eli Zaretskii | 2015-12-12 12:53:35 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-12-12 12:53:35 +0200 |
| commit | 5cc4f33b4ad0de0024c11ec41bcefcab34493efb (patch) | |
| tree | 179918cb0c05727a0e51a107644826488e13450b /doc | |
| parent | acae1834c619ad1a0c8db8b6421291070087a004 (diff) | |
| download | emacs-5cc4f33b4ad0de0024c11ec41bcefcab34493efb.tar.gz emacs-5cc4f33b4ad0de0024c11ec41bcefcab34493efb.zip | |
Document multi-mode indentation facilities
* doc/lispref/text.texi (Mode-Specific Indent): Document
'prog-indentation-context', 'prog-first-column', and 'prog-widen'.
* lisp/progmodes/prog-mode.el (prog-indentation-context)
(prog-widen): Doc fixes.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/text.texi | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 4d26638a94c..f3679a88f74 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -2362,6 +2362,84 @@ already indented, it calls @code{completion-at-point} to complete the | |||
| 2362 | text at point (@pxref{Completion in Buffers}). | 2362 | text at point (@pxref{Completion in Buffers}). |
| 2363 | @end defopt | 2363 | @end defopt |
| 2364 | 2364 | ||
| 2365 | @cindex literate programming | ||
| 2366 | @cindex multi-mode indentation | ||
| 2367 | Some major modes need to support embedded regions of text whose | ||
| 2368 | syntax belongs to a different major mode. Examples include | ||
| 2369 | @dfn{literate programming} source files that combine documentation and | ||
| 2370 | snippets of source code, Yacc/Bison programs that include snippets of | ||
| 2371 | plain C code, etc. To correctly indent the embedded chunks, the major | ||
| 2372 | mode needs to delegate the indentation to another mode's indentation | ||
| 2373 | engine (e.g., call @code{c-indent-defun} for C code or | ||
| 2374 | @code{python-indent-line} for Python), while providing it with some | ||
| 2375 | context to guide the indentation. The following facilities support | ||
| 2376 | such multi-mode indentation. | ||
| 2377 | |||
| 2378 | @defvar prog-indentation-context | ||
| 2379 | This variable, when non-@code{nil}, holds the indentation context for | ||
| 2380 | the sub-mode's indentation engine provided by the superior major mode. | ||
| 2381 | The value should be a list of the form @code{(@var{first-column} | ||
| 2382 | @w{(@var{start} . @var{end})} @code{prev-chunk})}. The members of the | ||
| 2383 | list have the following meaning: | ||
| 2384 | |||
| 2385 | @table @var | ||
| 2386 | @item first-column | ||
| 2387 | The column to be used for top-level constructs. This replaces the | ||
| 2388 | default value of the top-level column used by the sub-mode, usually | ||
| 2389 | zero. | ||
| 2390 | @item start | ||
| 2391 | @itemx end | ||
| 2392 | The region of the code chunk to be indented by the sub-mode. The | ||
| 2393 | value of @var{end} can be @code{nil}, which stands for the value of | ||
| 2394 | @code{point-max}. | ||
| 2395 | @item prev-chunk | ||
| 2396 | If this is non-@code{nil}, it should provide the sub-mode's | ||
| 2397 | indentation engine with a virtual context of the code chunk. Valid | ||
| 2398 | values include: | ||
| 2399 | |||
| 2400 | @itemize @minus | ||
| 2401 | @item | ||
| 2402 | A string whose contents is the text the sub-mode's indentation engine | ||
| 2403 | should consider to precede the code chunk. The sub-mode's indentation | ||
| 2404 | engine can add text properties to that string, to be reused in | ||
| 2405 | repeated calls with the same string, thus using it as a cache. An | ||
| 2406 | example where this is useful is code chunks that need to be indented | ||
| 2407 | as function bodies, but lack the function's preamble---the string | ||
| 2408 | could then include that missing preamble. | ||
| 2409 | @item | ||
| 2410 | A function. It is expected to be called with the start position of | ||
| 2411 | the current chunk, and should return a cons cell | ||
| 2412 | @w{@code{(@var{prev-start} . @var{prev-end})}} that specifies the | ||
| 2413 | region of the previous code chunk, or @code{nil} if there is no previous | ||
| 2414 | chunk. This is useful in literate-programming sources, where code is | ||
| 2415 | split into chunks, and correct indentation needs to access previous | ||
| 2416 | chunks. | ||
| 2417 | @end itemize | ||
| 2418 | @end table | ||
| 2419 | @end defvar | ||
| 2420 | |||
| 2421 | The following convenience functions should be used by major mode's | ||
| 2422 | indentation engine in support of invocations as sub-modes of another | ||
| 2423 | major mode. | ||
| 2424 | |||
| 2425 | @defun prog-first-column | ||
| 2426 | Call this function instead of using a literal value (usually, zero) of | ||
| 2427 | the column number for indenting top-level program constructs. The | ||
| 2428 | function's value is the column number to use for top-level constructs. | ||
| 2429 | When no superior mode is in effect, this function returns zero. | ||
| 2430 | @end defun | ||
| 2431 | |||
| 2432 | @defun prog-widen | ||
| 2433 | Call this function instead of @code{widen} to remove any restrictions | ||
| 2434 | imposed by the mode's indentation engine and restore the restrictions | ||
| 2435 | recorded in @code{prog-indentation-context}. This prevents the | ||
| 2436 | indentation engine of a sub-mode from inadvertently operating on text | ||
| 2437 | outside of the chunk it was supposed to indent, and preserves the | ||
| 2438 | restriction imposed by the superior mode. When no superior mode is in | ||
| 2439 | effect, this function just calls @code{widen}. | ||
| 2440 | @end defun | ||
| 2441 | |||
| 2442 | |||
| 2365 | @node Region Indent | 2443 | @node Region Indent |
| 2366 | @subsection Indenting an Entire Region | 2444 | @subsection Indenting an Entire Region |
| 2367 | 2445 | ||