]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/delphi.el
* compile.el (compilation-read-command): Doc fix.
[gnu-emacs] / lisp / progmodes / delphi.el
index ca5f12c2863217b284be75c37e3fbec156f26f6c..c5a38607b3844663824ab0221bc489f8add1c9b2 100644 (file)
@@ -1,27 +1,27 @@
 ;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs
 
-;; Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+;;   2008, 2009  Free Software Foundation, Inc.
 
-;; Author: Ray Blaak <blaak@infomatch.com>
-;; Maintainer: FSF  (Blaak's email addr bounces, Aug 2005)
+;; Authors: Ray Blaak <blaak@infomatch.com>,
+;;          Simon South <ssouth@member.fsf.org>
+;; Maintainer: Simon South <ssouth@member.fsf.org>
 ;; Keywords: languages
 
 ;; This file is part of GNU Emacs.
 
-;; 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 the Free
-;; Software Foundation; either version 3, or (at your option) any later
-;; version.
+;; 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
+;; 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 MERCHANTABILITY or FITNESS
-;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
-;; details.
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -239,10 +239,14 @@ are followed by an expression.")
 (defconst delphi-decl-sections '(type const var label resourcestring)
   "Denotes the start of a declaration section.")
 
+(defconst delphi-interface-types '(dispinterface interface)
+  "Interface types.")
+
 (defconst delphi-class-types '(class object)
   "Class types.")
 
-(defconst delphi-composite-types `(,@delphi-class-types record)
+(defconst delphi-composite-types
+  `(,@delphi-class-types ,@delphi-interface-types record)
   "Types that contain declarations within them.")
 
 (defconst delphi-unit-sections
@@ -836,8 +840,9 @@ non-delphi buffer. Set to nil in a delphi buffer.  To override, just do:
       (delphi-stmt-line-indent-of token delphi-indent-level))))
 
 (defun delphi-composite-type-start (token last-token)
-  ;; Returns true (actually the last-token) if the pair equals (= class) or (=
-  ;; record), and nil otherwise.
+  ;; Returns true (actually the last-token) if the pair equals (= class), (=
+  ;; dispinterface), (= interface), (= object), or (= record), and nil
+  ;; otherwise.
   (if (and (eq 'equals (delphi-token-kind token))
            (delphi-is (delphi-token-kind last-token) delphi-composite-types))
       last-token))
@@ -1328,7 +1333,29 @@ non-delphi buffer. Set to nil in a delphi buffer.  To override, just do:
                                          delphi-indent-level)))
 
          ;; In unit sections we indent right to the left.
-         ((delphi-is token-kind delphi-unit-sections) (throw 'done 0))
+         ((delphi-is token-kind delphi-unit-sections)
+          (throw 'done
+                 ;; Handle specially the case of "interface", which can be used
+                 ;; to start either a unit section or an interface definition.
+                 (if (delphi-is token-kind delphi-interface-types)
+                     (progn
+                       ;; Find the previous non-whitespace token.
+                       (while (progn
+                                (setq last-token token
+                                      token (delphi-previous-token token)
+                                      token-kind (delphi-token-kind token))
+                                (and token
+                                     (delphi-is token-kind
+                                                delphi-whitespace))))
+                       ;; If this token is an equals sign, "interface" is being
+                       ;; used to start an interface definition and we should
+                       ;; treat it as a composite type; otherwise, we should
+                       ;; consider it the start of a unit section.
+                       (if (and token (eq token-kind 'equals))
+                           (delphi-line-indent-of last-token
+                                                  delphi-indent-level)
+                         0))
+                   0)))
 
          ;; A previous terminator means we can stop.
          ((delphi-is token-kind delphi-previous-terminators)
@@ -1625,14 +1652,23 @@ before the indent, the point is moved to the indent."
 
 
 (defun delphi-tab ()
-  "Indent the current line or insert a TAB, depending on the value of
-`delphi-tab-always-indents' and the current line position."
+  "Indent the region, when Transient Mark mode is enabled and the region is
+active. Otherwise, indent the current line or insert a TAB, depending on the
+value of `delphi-tab-always-indents' and the current line position."
   (interactive)
-  (if (or delphi-tab-always-indents ; We are always indenting
-          ;; Or we are before the first non-space character on the line.
-          (save-excursion (skip-chars-backward delphi-space-chars) (bolp)))
-      (delphi-indent-line)
-    (insert "\t")))
+  (cond ((use-region-p)
+         ;; If Transient Mark mode is enabled and the region is active, indent
+         ;; the entire region.
+         (indent-region (region-beginning) (region-end)))
+        ((or delphi-tab-always-indents
+             (save-excursion (skip-chars-backward delphi-space-chars) (bolp)))
+         ;; Otherwise, if we are configured always to indent (regardless of the
+         ;; point's position in the line) or we are before the first non-space
+         ;; character on the line, indent the line.
+         (delphi-indent-line))
+        (t
+         ;; Otherwise, insert a tab character.
+         (insert "\t"))))
 
 
 (defun delphi-is-directory (path)
@@ -1908,7 +1944,8 @@ This is ok since we do our own keyword/comment/string face coloring.")
 ;;;###autoload
 (defun delphi-mode (&optional skip-initial-parsing)
   "Major mode for editing Delphi code. \\<delphi-mode-map>
-\\[delphi-tab]\t- Indents the current line for Delphi code.
+\\[delphi-tab]\t- Indents the current line (or region, if Transient Mark mode
+\t  is enabled and the region is active) of Delphi code.
 \\[delphi-find-unit]\t- Search for a Delphi source file.
 \\[delphi-fill-comment]\t- Fill the current comment.
 \\[delphi-new-comment-line]\t- If in a // comment, do a new comment line.