aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/text.texi56
1 files changed, 10 insertions, 46 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 9592702ef1c..561ad804344 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -2397,57 +2397,31 @@ text at point (@pxref{Completion in Buffers}).
2397syntax belongs to a different major mode. Examples include 2397syntax belongs to a different major mode. Examples include
2398@dfn{literate programming} source files that combine documentation and 2398@dfn{literate programming} source files that combine documentation and
2399snippets of source code, Yacc/Bison programs that include snippets of 2399snippets of source code, Yacc/Bison programs that include snippets of
2400plain C code, etc. To correctly indent the embedded chunks, the major 2400Python or JS code, etc. To correctly indent the embedded chunks, the primary
2401mode needs to delegate the indentation to another mode's indentation 2401mode needs to delegate the indentation to another mode's indentation
2402engine (e.g., call @code{c-indent-defun} for C code or 2402engine (e.g., call @code{js-indent-line} for JS code or
2403@code{python-indent-line} for Python), while providing it with some 2403@code{python-indent-line} for Python), while providing it with some
2404context to guide the indentation. The following facilities support 2404context to guide the indentation. Major modes, for their part, should
2405such multi-mode indentation. 2405avoid calling @code{widen} in their indentation code and obey
2406@code{prog-first-column}.
2406 2407
2407@defvar prog-indentation-context 2408@defvar prog-indentation-context
2408This variable, when non-@code{nil}, holds the indentation context for 2409This variable, when non-@code{nil}, holds the indentation context for
2409the sub-mode's indentation engine provided by the superior major mode. 2410the sub-mode's indentation engine provided by the superior major mode.
2410The value should be a list of the form @code{(@var{first-column} 2411The value should be a list of the form @code{(@var{first-column} . @var{rest}}.
2411@w{(@var{start} . @var{end})} @code{prev-chunk})}. The members of the 2412The members of the list have the following meaning:
2412list have the following meaning:
2413 2413
2414@table @var 2414@table @var
2415@item first-column 2415@item first-column
2416The column to be used for top-level constructs. This replaces the 2416The column to be used for top-level constructs. This replaces the
2417default value of the top-level column used by the sub-mode, usually 2417default value of the top-level column used by the sub-mode, usually
2418zero. 2418zero.
2419@item start 2419@item rest
2420@itemx end 2420This value is currently unused.
2421The region of the code chunk to be indented by the sub-mode. The
2422value of @var{end} can be @code{nil}, which stands for the value of
2423@code{point-max}.
2424@item prev-chunk
2425If this is non-@code{nil}, it should provide the sub-mode's
2426indentation engine with a virtual context of the code chunk. Valid
2427values include:
2428
2429@itemize @minus
2430@item
2431A string whose contents is the text the sub-mode's indentation engine
2432should consider to precede the code chunk. The sub-mode's indentation
2433engine can add text properties to that string, to be reused in
2434repeated calls with the same string, thus using it as a cache. An
2435example where this is useful is code chunks that need to be indented
2436as function bodies, but lack the function's preamble---the string
2437could then include that missing preamble.
2438@item
2439A function. It is expected to be called with the start position of
2440the current chunk, and should return a cons cell
2441@w{@code{(@var{prev-start} . @var{prev-end})}} that specifies the
2442region of the previous code chunk, or @code{nil} if there is no previous
2443chunk. This is useful in literate-programming sources, where code is
2444split into chunks, and correct indentation needs to access previous
2445chunks.
2446@end itemize
2447@end table 2421@end table
2448@end defvar 2422@end defvar
2449 2423
2450The following convenience functions should be used by major mode's 2424The following convenience function should be used by major mode's
2451indentation engine in support of invocations as sub-modes of another 2425indentation engine in support of invocations as sub-modes of another
2452major mode. 2426major mode.
2453 2427
@@ -2458,16 +2432,6 @@ function's value is the column number to use for top-level constructs.
2458When no superior mode is in effect, this function returns zero. 2432When no superior mode is in effect, this function returns zero.
2459@end defun 2433@end defun
2460 2434
2461@defun prog-widen
2462Call this function instead of @code{widen} to remove any restrictions
2463imposed by the mode's indentation engine and restore the restrictions
2464recorded in @code{prog-indentation-context}. This prevents the
2465indentation engine of a sub-mode from inadvertently operating on text
2466outside of the chunk it was supposed to indent, and preserves the
2467restriction imposed by the superior mode. When no superior mode is in
2468effect, this function just calls @code{widen}.
2469@end defun
2470
2471 2435
2472@node Region Indent 2436@node Region Indent
2473@subsection Indenting an Entire Region 2437@subsection Indenting an Entire Region