Function: align

align is an autoloaded, interactive and natively compiled function defined in align.el.gz.

Signature

(align BEG END &optional SEPARATE RULES EXCLUDE-RULES)

Documentation

Attempt to align a region based on a set of alignment rules.

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 separate attribute set.

RULES and EXCLUDE-RULES, if either is non-nil, will replace the default rule lists defined in align-rules-list and align-exclude-rules-list. See align-rules-list for more details on the format of these lists.

View in manual

Probably introduced at or before Emacs version 21.1.

Key Bindings

This command is not in any keymaps.

Source Code

;; Defined in /usr/src/emacs/lisp/align.el.gz
;;; User Functions:

;;;###autoload
(defun align (beg end &optional separate rules exclude-rules)
  "Attempt to align a region based on a set of alignment rules.
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
`separate' attribute set.

RULES and EXCLUDE-RULES, if either is non-nil, will replace the
default rule lists defined in `align-rules-list' and
`align-exclude-rules-list'.  See `align-rules-list' for more details
on the format of these lists."
  (interactive "r")
  (let ((separator
	 (or separate
	     (if (and (symbolp align-region-separate)
		      (boundp align-region-separate))
		 (symbol-value align-region-separate)
	       align-region-separate)
	     'entire)))
    (if (not (or ;(eq separator 'largest)
		 (and (functionp separator)
		      (not (funcall separator nil nil)))))
	(align-region beg end separator
		      (or rules align-mode-rules-list align-rules-list)
		      (or exclude-rules align-mode-exclude-rules-list
			  align-exclude-rules-list))
      (let ((sec-first end)
	    (sec-last beg))
	(align-region beg end
		      separator
		      nil ; rules
                      (or exclude-rules
			  align-mode-exclude-rules-list
			  align-exclude-rules-list)
                      (lambda (b e mode)
                        (when (consp mode)
                          (setq sec-first (min sec-first b)
                                sec-last  (max sec-last e)))))
	(if (< sec-first sec-last)
	    (align-region sec-first sec-last 'entire
			  (or rules align-mode-rules-list align-rules-list)
			  (or exclude-rules align-mode-exclude-rules-list
			      align-exclude-rules-list)))))))