]> code.delx.au - gnu-emacs/blobdiff - lisp/align.el
Merge from emacs-23; up to 2010-06-12T17:12:15Z!cyd@stupidchicken.com.
[gnu-emacs] / lisp / align.el
index 911200f58adb3e9577661c65d4c5c1446f10b130..8767b6ff306855bddb9aa3fe9bab7d46e282c294 100644 (file)
@@ -1,7 +1,6 @@
 ;;; align.el --- align text to a specific column, by regexp
 
 ;;; align.el --- align text to a specific column, by regexp
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2011  Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 ;; Maintainer: FSF
 
 ;; Author: John Wiegley <johnw@gnu.org>
 ;; Maintainer: FSF
   "An integer that represents the default amount of padding to use.
 If `align-to-tab-stop' is non-nil, this will represent the number of
 tab stops to use for alignment, rather than the number of spaces.
   "An integer that represents the default amount of padding to use.
 If `align-to-tab-stop' is non-nil, this will represent the number of
 tab stops to use for alignment, rather than the number of spaces.
-Each alignment rule can optionally override both this variable.  See
-`align-mode-alist'."
+Each alignment rule can optionally override both this variable and
+`align-to-tab-stop'.  See `align-rules-list'."
   :type 'integer
   :group 'align)
 
   :type 'integer
   :group 'align)
 
@@ -157,8 +156,8 @@ Since each alignment rule can possibly have its own set of alignment
 sections (whenever `align-region-separate' is non-nil, and not a
 string), this heuristic is used to determine how far before and after
 point we should search in looking for a region separator.  Larger
 sections (whenever `align-region-separate' is non-nil, and not a
 string), this heuristic is used to determine how far before and after
 point we should search in looking for a region separator.  Larger
-values can mean slower perform in large files, although smaller values
-may cause unexpected behavior at times."
+values can mean slower performance in large files, although smaller
+values may cause unexpected behavior at times."
   :type 'integer
   :group 'align)
 
   :type 'integer
   :group 'align)
 
@@ -174,7 +173,7 @@ may cause unexpected behavior at times."
 
 (defcustom align-large-region 10000
   "If an integer, defines what constitutes a \"large\" region.
 
 (defcustom align-large-region 10000
   "If an integer, defines what constitutes a \"large\" region.
-If nil,then no messages will ever be printed to the minibuffer."
+If nil, then no messages will ever be printed to the minibuffer."
   :type 'integer
   :group 'align)
 
   :type 'integer
   :group 'align)
 
@@ -184,7 +183,7 @@ If nil,then no messages will ever be printed to the minibuffer."
   :group 'align)
 
 (defcustom align-perl-modes '(perl-mode cperl-mode)
   :group 'align)
 
 (defcustom align-perl-modes '(perl-mode cperl-mode)
-  "A list of modes where perl syntax is to be seen."
+  "A list of modes where Perl syntax is to be seen."
   :type '(repeat symbol)
   :group 'align)
 
   :type '(repeat symbol)
   :group 'align)
 
@@ -222,7 +221,7 @@ If nil,then no messages will ever be printed to the minibuffer."
   (append align-lisp-modes align-c++-modes align-perl-modes
          '(python-mode makefile-mode))
   "A list of modes with a single-line comment syntax.
   (append align-lisp-modes align-c++-modes align-perl-modes
          '(python-mode makefile-mode))
   "A list of modes with a single-line comment syntax.
-These are comments as in Lisp, which have a beginning but, end with
+These are comments as in Lisp, which have a beginning, but end with
 the line (i.e., `comment-end' is an empty string)."
   :type '(repeat symbol)
   :group 'align)
 the line (i.e., `comment-end' is an empty string)."
   :type '(repeat symbol)
   :group 'align)
@@ -259,8 +258,8 @@ The possible settings for `align-region-separate' are:
 
  `group'   Each contiguous set of lines where a specific alignment
           occurs is considered a section for that alignment rule.
 
  `group'   Each contiguous set of lines where a specific alignment
           occurs is considered a section for that alignment rule.
-          Note that each rule will may have any entirely different
-          set of section divisions than another.
+          Note that each rule may have any entirely different set
+           of section divisions than another.
 
             int    alpha = 1; /* one */
             double beta  = 2.0;
 
             int    alpha = 1; /* one */
             double beta  = 2.0;
@@ -292,7 +291,7 @@ The possible settings for `align-region-separate' are:
           between sections, the behavior will be very similar to
           `largest', and faster.  But if the mode does not use clear
           separators (for example, if you collapse your braces onto
           between sections, the behavior will be very similar to
           `largest', and faster.  But if the mode does not use clear
           separators (for example, if you collapse your braces onto
-          the preceding statement in C or perl), `largest' is
+          the preceding statement in C or Perl), `largest' is
           probably the better alternative.
 
  function  A function that will be passed the beginning and ending
           probably the better alternative.
 
  function  A function that will be passed the beginning and ending
@@ -301,8 +300,8 @@ The possible settings for `align-region-separate' are:
           both of these parameters will be nil, in which case the
           function should return non-nil if it wants each rule to
           define its own section, or nil if it wants the largest
           both of these parameters will be nil, in which case the
           function should return non-nil if it wants each rule to
           define its own section, or nil if it wants the largest
-          section found to be used as the common section for all rules
-          that occur there.
+          section found to be used as the common section for all
+          rules that occur there.
 
  list      A list of markers within the buffer that represent where
           the section dividers lie.  Be certain to use markers!  For
 
  list      A list of markers within the buffer that represent where
           the section dividers lie.  Be certain to use markers!  For
@@ -623,8 +622,8 @@ The following attributes are meaningful:
            the purposes of alignment.  The \"alignment character\" is
            always the first character immediately following this
            parenthesis group.  This attribute may also be a list of
            the purposes of alignment.  The \"alignment character\" is
            always the first character immediately following this
            parenthesis group.  This attribute may also be a list of
-           integer, in which case multiple alignment characters will
-           be aligned, with the list of integer identifying the
+           integers, in which case multiple alignment characters will
+           be aligned, with the list of integers identifying the
            whitespace groups which precede them.  The default for
            this attribute is 1.
 
            whitespace groups which precede them.  The default for
            this attribute is 1.
 
@@ -636,7 +635,7 @@ The following attributes are meaningful:
 `case-fold' If `regexp' is an ordinary regular expression string
            containing alphabetic character, sometimes you may want
            the search to proceed case-insensitively (for languages
 `case-fold' If `regexp' is an ordinary regular expression string
            containing alphabetic character, sometimes you may want
            the search to proceed case-insensitively (for languages
-           that ignore case, such as pascal for example).  In that
+           that ignore case, such as Pascal for example).  In that
            case, set `case-fold' to a non-nil value, and the regular
            expression search will ignore case.  If `regexp' is set to
            a function, that function must handle the job of ignoring
            case, set `case-fold' to a non-nil value, and the regular
            expression search will ignore case.  If `regexp' is set to
            a function, that function must handle the job of ignoring
@@ -926,7 +925,7 @@ align them so that the opening parentheses would line up:
     Joe (123) 456-7890
 
 There is no predefined rule to handle this, but you could easily do it
     Joe (123) 456-7890
 
 There is no predefined rule to handle this, but you could easily do it
-using a REGEXP like \"(\". All you would have to do is to mark the
+using a REGEXP like \"(\".  All you would have to do is to mark the
 region, call `align-regexp' and type in that regular expression."
   (interactive
    (append
 region, call `align-regexp' and type in that regular expression."
   (interactive
    (append
@@ -944,6 +943,8 @@ region, call `align-regexp' and type in that regular expression."
       (list (concat "\\(\\s-*\\)"
                    (read-string "Align regexp: "))
            1 align-default-spacing nil))))
       (list (concat "\\(\\s-*\\)"
                    (read-string "Align regexp: "))
            1 align-default-spacing nil))))
+  (or group (setq group 1))
+  (or spacing (setq spacing align-default-spacing))
   (let ((rule
         (list (list nil (cons 'regexp regexp)
                     (cons 'group (abs group))
   (let ((rule
         (list (list nil (cons 'regexp regexp)
                     (cons 'group (abs group))
@@ -1105,7 +1106,7 @@ documentation for `align-region-separate' for more details."
             (setq seps (cdr seps))))
           yes))))
 
             (setq seps (cdr seps))))
           yes))))
 
-(defun align-adjust-col-for-rule (column rule spacing tab-stop)
+(defun align-adjust-col-for-rule (column _rule spacing tab-stop)
   "Adjust COLUMN according to the given RULE.
 SPACING specifies how much spacing to use.
 TAB-STOP specifies whether SPACING refers to tab-stop boundaries."
   "Adjust COLUMN according to the given RULE.
 SPACING specifies how much spacing to use.
 TAB-STOP specifies whether SPACING refers to tab-stop boundaries."
@@ -1160,7 +1161,7 @@ have been aligned.  No changes will be made to the buffer."
         (justify (cdr (assq 'justify rule)))
         (col (or fixed 0))
         (width 0)
         (justify (cdr (assq 'justify rule)))
         (col (or fixed 0))
         (width 0)
-        ecol change look)
+        ecol change)
 
     ;; Determine the alignment column.
     (let ((a areas))
 
     ;; Determine the alignment column.
     (let ((a areas))
@@ -1284,7 +1285,6 @@ purpose where you might want to know where the regions that the
 aligner would have dealt with are."
   (let ((end-mark (and end (copy-marker end t)))
        (real-beg beg)
 aligner would have dealt with are."
   (let ((end-mark (and end (copy-marker end t)))
        (real-beg beg)
-       (real-end end)
        (report (and (not func) align-large-region beg end
                     (>= (- end beg) align-large-region)))
        (rule-index 1)
        (report (and (not func) align-large-region beg end
                     (>= (- end beg) align-large-region)))
        (rule-index 1)
@@ -1307,12 +1307,13 @@ aligner would have dealt with are."
                 (rulesep (assq 'separate rule))
                 (thissep (if rulesep (cdr rulesep) separate))
                 same (eol 0)
                 (rulesep (assq 'separate rule))
                 (thissep (if rulesep (cdr rulesep) separate))
                 same (eol 0)
+                search-start
                 group group-c
                 spacing spacing-c
                 tab-stop tab-stop-c
                 repeat repeat-c
                 valid valid-c
                 group group-c
                 spacing spacing-c
                 tab-stop tab-stop-c
                 repeat repeat-c
                 valid valid-c
-                pos-list first
+                first
                 regions index
                 last-point b e
                 save-match-data
                 regions index
                 last-point b e
                 save-match-data
@@ -1412,6 +1413,7 @@ aligner would have dealt with are."
                      ;; while we can find the rule in the alignment
                      ;; region..
                      (while (and (< (point) end-mark)
                      ;; while we can find the rule in the alignment
                      ;; region..
                      (while (and (< (point) end-mark)
+                                 (setq search-start (point))
                                  (if regfunc
                                      (funcall regfunc end-mark nil)
                                    (re-search-forward regexp
                                  (if regfunc
                                      (funcall regfunc end-mark nil)
                                    (re-search-forward regexp
@@ -1436,7 +1438,7 @@ aligner would have dealt with are."
                        ;; if the search ended us on the beginning of
                        ;; the next line, move back to the end of the
                        ;; previous line.
                        ;; if the search ended us on the beginning of
                        ;; the next line, move back to the end of the
                        ;; previous line.
-                       (if (bolp)
+                       (if (and (bolp) (> (point) search-start))
                            (forward-char -1))
 
                        ;; lookup the `group' attribute the first time
                            (forward-char -1))
 
                        ;; lookup the `group' attribute the first time
@@ -1576,7 +1578,12 @@ aligner would have dealt with are."
                            ;; the next line; don't bother searching
                            ;; anymore on this one
                            (if (and (not repeat) (not (bolp)))
                            ;; the next line; don't bother searching
                            ;; anymore on this one
                            (if (and (not repeat) (not (bolp)))
-                               (forward-line)))))
+                               (forward-line))
+
+                           ;; if the search did not change point,
+                           ;; move forward to avoid an infinite loop
+                           (if (= (point) search-start)
+                               (forward-char)))))
 
                      ;; when they are no more matches for this rule,
                      ;; align whatever was left over
 
                      ;; when they are no more matches for this rule,
                      ;; align whatever was left over
@@ -1596,5 +1603,4 @@ aligner would have dealt with are."
 
 (run-hooks 'align-load-hook)
 
 
 (run-hooks 'align-load-hook)
 
-;; arch-tag: ef79cccf-1db8-4888-a8a1-d7ce2d1532f7
 ;;; align.el ends here
 ;;; align.el ends here