aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorEli Zaretskii2015-12-12 12:53:35 +0200
committerEli Zaretskii2015-12-12 12:53:35 +0200
commit5cc4f33b4ad0de0024c11ec41bcefcab34493efb (patch)
tree179918cb0c05727a0e51a107644826488e13450b /doc
parentacae1834c619ad1a0c8db8b6421291070087a004 (diff)
downloademacs-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.texi78
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
2362text at point (@pxref{Completion in Buffers}). 2362text 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
2368syntax belongs to a different major mode. Examples include
2369@dfn{literate programming} source files that combine documentation and
2370snippets of source code, Yacc/Bison programs that include snippets of
2371plain C code, etc. To correctly indent the embedded chunks, the major
2372mode needs to delegate the indentation to another mode's indentation
2373engine (e.g., call @code{c-indent-defun} for C code or
2374@code{python-indent-line} for Python), while providing it with some
2375context to guide the indentation. The following facilities support
2376such multi-mode indentation.
2377
2378@defvar prog-indentation-context
2379This variable, when non-@code{nil}, holds the indentation context for
2380the sub-mode's indentation engine provided by the superior major mode.
2381The 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
2383list have the following meaning:
2384
2385@table @var
2386@item first-column
2387The column to be used for top-level constructs. This replaces the
2388default value of the top-level column used by the sub-mode, usually
2389zero.
2390@item start
2391@itemx end
2392The region of the code chunk to be indented by the sub-mode. The
2393value of @var{end} can be @code{nil}, which stands for the value of
2394@code{point-max}.
2395@item prev-chunk
2396If this is non-@code{nil}, it should provide the sub-mode's
2397indentation engine with a virtual context of the code chunk. Valid
2398values include:
2399
2400@itemize @minus
2401@item
2402A string whose contents is the text the sub-mode's indentation engine
2403should consider to precede the code chunk. The sub-mode's indentation
2404engine can add text properties to that string, to be reused in
2405repeated calls with the same string, thus using it as a cache. An
2406example where this is useful is code chunks that need to be indented
2407as function bodies, but lack the function's preamble---the string
2408could then include that missing preamble.
2409@item
2410A function. It is expected to be called with the start position of
2411the current chunk, and should return a cons cell
2412@w{@code{(@var{prev-start} . @var{prev-end})}} that specifies the
2413region of the previous code chunk, or @code{nil} if there is no previous
2414chunk. This is useful in literate-programming sources, where code is
2415split into chunks, and correct indentation needs to access previous
2416chunks.
2417@end itemize
2418@end table
2419@end defvar
2420
2421The following convenience functions should be used by major mode's
2422indentation engine in support of invocations as sub-modes of another
2423major mode.
2424
2425@defun prog-first-column
2426Call this function instead of using a literal value (usually, zero) of
2427the column number for indenting top-level program constructs. The
2428function's value is the column number to use for top-level constructs.
2429When no superior mode is in effect, this function returns zero.
2430@end defun
2431
2432@defun prog-widen
2433Call this function instead of @code{widen} to remove any restrictions
2434imposed by the mode's indentation engine and restore the restrictions
2435recorded in @code{prog-indentation-context}. This prevents the
2436indentation engine of a sub-mode from inadvertently operating on text
2437outside of the chunk it was supposed to indent, and preserves the
2438restriction imposed by the superior mode. When no superior mode is in
2439effect, 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