bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#259: delphi-mode does not properly format interface definitions


From: Simon South
Subject: bug#259: delphi-mode does not properly format interface definitions
Date: Fri, 23 May 2008 04:25:26 -0400
User-agent: Thunderbird 2.0.0.14 (Windows/20080421)

Here's a patch that I believe is correct. This adds proper support for the "dispinterface" keyword and for the "interface" keyword when used to define interfaces.

I've tested this on the sample unit I posted earlier and on some other files and it works fine. I'll put together a more complete test case and post it here as well if it's useful.

The changes are:

- Added a "delphi-interface-types" constant to identify the "interface" and "dispinterface" keywords.

- Updated the definition of "delphi-composite-types" to include interface types.

- Updated the description of "delphi-composite-type-start" to include interface types (and to mention "object", which was previously missing).

- Modified the "delphi-enclosing-indent-of" function to recognize the dual meaning of "interface". When that keyword is encountered, the function searches backwards to find the previous non-whitespace token. If that token is an equals sign, "interface" is interpreted as the start of an interface definition; otherwise it's assumed to be the start of a unit section.

- Updated the copyright and authorship notices. (Let's see if the email addresses make it through...)

---

*** delphi.el.orig      Thu May 15 17:57:29 2008
--- delphi.el   Fri May 23 04:01:37 2008
***************
*** 1,9 ****
;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs

! ;; Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007
  ;; Free Software Foundation, Inc.

! ;; Author: Ray Blaak <address@hidden>
  ;; Maintainer: FSF  (Blaak's email addr bounces, Aug 2005)
  ;; Keywords: languages

--- 1,10 ----
;;; 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.

! ;; Authors: Ray Blaak <address@hidden>,
! ;;          Simon South <address@hidden>
  ;; Maintainer: FSF  (Blaak's email addr bounces, Aug 2005)
  ;; Keywords: languages

***************
*** 262,271 ****
  (defconst delphi-decl-sections '(type const var label resourcestring)
    "Denotes the start of a declaration section.")

  (defconst delphi-class-types '(class object)
    "Class types.")

! (defconst delphi-composite-types `(,@delphi-class-types record)
    "Types that contain declarations within them.")

  (defconst delphi-unit-sections
--- 263,276 ----
  (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 ,@delphi-interface-types record)
    "Types that contain declarations within them.")

  (defconst delphi-unit-sections
***************
*** 859,866 ****
        (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.
    (if (and (eq 'equals (delphi-token-kind token))
(delphi-is (delphi-token-kind last-token) delphi-composite-types))
        last-token))
--- 864,872 ----
        (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), (=
!   ;; 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))
***************
*** 1351,1357 ****
                                           delphi-indent-level)))

           ;; In unit sections we indent right to the left.
!          ((delphi-is token-kind delphi-unit-sections) (throw 'done 0))

           ;; A previous terminator means we can stop.
           ((delphi-is token-kind delphi-previous-terminators)
--- 1357,1385 ----
                                           delphi-indent-level)))

           ;; In unit sections we indent right to the left.
!          ((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)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]