aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorMichael Albinus2023-10-16 09:02:39 +0200
committerMichael Albinus2023-10-16 09:02:39 +0200
commit2071904d5199c903c718d67fc9d47e6787f5114e (patch)
treee46d20787e4f3622b245146cdde20514dd14d611 /doc
parent36656ff70e3d8971117b0d25b2afd2727b09b098 (diff)
parent07c45f20fd3828548d5f0c110034e9857a94ccaf (diff)
downloademacs-2071904d5199c903c718d67fc9d47e6787f5114e.tar.gz
emacs-2071904d5199c903c718d67fc9d47e6787f5114e.zip
Merge from origin/emacs-29
07c45f20fd3 Fix test in files-tests 5d3f3288d22 ; * doc/emacs/search.texi (Regexp Backslash): Improve ind... 9525315c117 Add missing :version to two defcustoms 9044d4d94bb Fix a defcustom :type in eldoc.el 8141d73ea7f Document 'M-x align' in the Emacs manual
Diffstat (limited to 'doc')
-rw-r--r--doc/emacs/emacs.texi1
-rw-r--r--doc/emacs/indent.texi234
-rw-r--r--doc/emacs/search.texi2
3 files changed, 237 insertions, 0 deletions
diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi
index f9096557c24..da9696dfa4b 100644
--- a/doc/emacs/emacs.texi
+++ b/doc/emacs/emacs.texi
@@ -594,6 +594,7 @@ Indentation
594* Tab Stops:: Stop points for indentation in Text modes. 594* Tab Stops:: Stop points for indentation in Text modes.
595* Just Spaces:: Using only space characters for indentation. 595* Just Spaces:: Using only space characters for indentation.
596* Indent Convenience:: Optional indentation features. 596* Indent Convenience:: Optional indentation features.
597* Code Alignment:: Making common parts of lines start at the same column.
597 598
598Commands for Human Languages 599Commands for Human Languages
599 600
diff --git a/doc/emacs/indent.texi b/doc/emacs/indent.texi
index 17b663d22e1..0df973c1dd0 100644
--- a/doc/emacs/indent.texi
+++ b/doc/emacs/indent.texi
@@ -55,6 +55,7 @@ repositioned to the first non-whitespace character on the line.
55* Tab Stops:: Stop points for indentation in Text modes. 55* Tab Stops:: Stop points for indentation in Text modes.
56* Just Spaces:: Using only space characters for indentation. 56* Just Spaces:: Using only space characters for indentation.
57* Indent Convenience:: Optional indentation features. 57* Indent Convenience:: Optional indentation features.
58* Code Alignment:: Making common parts of lines start at the same column.
58@end menu 59@end menu
59 60
60@node Indentation Commands 61@node Indentation Commands
@@ -265,3 +266,236 @@ indents the line after every @key{RET} you type. This mode is enabled
265by default. To toggle this minor mode, type @kbd{M-x 266by default. To toggle this minor mode, type @kbd{M-x
266electric-indent-mode}. To toggle the mode in a single buffer, 267electric-indent-mode}. To toggle the mode in a single buffer,
267use @kbd{M-x electric-indent-local-mode}. 268use @kbd{M-x electric-indent-local-mode}.
269
270@node Code Alignment
271@section Code Alignment
272@cindex code alignment
273@cindex aligning code
274
275 @dfn{Alignment} is the process of adjusting whitespace in a sequence
276of lines in the region such that in all lines certain parts begin at
277the same column. This is usually something you do to enhance
278readability of a piece of text or code. The classic example is
279aligning a series of assignments in C-like programming languages:
280
281@example
282int a = 1;
283short foo = 2;
284double blah = 4;
285@end example
286
287@noindent
288is commonly aligned to:
289
290@example
291int a = 1;
292short foo = 2;
293double blah = 4;
294@end example
295
296@cindex alignment rules
297@findex align
298 You can use the command @kbd{M-x align} to align lines in the
299current region. This command knows about common alignment patterns
300across many markup and programming languages. It encodes these
301patterns as a set of @dfn{alignment rules}, that say how to align
302different kinds of text in different contexts.
303
304@vindex align-rules-list
305@vindex align-mode-rules-list
306The user option @code{align-rules-list} says which alignment rules
307@kbd{M-x align} should consult. The value of this option is a list
308with elements describing alignment rules. Each element is a cons cell
309@code{(@var{title} . @var{attributes})}, where @var{title} is the name
310of the alignment rule as a symbol, and @var{attributes} is a list of
311rule attributes that define when the rule should apply and how it
312partitions and aligns lines. Each rule attribute is a cons cell
313@code{(@var{attribute} . @var{value})}, where @var{attribute} is the
314name of attribute and @var{value} is its value. The only required
315attribute is @code{regexp}, whose value is a regular expression with
316sub-expressions matching the parts of each line where @kbd{M-x align}
317should expand or contract whitespace (@pxref{Regexp Backslash}). See
318the documentation string of @code{align-rules-list} (@kbd{C-h v
319align-rules-list @key{RET}}) for a full description of possible
320alignment rule attributes. By default, this option is set to a long
321list of alignment rules for many languages that Emacs supports. The
322default rules use the @code{modes} rule attribute to specify major
323modes in which @kbd{M-x align} should apply them. Major modes can
324also override @code{align-rules-list} by setting the buffer-local
325variable @code{align-mode-rules-list} to a non-@code{nil} list of
326alignment rules. When @code{align-mode-rules-list} is non-@code{nil},
327@kbd{M-x align} consults it instead of @code{align-rules-list}.
328
329@cindex align exclusion rules
330@vindex align-exclude-rules-list
331@vindex align-mode-exclude-rules-list
332Besides alignment rules, @kbd{M-x align} uses another kind of rules
333called @dfn{exclusion rules}. The exclusion rules say which parts in
334the region @kbd{M-x align} should not align and instead leave them
335intact. The user option @code{align-exclude-rules-list} specifies
336these exclusion rules. Similarly to @code{align-rules-list}, the
337value of @code{align-exclude-rules-list} is also a list of cons cells
338that describe the exclusion rules. By default,
339@code{align-exclude-rules-list} includes rules that exclude alignment
340in quoted strings and comments in Lisp, C and other languages. Beyond
341the default exclusion rules in @code{align-exclude-rules-list}, major
342modes can define bespoke exclusion rules by setting
343@code{align-mode-exclude-rules-list} to a non-@code{nil} list of
344rules, this overrides @code{align-exclude-rules-list} just like
345@code{align-mode-rules-list} overrides @code{align-rules-list}.
346
347@cindex alignment sections
348@vindex align-region-separate
349@kbd{M-x align} splits the region into a series of @dfn{sections},
350usually sequences of non-blank lines, and aligns each section
351according to all matching alignment rule by expanding or contracting
352stretches of whitespace. @kbd{M-x align} consistently aligns all
353lines inside a single section, but it may align different sections in
354the region differently. The user option @code{align-region-separate}
355specifies how @kbd{M-x align} separates the region to sections. This
356option can be one of the symbols @code{entire}, @code{group}, or a
357regular expression. If @code{align-region-separate} is @code{entire},
358Emacs aligns the entire region as a single section. If this option is
359@code{group}, Emacs aligns each group of consecutive non-blank lines
360in the region as a separate section. If @code{align-region-separate}
361is a regular expression, @kbd{M-x align} scans the region for matches
362to that regular expression and treats them as section separators. By
363default @code{align-region-separate} is set to a regular expression
364that matches blank lines and lines that contains only whitespace and a
365single curly brace (@samp{@{} or @samp{@}}). For special cases where
366regular expressions are not accurate enough, you can also set
367@code{align-region-separate} to a function that says how to separate
368the region to alignment sections. See the documentation string of
369@code{align-region-separate} for more details. Specific alignment
370rules can override the value of @code{align-region-separate} and
371define their own section separator by specifying the @code{separate}
372rule attribute.
373
374If you call @kbd{M-x align} with a prefix argument (@kbd{C-u}), it
375enables more alignment rules that are often useful but may sometimes
376be too intrusive. For example, in a Lisp buffer with the following
377form:
378
379@lisp
380(set-face-attribute 'mode-line-inactive nil
381 :box nil
382 :background nil
383 :underline "black")
384@end lisp
385
386@noindent
387Typing (@kbd{C-u M-x align}) yields:
388
389@lisp
390(set-face-attribute 'mode-line-inactive nil
391 :box nil
392 :background nil
393 :underline "black")
394@end lisp
395
396In most cases, you should try @kbd{M-x align} without a prefix
397argument first, and if that doesn't produce the right result you can
398undo with @kbd{C-/} and try again with @kbd{C-u M-x align}.
399
400@findex align-highlight-rule
401@findex align-unhighlight-rule
402You can use the command @kbd{M-x align-highlight-rule} to visualize
403the effect of a specific alignment or exclusion rule in the current
404region. This command prompts you for the title of a rule and
405highlights the parts on the region that this rule affects. For
406alignment rules, this command highlights the whitespace that @kbd{M-x
407align} would expand or contract, and for exclusion this command
408highlights the parts that @kbd{M-x align} would exclude from
409alignment. To remove the highlighting that this command creates, type
410@kbd{M-x align-unhighlight-rule}.
411
412@findex align-current
413@findex align-entire
414 The command @kbd{M-x align-current} is similar to @kbd{M-x align},
415except that it operates only on the alignment section that contains
416point regardless of the current region. This command determines the
417boundaries of the current section according to the section separators
418that @code{align-region-separate} define. @kbd{M-x align-entire} is
419another variant of @kbd{M-x align}, that disregards
420@code{align-region-separate} and aligns the entire region as a single
421alignment section with consistent alignment. If you set
422@code{align-region-separate} to @code{entire}, @kbd{M-x align} behaves
423like @kbd{M-x align-entire} by default. To illustrate the effect of
424aligning the entire region as a single alignment section, consider the
425following code:
426
427@example
428one = 1;
429foobarbaz = 2;
430
431spam = 3;
432emacs = 4;
433@end example
434
435@noindent
436when the region covers all of these lines, typing @kbd{M-x align}
437yields:
438
439@example
440one = 1;
441foobarbaz = 2;
442
443spam = 3;
444emacs = 4;
445@end example
446
447@noindent
448On the other hand, @kbd{M-x align-entire} aligns all of the lines as a
449single section, so the @samp{=} appears at the same column in all
450lines:
451
452@example
453one = 1;
454foobarbaz = 2;
455
456spam = 3;
457emacs = 4;
458@end example
459
460@findex align-regexp
461 The command @kbd{M-x align-regexp} lets you align the current region
462with an alignment rule that you define ad-hoc, instead of using the
463predefined rules in @code{align-rules-list}. @kbd{M-x align-regexp}
464prompts you for a regular expression and uses that expression as the
465@code{regexp} attribute for an ad-hoc alignment rule that this command
466uses to align the current region. By default, this command adjusts
467the whitespace that matches the first sub-expression of the regular
468expression you specify. If you call @kbd{M-x align-regexp} with a
469prefix argument, it also prompts you for the sub-expression to use and
470lets you specify the amount of whitespace to use as padding, as well
471as whether to apply the rule repeatedly to all matches of the regular
472expression in each line. @xref{Regexp Backslash}, for more
473information about regular expressions and their sub-expressions.
474
475@vindex align-indent-before-aligning
476 If the user option @code{align-indent-before-aligning} is
477non-@code{nil}, Emacs indents the region before aligning it with
478@kbd{M-x align}. @xref{Indentation}. By default
479@code{align-indent-before-aligning} is set to @code{nil}.
480
481@vindex align-to-tab-stop
482 The user option @code{align-to-tab-stop} says whether aligned parts
483should start at a tab stop (@pxref{Tab Stops}). If this option is
484@code{nil}, @kbd{M-x align} uses just enough whitespace for alignment,
485disregarding tab stops. If this is a non-@code{nil} symbol, @kbd{M-x
486align} checks the value of that symbol, and if this value is
487non-@code{nil}, @kbd{M-x align} aligns to tab stops. By default, this
488option is set to @code{indent-tabs-mode}, so alignment respects tab
489stops in buffers that use tabs for indentation. @xref{Just Spaces}.
490
491@vindex align-default-spacing
492 The user option @code{align-default-spacing} specifies the default
493amount of whitespace that @kbd{M-x align} and its related commands use
494for padding between the different parts of each line when aligning it.
495When @code{align-to-tab-stop} is @code{nil}, the value of
496@code{align-default-spacing} is the number of spaces to use for
497padding; when @code{align-to-tab-stop} is non-@code{nil}, the value of
498@code{align-default-spacing} is instead the number of tab stops to
499use. Each alignment rule can override the default that
500@code{align-default-spacing} specifies with the @code{spacing}
501attribute rule.
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index 6d8b3a2727a..a79176fcefb 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -1159,6 +1159,8 @@ surrounding @samp{\( @dots{} \)} grouping can limit the grouping power of
1159 1159
1160Full backtracking capability exists to handle multiple uses of @samp{\|}. 1160Full backtracking capability exists to handle multiple uses of @samp{\|}.
1161 1161
1162@cindex sub-expressions, in regular expressions
1163@cindex grouping, in regular expressions
1162@item \( @dots{} \) 1164@item \( @dots{} \)
1163is a grouping construct that serves three purposes: 1165is a grouping construct that serves three purposes:
1164 1166