aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/align.el
diff options
context:
space:
mode:
authorGlenn Morris2013-07-25 22:45:15 -0400
committerGlenn Morris2013-07-25 22:45:15 -0400
commit8358a09d4f1e7e26bec6f72c267fd2b931d00c19 (patch)
treecedcc8b9e2c86cc201146cdfbfb662dd5665196b /lisp/align.el
parent15ac32d5284476d27dd40bd238c3bab633081aee (diff)
downloademacs-8358a09d4f1e7e26bec6f72c267fd2b931d00c19.tar.gz
emacs-8358a09d4f1e7e26bec6f72c267fd2b931d00c19.zip
* lisp/align.el (align-regexp): Doc fix.
(align-region): Explicit error if subexpression missing/does not match. Fixes: debbugs:14857
Diffstat (limited to 'lisp/align.el')
-rw-r--r--lisp/align.el39
1 files changed, 28 insertions, 11 deletions
diff --git a/lisp/align.el b/lisp/align.el
index 1b62042be75..3d2ca192245 100644
--- a/lisp/align.el
+++ b/lisp/align.el
@@ -906,15 +906,8 @@ on the format of these lists."
906;;;###autoload 906;;;###autoload
907(defun align-regexp (beg end regexp &optional group spacing repeat) 907(defun align-regexp (beg end regexp &optional group spacing repeat)
908 "Align the current region using an ad-hoc rule read from the minibuffer. 908 "Align the current region using an ad-hoc rule read from the minibuffer.
909BEG and END mark the limits of the region. This function will prompt 909BEG and END mark the limits of the region. Interactively, this function
910for the REGEXP to align with. If no prefix arg was specified, you 910prompts for the regular expression REGEXP to align with.
911only need to supply the characters to be lined up and any preceding
912whitespace is replaced. If a prefix arg was specified, the full
913regexp with parenthesized whitespace should be supplied; it will also
914prompt for which parenthesis GROUP within REGEXP to modify, the amount
915of SPACING to use, and whether or not to REPEAT the rule throughout
916the line. See `align-rules-list' for more information about these
917options.
918 911
919For example, let's say you had a list of phone numbers, and wanted to 912For example, let's say you had a list of phone numbers, and wanted to
920align them so that the opening parentheses would line up: 913align them so that the opening parentheses would line up:
@@ -925,8 +918,29 @@ align them so that the opening parentheses would line up:
925 Joe (123) 456-7890 918 Joe (123) 456-7890
926 919
927There is no predefined rule to handle this, but you could easily do it 920There is no predefined rule to handle this, but you could easily do it
928using a REGEXP like \"(\". All you would have to do is to mark the 921using a REGEXP like \"(\". Interactively, all you would have to do is
929region, call `align-regexp' and type in that regular expression." 922to mark the region, call `align-regexp' and enter that regular expression.
923
924REGEXP must contain at least one parenthesized subexpression, typically
925whitespace of the form \"\\\\(\\\\s-*\\\\)\". In normal interactive use,
926this is automatically added to the start of your regular expression after
927you enter it. You only need to supply the characters to be lined up, and
928any preceding whitespace is replaced.
929
930If you specify a prefix argument (or use this function non-interactively),
931you must enter the full regular expression, including the subexpression.
932The function also then prompts for which subexpression parenthesis GROUP
933\(default 1) within REGEXP to modify, the amount of SPACING (default
934`align-default-spacing') to use, and whether or not to REPEAT the rule
935throughout the line.
936
937See `align-rules-list' for more information about these options.
938
939The non-interactive form of the previous example would look something like:
940 \(align-regexp (point-min) (point-max) \"\\\\(\\\\s-*\\\\)(\")
941
942This function is a nothing more than a small wrapper that helps you
943construct a rule to pass to `align-region', which does the real work."
930 (interactive 944 (interactive
931 (append 945 (append
932 (list (region-beginning) (region-end)) 946 (list (region-beginning) (region-end))
@@ -1498,6 +1512,9 @@ aligner would have dealt with are."
1498 (setq rule-beg (match-beginning first) 1512 (setq rule-beg (match-beginning first)
1499 save-match-data (match-data)) 1513 save-match-data (match-data))
1500 1514
1515 (or rule-beg
1516 (error "No match for subexpression %s" first))
1517
1501 ;; unless the `valid' attribute is set, and tells 1518 ;; unless the `valid' attribute is set, and tells
1502 ;; us that the rule is not valid at this point in 1519 ;; us that the rule is not valid at this point in
1503 ;; the code.. 1520 ;; the code..