]> code.delx.au - gnu-emacs/blobdiff - lisp/align.el
(dired-pop-to-buffer): Try to make this behave the
[gnu-emacs] / lisp / align.el
index e5ad98c815ab778b29364e584b2ae3551d5dbb71..0917e7d41875c8d7d24831328ad6965e1f0cd130 100644 (file)
@@ -1,16 +1,18 @@
 ;;; align.el --- align text to a specific column, by regexp
 
 ;;; align.el --- align text to a specific column, by regexp
 
-;; Copyright (C) 1999, 2000, 2002 Free Sofware Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 ;; Author: John Wiegley <johnw@gnu.org>
+;; Maintainer: FSF
 ;; Keywords: convenience languages lisp
 
 ;; This file is part of GNU Emacs.
 
 ;; Keywords: convenience languages lisp
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; Commentary:
 
 ;;; User Variables:
 
 (defcustom align-load-hook nil
 ;;; User Variables:
 
 (defcustom align-load-hook nil
-  "*Hook that gets run after the aligner has been loaded."
+  "Hook that gets run after the aligner has been loaded."
   :type 'hook
   :group 'align)
 
 (defcustom align-indent-before-aligning nil
   :type 'hook
   :group 'align)
 
 (defcustom align-indent-before-aligning nil
-  "*If non-nil, indent the marked region before aligning it."
+  "If non-nil, indent the marked region before aligning it."
   :type 'boolean
   :group 'align)
 
 (defcustom align-default-spacing 1
   :type 'boolean
   :group 'align)
 
 (defcustom align-default-spacing 1
-  "*An integer that represents the default amount of padding to use.
+  "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
 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
@@ -146,13 +146,13 @@ Each alignment rule can optionally override both this variable.  See
   :group 'align)
 
 (defcustom align-to-tab-stop 'indent-tabs-mode
   :group 'align)
 
 (defcustom align-to-tab-stop 'indent-tabs-mode
-  "*If non-nil, alignments will always fall on a tab boundary.
+  "If non-nil, alignments will always fall on a tab boundary.
 It may also be a symbol, whose value will be taken."
   :type '(choice (const nil) symbol)
   :group 'align)
 
 (defcustom align-region-heuristic 500
 It may also be a symbol, whose value will be taken."
   :type '(choice (const nil) symbol)
   :group 'align)
 
 (defcustom align-region-heuristic 500
-  "*If non-nil, used as a heuristic by `align-current'.
+  "If non-nil, used as a heuristic by `align-current'.
 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
 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
@@ -163,72 +163,72 @@ may cause unexpected behavior at times."
   :group 'align)
 
 (defcustom align-highlight-change-face 'highlight
   :group 'align)
 
 (defcustom align-highlight-change-face 'highlight
-  "*The face to highlight with if changes are necessary."
+  "The face to highlight with if changes are necessary."
   :type 'face
   :group 'align)
 
 (defcustom align-highlight-nochange-face 'secondary-selection
   :type 'face
   :group 'align)
 
 (defcustom align-highlight-nochange-face 'secondary-selection
-  "*The face to highlight with if no changes are necessary."
+  "The face to highlight with if no changes are necessary."
   :type 'face
   :group 'align)
 
 (defcustom align-large-region 10000
   :type 'face
   :group 'align)
 
 (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 an integer, defines what constitutes a \"large\" region.
+If nil, then no messages will ever be printed to the minibuffer."
   :type 'integer
   :group 'align)
 
 (defcustom align-c++-modes '(c++-mode c-mode java-mode)
   :type 'integer
   :group 'align)
 
 (defcustom align-c++-modes '(c++-mode c-mode java-mode)
-  "*A list of modes whose syntax resembles C/C++."
+  "A list of modes whose syntax resembles C/C++."
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-perl-modes '(perl-mode cperl-mode)
   :type '(repeat symbol)
   :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)
 
 (defcustom align-lisp-modes
   '(emacs-lisp-mode lisp-interaction-mode lisp-mode scheme-mode)
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-lisp-modes
   '(emacs-lisp-mode lisp-interaction-mode lisp-mode scheme-mode)
-  "*A list of modes whose syntax resembles Lisp."
+  "A list of modes whose syntax resembles Lisp."
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-tex-modes
   '(tex-mode plain-tex-mode latex-mode slitex-mode)
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-tex-modes
   '(tex-mode plain-tex-mode latex-mode slitex-mode)
-  "*A list of modes whose syntax resembles TeX (and family)."
+  "A list of modes whose syntax resembles TeX (and family)."
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-text-modes '(text-mode outline-mode)
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-text-modes '(text-mode outline-mode)
-  "*A list of modes whose content is plain text."
+  "A list of modes whose content is plain text."
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-dq-string-modes
   (append align-lisp-modes align-c++-modes align-perl-modes
          '(python-mode))
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-dq-string-modes
   (append align-lisp-modes align-c++-modes align-perl-modes
          '(python-mode))
-  "*A list of modes where double quoted strings should be excluded."
+  "A list of modes where double quoted strings should be excluded."
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-sq-string-modes
   (append align-perl-modes '(python-mode))
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-sq-string-modes
   (append align-perl-modes '(python-mode))
-  "*A list of modes where single quoted strings should be excluded."
+  "A list of modes where single quoted strings should be excluded."
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-open-comment-modes
   (append align-lisp-modes align-c++-modes align-perl-modes
          '(python-mode makefile-mode))
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-open-comment-modes
   (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
+  "A list of modes with a single-line comment syntax.
+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)
 
 (defcustom align-region-separate "^\\s-*[{}]?\\s-*$"
 the line (i.e., `comment-end' is an empty string)."
   :type '(repeat symbol)
   :group 'align)
 
 (defcustom align-region-separate "^\\s-*[{}]?\\s-*$"
-  "*Select the method by which alignment sections will be separated.
+  "Select the method by which alignment sections will be separated.
 If this is a symbol, that symbol's value will be used.
 
 For the sake of clarification, consider the following example, which
 If this is a symbol, that symbol's value will be used.
 
 For the sake of clarification, consider the following example, which
@@ -259,8 +259,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 +292,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 +301,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
@@ -383,9 +383,6 @@ The possible settings for `align-region-separate' are:
                           regexp function)))))))
   "The `type' form for any `align-rules-list' variable.")
 
                           regexp function)))))))
   "The `type' form for any `align-rules-list' variable.")
 
-(unless (functionp 'c-guess-basic-syntax)
-  (autoload 'c-guess-basic-syntax "cc-engine"))
-
 (defcustom align-rules-list
   `((lisp-second-arg
      (regexp   . "\\(^\\s-+[^( \t\n]\\|(\\(\\S-+\\)\\s-+\\)\\S-+\\(\\s-+\\)")
 (defcustom align-rules-list
   `((lisp-second-arg
      (regexp   . "\\(^\\s-+[^( \t\n]\\|(\\(\\S-+\\)\\s-+\\)\\S-+\\(\\s-+\\)")
@@ -466,13 +463,13 @@ The possible settings for `align-region-separate' are:
      (repeat   . t)
      (modes    . align-c++-modes)
      (run-if   . ,(function (lambda () current-prefix-arg))))
      (repeat   . t)
      (modes    . align-c++-modes)
      (run-if   . ,(function (lambda () current-prefix-arg))))
-;      (valid
-;       . ,(function
-;        (lambda ()
-;          (memq (caar (c-guess-basic-syntax))
-;                '(brace-list-intro
-;                  brace-list-entry
-;                  brace-entry-open))))))
+                                       ;      (valid
+                                       ;       . ,(function
+                                       ;         (lambda ()
+                                       ;           (memq (caar (c-guess-basic-syntax))
+                                       ;                 '(brace-list-intro
+                                       ;                   brace-list-entry
+                                       ;                   brace-entry-open))))))
 
     ;; With a prefix argument, comma delimiter will be aligned.  Since
     ;; perl-mode doesn't give us enough syntactic information (and we
 
     ;; With a prefix argument, comma delimiter will be aligned.  Since
     ;; perl-mode doesn't give us enough syntactic information (and we
@@ -525,11 +522,11 @@ The possible settings for `align-region-separate' are:
      (regexp   . "\\(\\s-*\\)\\\\$")
      (modes    . align-c++-modes)
      (column   . c-backslash-column))
      (regexp   . "\\(\\s-*\\)\\\\$")
      (modes    . align-c++-modes)
      (column   . c-backslash-column))
-;      (valid
-;       . ,(function
-;        (lambda ()
-;          (memq (caar (c-guess-basic-syntax))
-;                '(cpp-macro cpp-macro-cont))))))
+                                       ;      (valid
+                                       ;       . ,(function
+                                       ;         (lambda ()
+                                       ;           (memq (caar (c-guess-basic-syntax))
+                                       ;                 '(cpp-macro cpp-macro-cont))))))
 
     (basic-line-continuation
      (regexp   . "\\(\\s-*\\)\\\\$")
 
     (basic-line-continuation
      (regexp   . "\\(\\s-*\\)\\\\$")
@@ -561,7 +558,7 @@ The possible settings for `align-region-separate' are:
     ;; With a numeric prefix argument, or C-u, space delimited text
     ;; tables will be aligned.
     (text-column
     ;; With a numeric prefix argument, or C-u, space delimited text
     ;; tables will be aligned.
     (text-column
-     (regexp   . "\\(^\\|\\S-\\)\\(\\s-+\\)\\(\\S-\\|$\\)")
+     (regexp   . "\\(^\\|\\S-\\)\\([ \t]+\\)\\(\\S-\\|$\\)")
      (group    . 2)
      (modes    . align-text-modes)
      (repeat   . t)
      (group    . 2)
      (modes    . align-text-modes)
      (repeat   . t)
@@ -578,8 +575,13 @@ The possible settings for `align-region-separate' are:
      (justify  . t)
      (run-if   . ,(function
                   (lambda ()
      (justify  . t)
      (run-if   . ,(function
                   (lambda ()
-                    (eq '- current-prefix-arg))))))
-  "*An list describing all of the available alignment rules.
+                    (eq '- current-prefix-arg)))))
+
+    (css-declaration
+     (regexp . "^\\s-*\\w+:\\(\\s-*\\).*;")
+     (group . (1))
+     (modes . '(css-mode html-mode))))
+  "A list describing all of the available alignment rules.
 The format is:
 
    ((TITLE
 The format is:
 
    ((TITLE
@@ -621,8 +623,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.
 
@@ -634,10 +636,10 @@ 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
-           case, set `case-fold' to nil, and the regular expression
-           search will ignore case.  If `regexp' is set to a
-           function, that function must handle the job of ignoring
+           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
+           function, that function must handle the job of ignoring
            case by itself.
 
 `tab-stop'  If the `tab-stop' attribute is set, and non-nil, the
            case by itself.
 
 `tab-stop'  If the `tab-stop' attribute is set, and non-nil, the
@@ -777,7 +779,7 @@ The following attributes are meaningful:
      (regexp . "^\\s-*#\\s-*\\(if\\w*\\|endif\\)\\(.*\\)$")
      (group  . 2)
      (modes  . align-c++-modes)))
      (regexp . "^\\s-*#\\s-*\\(if\\w*\\|endif\\)\\(.*\\)$")
      (group  . 2)
      (modes  . align-c++-modes)))
-  "*An list describing text that should be excluded from alignment.
+  "A list describing text that should be excluded from alignment.
 See the documentation for `align-rules-list' for more info."
   :type align-exclude-rules-list-type
   :group 'align)
 See the documentation for `align-rules-list' for more info."
   :type align-exclude-rules-list-type
   :group 'align)
@@ -835,7 +837,7 @@ See the variable `align-exclude-rules-list' for more details.")
 
     (use-entity
      (regexp   . "\\(\\s-+\\)use\\s-+entity")))
 
     (use-entity
      (regexp   . "\\(\\s-+\\)use\\s-+entity")))
-  "*Alignment rules for `vhdl-mode'.  See `align-rules-list' for more info."
+  "Alignment rules for `vhdl-mode'.  See `align-rules-list' for more info."
   :type align-rules-list-type
   :group 'align)
 
   :type align-rules-list-type
   :group 'align)
 
@@ -928,15 +930,14 @@ 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
-    (list (min (point) (mark))
-         (max (point) (mark)))
+    (list (region-beginning) (region-end))
     (if current-prefix-arg
        (list (read-string "Complex align using regexp: "
                           "\\(\\s-*\\)")
     (if current-prefix-arg
        (list (read-string "Complex align using regexp: "
                           "\\(\\s-*\\)")
-             (string-to-int
+             (string-to-number
               (read-string
                "Parenthesis group to modify (justify if negative): " "1"))
               (read-string
                "Parenthesis group to modify (justify if negative): " "1"))
-             (string-to-int
+             (string-to-number
               (read-string "Amount of spacing (or column if negative): "
                            (number-to-string align-default-spacing)))
              (y-or-n-p "Repeat throughout line? "))
               (read-string "Amount of spacing (or column if negative): "
                            (number-to-string align-default-spacing)))
              (y-or-n-p "Repeat throughout line? "))
@@ -985,8 +986,7 @@ list of rules (see `align-rules-list'), it can be used to override the
 default alignment rules that would have been used to identify the text
 to be colored."
   (interactive
 default alignment rules that would have been used to identify the text
 to be colored."
   (interactive
-   (list (min (mark) (point))
-        (max (mark) (point))
+   (list (region-beginning) (region-end)
         (completing-read
          "Title of rule to highlight: "
          (mapcar
         (completing-read
          "Title of rule to highlight: "
          (mapcar
@@ -1073,7 +1073,7 @@ current position."
                           (eq (char-before pos) ?\\))
                 (setq count (1+ count) pos (1- pos)))
               (eq (mod count 2) 1))
                           (eq (char-before pos) ?\\))
                 (setq count (1+ count) pos (1- pos)))
               (eq (mod count 2) 1))
-            (goto-char (match-beginning 2))))
+            (goto-char (match-beginning (if reverse 1 2)))))
     result))
 
 (defun align-new-section-p (beg end separator)
     result))
 
 (defun align-new-section-p (beg end separator)
@@ -1212,6 +1212,14 @@ have been aligned.  No changes will be made to the buffer."
              (cond ((< gocol 0) t)     ; don't do anything
                    ((= cur gocol) t)   ; don't need to
                    ((< cur gocol)      ; just add space
              (cond ((< gocol 0) t)     ; don't do anything
                    ((= cur gocol) t)   ; don't need to
                    ((< cur gocol)      ; just add space
+                    ;; FIXME: It is stated above that "...the
+                    ;;        whitespace to be modified was already
+                    ;;        deleted by `align-region', all we have
+                    ;;        to do here is indent."  However, this
+                    ;;        doesn't seem to be true, so we first
+                    ;;        delete the whitespace to avoid tabs
+                    ;;        after spaces.
+                    (delete-horizontal-space t)
                     (indent-to gocol))
                    (t
                     ;; This code works around an oddity in the
                     (indent-to gocol))
                    (t
                     ;; This code works around an oddity in the
@@ -1299,6 +1307,7 @@ 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
                 group group-c
                 spacing spacing-c
                 tab-stop tab-stop-c
@@ -1404,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
@@ -1428,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
@@ -1568,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
@@ -1588,4 +1603,5 @@ 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