From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Simon South Newsgroups: gmane.emacs.bugs Subject: bug#259: delphi-mode does not properly format interface definitions Date: Fri, 23 May 2008 04:25:26 -0400 Message-ID: <48367F76.1020902@slowcomputing.org> References: <482DB340.3050405@slowcomputing.org> <482DCB0F.2080602@slowcomputing.org> <48358E99.4010001@slowcomputing.org> Reply-To: Simon South , 259@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1211596141 2777 80.91.229.12 (24 May 2008 02:29:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 24 May 2008 02:29:01 +0000 (UTC) To: 259@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 24 04:29:38 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JzjVp-0007LY-Eo for geb-bug-gnu-emacs@m.gmane.org; Sat, 24 May 2008 04:29:37 +0200 Original-Received: from localhost ([127.0.0.1]:41298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JzjV4-0002tE-Kr for geb-bug-gnu-emacs@m.gmane.org; Fri, 23 May 2008 22:28:50 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JzT0C-00065m-QG for bug-gnu-emacs@gnu.org; Fri, 23 May 2008 04:51:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JzT09-00063z-Vz for bug-gnu-emacs@gnu.org; Fri, 23 May 2008 04:51:51 -0400 Original-Received: from [199.232.76.173] (port=38767 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JzT09-00063J-0s for bug-gnu-emacs@gnu.org; Fri, 23 May 2008 04:51:49 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:35690) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JzT07-00086p-HM for bug-gnu-emacs@gnu.org; Fri, 23 May 2008 04:51:48 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m4N8pgDS009558; Fri, 23 May 2008 01:51:44 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m4N8Z3c0004889; Fri, 23 May 2008 01:35:03 -0700 X-Loop: don@donarmstrong.com Resent-From: Simon South Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Fri, 23 May 2008 08:35:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 259 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Original-Received: via spool by 259-submit@emacsbugs.donarmstrong.com id=B259.12115311313587 (code B ref 259); Fri, 23 May 2008 08:35:03 +0000 Original-Received: (at 259) by emacsbugs.donarmstrong.com; 23 May 2008 08:25:31 +0000 Original-Received: from postalmail-a5.g.dreamhost.com (sd-green-bigip-83.dreamhost.com [208.97.132.83]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m4N8PRJL003485 for <259@emacsbugs.donarmstrong.com>; Fri, 23 May 2008 01:25:29 -0700 Original-Received: from [192.168.2.10] (bas1-toronto63-1096578704.dsl.bell.ca [65.92.118.144]) by postalmail-a5.g.dreamhost.com (Postfix) with ESMTP id 85653BF2BE for <259@emacsbugs.donarmstrong.com>; Fri, 23 May 2008 01:25:27 -0700 (PDT) User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) In-Reply-To: <48358E99.4010001@slowcomputing.org> X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Fri, 23 May 2008 04:51:50 -0400 X-Mailman-Approved-At: Fri, 23 May 2008 22:27:16 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:18123 Archived-At: 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 ;; 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 , ! ;; Simon South ;; 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)