1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-24 19:03:29 +00:00

Tweak how 'align' and 'align-regexp' align text

* lisp/align.el (align-rules-list): Change to work without `C-u'.
(align): Doc clarification.
(align-regexp): Ditto, and change default `C-u' regexp from
"\\(\\s-*\\)" to "\\(\\s-*\\)" so that it'll make things columnar
if the user just hits RET through all the defaults.
This commit is contained in:
Lars Ingebrigtsen 2021-10-19 22:39:00 +02:00
parent 0bb0fbee68
commit 90266b8356
2 changed files with 38 additions and 17 deletions

View File

@ -103,6 +103,15 @@ delimiter in the echo area.
* Changes in Specialized Modes and Packages in Emacs 29.1
** align
---
*** Alignment in 'text-mode' has changed.
Previously, 'M-x align' didn't do anything, and you have to say 'C-u
M-x align' for it to work. This has now been changed. The default
for regexp for 'C-u M-x align-regexp' has also been changed to be
easier for inexperienced users to use.
** eww
+++

View File

@ -553,8 +553,7 @@ The possible settings for `align-region-separate' are:
(modes . align-text-modes)
(repeat . t)
(run-if . ,(lambda ()
(and current-prefix-arg
(not (eq '- current-prefix-arg))))))
(not (eq '- current-prefix-arg)))))
;; With a negative prefix argument, lists of dollar figures will
;; be aligned.
@ -836,11 +835,22 @@ See the variable `align-exclude-rules-list' for more details.")
;;;###autoload
(defun align (beg end &optional separate rules exclude-rules)
"Attempt to align a region based on a set of alignment rules.
BEG and END mark the region. If BEG and END are specifically set to
nil (this can only be done programmatically), the beginning and end of
the current alignment section will be calculated based on the location
of point, and the value of `align-region-separate' (or possibly each
rule's `separate' attribute).
Interactively, BEG and END are the mark/point of the current region.
Many modes define specific alignment rules, and some of these
rules in some modes react to the current prefix argument. For
instance, in `text-mode', `M-x align' will align into columns
based on space delimiters, while `C-u - M-x align' will align
into columns based on the \"$\" character. See the
`align-rules-list' variable definition for the specific rules.
Also see `align-regexp', which will guide you through various
parameters for aligning text.
Non-interactively, if BEG and END are nil, the beginning and end
of the current alignment section will be calculated based on the
location of point, and the value of `align-region-separate' (or
possibly each rule's `separate' attribute).
If SEPARATE is non-nil, it overrides the value of
`align-region-separate' for all rules, except those that have their
@ -889,6 +899,15 @@ on the format of these lists."
BEG and END mark the limits of the region. Interactively, this function
prompts for the regular expression REGEXP to align with.
Interactively, if you specify a prefix argument, the function
will guide you through entering the full regular expression, and
then prompts for which subexpression parenthesis GROUP (default
1) within REGEXP to modify, the amount of SPACING (default
`align-default-spacing') to use, and whether or not to REPEAT the
rule throughout the line.
See `align-rules-list' for more information about these options.
For example, let's say you had a list of phone numbers, and wanted to
align them so that the opening parentheses would line up:
@ -908,15 +927,8 @@ regular expression after you enter it. Interactively, you only
need to supply the characters to be lined up, and any preceding
whitespace is replaced.
Non-interactively (or if you specify a prefix argument), you must
enter the full regular expression, including the subexpression.
Interactively, the function also then prompts for which
subexpression parenthesis GROUP (default 1) within REGEXP to
modify, the amount of SPACING (default `align-default-spacing')
to use, and whether or not to REPEAT the rule throughout the
line.
See `align-rules-list' for more information about these options.
Non-interactively, you must enter the full regular expression,
including the subexpression.
The non-interactive form of the previous example would look something like:
(align-regexp (point-min) (point-max) \"\\\\(\\\\s-*\\\\)(\")
@ -928,7 +940,7 @@ construct a rule to pass to `align-region', which does the real work."
(list (region-beginning) (region-end))
(if current-prefix-arg
(list (read-string "Complex align using regexp: "
"\\(\\s-*\\)" 'align-regexp-history)
"\\(\\s-*\\) " 'align-regexp-history)
(string-to-number
(read-string
"Parenthesis group to modify (justify if negative): " "1"))