diff options
| author | Michael Albinus | 2023-10-16 09:02:39 +0200 |
|---|---|---|
| committer | Michael Albinus | 2023-10-16 09:02:39 +0200 |
| commit | 2071904d5199c903c718d67fc9d47e6787f5114e (patch) | |
| tree | e46d20787e4f3622b245146cdde20514dd14d611 /doc | |
| parent | 36656ff70e3d8971117b0d25b2afd2727b09b098 (diff) | |
| parent | 07c45f20fd3828548d5f0c110034e9857a94ccaf (diff) | |
| download | emacs-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.texi | 1 | ||||
| -rw-r--r-- | doc/emacs/indent.texi | 234 | ||||
| -rw-r--r-- | doc/emacs/search.texi | 2 |
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 | ||
| 598 | Commands for Human Languages | 599 | Commands 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 | |||
| 265 | by default. To toggle this minor mode, type @kbd{M-x | 266 | by default. To toggle this minor mode, type @kbd{M-x |
| 266 | electric-indent-mode}. To toggle the mode in a single buffer, | 267 | electric-indent-mode}. To toggle the mode in a single buffer, |
| 267 | use @kbd{M-x electric-indent-local-mode}. | 268 | use @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 | ||
| 276 | of lines in the region such that in all lines certain parts begin at | ||
| 277 | the same column. This is usually something you do to enhance | ||
| 278 | readability of a piece of text or code. The classic example is | ||
| 279 | aligning a series of assignments in C-like programming languages: | ||
| 280 | |||
| 281 | @example | ||
| 282 | int a = 1; | ||
| 283 | short foo = 2; | ||
| 284 | double blah = 4; | ||
| 285 | @end example | ||
| 286 | |||
| 287 | @noindent | ||
| 288 | is commonly aligned to: | ||
| 289 | |||
| 290 | @example | ||
| 291 | int a = 1; | ||
| 292 | short foo = 2; | ||
| 293 | double 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 | ||
| 299 | current region. This command knows about common alignment patterns | ||
| 300 | across many markup and programming languages. It encodes these | ||
| 301 | patterns as a set of @dfn{alignment rules}, that say how to align | ||
| 302 | different kinds of text in different contexts. | ||
| 303 | |||
| 304 | @vindex align-rules-list | ||
| 305 | @vindex align-mode-rules-list | ||
| 306 | The 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 | ||
| 308 | with elements describing alignment rules. Each element is a cons cell | ||
| 309 | @code{(@var{title} . @var{attributes})}, where @var{title} is the name | ||
| 310 | of the alignment rule as a symbol, and @var{attributes} is a list of | ||
| 311 | rule attributes that define when the rule should apply and how it | ||
| 312 | partitions and aligns lines. Each rule attribute is a cons cell | ||
| 313 | @code{(@var{attribute} . @var{value})}, where @var{attribute} is the | ||
| 314 | name of attribute and @var{value} is its value. The only required | ||
| 315 | attribute is @code{regexp}, whose value is a regular expression with | ||
| 316 | sub-expressions matching the parts of each line where @kbd{M-x align} | ||
| 317 | should expand or contract whitespace (@pxref{Regexp Backslash}). See | ||
| 318 | the documentation string of @code{align-rules-list} (@kbd{C-h v | ||
| 319 | align-rules-list @key{RET}}) for a full description of possible | ||
| 320 | alignment rule attributes. By default, this option is set to a long | ||
| 321 | list of alignment rules for many languages that Emacs supports. The | ||
| 322 | default rules use the @code{modes} rule attribute to specify major | ||
| 323 | modes in which @kbd{M-x align} should apply them. Major modes can | ||
| 324 | also override @code{align-rules-list} by setting the buffer-local | ||
| 325 | variable @code{align-mode-rules-list} to a non-@code{nil} list of | ||
| 326 | alignment 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 | ||
| 332 | Besides alignment rules, @kbd{M-x align} uses another kind of rules | ||
| 333 | called @dfn{exclusion rules}. The exclusion rules say which parts in | ||
| 334 | the region @kbd{M-x align} should not align and instead leave them | ||
| 335 | intact. The user option @code{align-exclude-rules-list} specifies | ||
| 336 | these exclusion rules. Similarly to @code{align-rules-list}, the | ||
| 337 | value of @code{align-exclude-rules-list} is also a list of cons cells | ||
| 338 | that describe the exclusion rules. By default, | ||
| 339 | @code{align-exclude-rules-list} includes rules that exclude alignment | ||
| 340 | in quoted strings and comments in Lisp, C and other languages. Beyond | ||
| 341 | the default exclusion rules in @code{align-exclude-rules-list}, major | ||
| 342 | modes can define bespoke exclusion rules by setting | ||
| 343 | @code{align-mode-exclude-rules-list} to a non-@code{nil} list of | ||
| 344 | rules, 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}, | ||
| 350 | usually sequences of non-blank lines, and aligns each section | ||
| 351 | according to all matching alignment rule by expanding or contracting | ||
| 352 | stretches of whitespace. @kbd{M-x align} consistently aligns all | ||
| 353 | lines inside a single section, but it may align different sections in | ||
| 354 | the region differently. The user option @code{align-region-separate} | ||
| 355 | specifies how @kbd{M-x align} separates the region to sections. This | ||
| 356 | option can be one of the symbols @code{entire}, @code{group}, or a | ||
| 357 | regular expression. If @code{align-region-separate} is @code{entire}, | ||
| 358 | Emacs aligns the entire region as a single section. If this option is | ||
| 359 | @code{group}, Emacs aligns each group of consecutive non-blank lines | ||
| 360 | in the region as a separate section. If @code{align-region-separate} | ||
| 361 | is a regular expression, @kbd{M-x align} scans the region for matches | ||
| 362 | to that regular expression and treats them as section separators. By | ||
| 363 | default @code{align-region-separate} is set to a regular expression | ||
| 364 | that matches blank lines and lines that contains only whitespace and a | ||
| 365 | single curly brace (@samp{@{} or @samp{@}}). For special cases where | ||
| 366 | regular expressions are not accurate enough, you can also set | ||
| 367 | @code{align-region-separate} to a function that says how to separate | ||
| 368 | the region to alignment sections. See the documentation string of | ||
| 369 | @code{align-region-separate} for more details. Specific alignment | ||
| 370 | rules can override the value of @code{align-region-separate} and | ||
| 371 | define their own section separator by specifying the @code{separate} | ||
| 372 | rule attribute. | ||
| 373 | |||
| 374 | If you call @kbd{M-x align} with a prefix argument (@kbd{C-u}), it | ||
| 375 | enables more alignment rules that are often useful but may sometimes | ||
| 376 | be too intrusive. For example, in a Lisp buffer with the following | ||
| 377 | form: | ||
| 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 | ||
| 387 | Typing (@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 | |||
| 396 | In most cases, you should try @kbd{M-x align} without a prefix | ||
| 397 | argument first, and if that doesn't produce the right result you can | ||
| 398 | undo with @kbd{C-/} and try again with @kbd{C-u M-x align}. | ||
| 399 | |||
| 400 | @findex align-highlight-rule | ||
| 401 | @findex align-unhighlight-rule | ||
| 402 | You can use the command @kbd{M-x align-highlight-rule} to visualize | ||
| 403 | the effect of a specific alignment or exclusion rule in the current | ||
| 404 | region. This command prompts you for the title of a rule and | ||
| 405 | highlights the parts on the region that this rule affects. For | ||
| 406 | alignment rules, this command highlights the whitespace that @kbd{M-x | ||
| 407 | align} would expand or contract, and for exclusion this command | ||
| 408 | highlights the parts that @kbd{M-x align} would exclude from | ||
| 409 | alignment. 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}, | ||
| 415 | except that it operates only on the alignment section that contains | ||
| 416 | point regardless of the current region. This command determines the | ||
| 417 | boundaries of the current section according to the section separators | ||
| 418 | that @code{align-region-separate} define. @kbd{M-x align-entire} is | ||
| 419 | another variant of @kbd{M-x align}, that disregards | ||
| 420 | @code{align-region-separate} and aligns the entire region as a single | ||
| 421 | alignment section with consistent alignment. If you set | ||
| 422 | @code{align-region-separate} to @code{entire}, @kbd{M-x align} behaves | ||
| 423 | like @kbd{M-x align-entire} by default. To illustrate the effect of | ||
| 424 | aligning the entire region as a single alignment section, consider the | ||
| 425 | following code: | ||
| 426 | |||
| 427 | @example | ||
| 428 | one = 1; | ||
| 429 | foobarbaz = 2; | ||
| 430 | |||
| 431 | spam = 3; | ||
| 432 | emacs = 4; | ||
| 433 | @end example | ||
| 434 | |||
| 435 | @noindent | ||
| 436 | when the region covers all of these lines, typing @kbd{M-x align} | ||
| 437 | yields: | ||
| 438 | |||
| 439 | @example | ||
| 440 | one = 1; | ||
| 441 | foobarbaz = 2; | ||
| 442 | |||
| 443 | spam = 3; | ||
| 444 | emacs = 4; | ||
| 445 | @end example | ||
| 446 | |||
| 447 | @noindent | ||
| 448 | On the other hand, @kbd{M-x align-entire} aligns all of the lines as a | ||
| 449 | single section, so the @samp{=} appears at the same column in all | ||
| 450 | lines: | ||
| 451 | |||
| 452 | @example | ||
| 453 | one = 1; | ||
| 454 | foobarbaz = 2; | ||
| 455 | |||
| 456 | spam = 3; | ||
| 457 | emacs = 4; | ||
| 458 | @end example | ||
| 459 | |||
| 460 | @findex align-regexp | ||
| 461 | The command @kbd{M-x align-regexp} lets you align the current region | ||
| 462 | with an alignment rule that you define ad-hoc, instead of using the | ||
| 463 | predefined rules in @code{align-rules-list}. @kbd{M-x align-regexp} | ||
| 464 | prompts you for a regular expression and uses that expression as the | ||
| 465 | @code{regexp} attribute for an ad-hoc alignment rule that this command | ||
| 466 | uses to align the current region. By default, this command adjusts | ||
| 467 | the whitespace that matches the first sub-expression of the regular | ||
| 468 | expression you specify. If you call @kbd{M-x align-regexp} with a | ||
| 469 | prefix argument, it also prompts you for the sub-expression to use and | ||
| 470 | lets you specify the amount of whitespace to use as padding, as well | ||
| 471 | as whether to apply the rule repeatedly to all matches of the regular | ||
| 472 | expression in each line. @xref{Regexp Backslash}, for more | ||
| 473 | information 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 | ||
| 477 | non-@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 | ||
| 483 | should 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, | ||
| 485 | disregarding tab stops. If this is a non-@code{nil} symbol, @kbd{M-x | ||
| 486 | align} checks the value of that symbol, and if this value is | ||
| 487 | non-@code{nil}, @kbd{M-x align} aligns to tab stops. By default, this | ||
| 488 | option is set to @code{indent-tabs-mode}, so alignment respects tab | ||
| 489 | stops 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 | ||
| 493 | amount of whitespace that @kbd{M-x align} and its related commands use | ||
| 494 | for padding between the different parts of each line when aligning it. | ||
| 495 | When @code{align-to-tab-stop} is @code{nil}, the value of | ||
| 496 | @code{align-default-spacing} is the number of spaces to use for | ||
| 497 | padding; 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 | ||
| 499 | use. Each alignment rule can override the default that | ||
| 500 | @code{align-default-spacing} specifies with the @code{spacing} | ||
| 501 | attribute 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 | ||
| 1160 | Full backtracking capability exists to handle multiple uses of @samp{\|}. | 1160 | Full 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{} \) |
| 1163 | is a grouping construct that serves three purposes: | 1165 | is a grouping construct that serves three purposes: |
| 1164 | 1166 | ||