annotate lisp/progmodes/delphi.el @ 40679:3c4df1ce9e4c

(tooltip-delay): Decrease to 0.7. (tooltip-hide-delay): Enlarge to 10.
author Eli Zaretskii <eliz@gnu.org>
date Sat, 03 Nov 2001 16:59:11 +0000
parents b174db545cfd
children 6297965bc792
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35624
diff changeset
1 ;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1998, 1999 Free Software Foundation, Inc.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5 ;; Author: Ray Blaak <blaak@infomatch.com>
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; Keywords: languages
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify it under
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
11 ;; the terms of the GNU General Public License as published by the Free
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
12 ;; Software Foundation; either version 2, or (at your option) any later
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
13 ;; version.
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
16 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
17 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
18 ;; details.
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
20 ;; You should have received a copy of the GNU General Public License along with
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
21 ;; GNU Emacs; see the file COPYING. If not, write to the Free Software
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
22 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26 ;; To enter Delphi mode when you find a Delphi source file, one must override
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 ;; the auto-mode-alist to associate Delphi with .pas (and .dpr and .dpk)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;; files. Emacs, by default, will otherwise enter Pascal mode. E.g.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29 ;;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;; (autoload 'delphi-mode "delphi")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 ;; (setq auto-mode-alist
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 ;; (cons '("\\.\\(pas\\|dpr\\|dpk\\)$" . delphi-mode) auto-mode-alist))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
34 ;; To get keyword, comment, and string literal coloring, be sure that font-lock
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
35 ;; is running. One can manually do M-x font-lock-mode in a Delphi buffer, or
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
36 ;; one can put in .emacs:
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
37 ;;
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
38 ;; (add-hook 'delphi-mode-hook 'turn-on-font-lock)
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
39
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
40 ;; If font-lock is not loaded by default, you might have to do:
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
41 ;;
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
42 ;; (autoload 'font-lock-mode "font-lock")
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
43 ;; (autoload 'turn-on-font-lock "font-lock")
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
44 ;; (setq font-lock-support-mode 'lazy-lock-mode)
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
45 ;;
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
46 ;; Lazy lock is very necessary for faster screen updates.
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
47
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
48 ;; For good performance, be sure to byte-compile delphi.el, e.g.
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
49 ;;
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
50 ;; M-x byte-compile-file <give the path to delphi.el when prompted>
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
51
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
52 ;; This will generate delphi.elc, which will be loaded instead of delphi.el
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
53 ;; when delphi-mode is autoloaded.
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
54
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55 ;; When you have entered Delphi mode, you may get more info by pressing
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 ;; C-h m.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
58 ;; This delphi mode implementation is fairly tolerant of syntax errors, relying
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
59 ;; as much as possible on the indentation of the previous statement. This also
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
60 ;; makes it faster and simpler, since there is less searching for properly
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
61 ;; constructed beginnings.
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63 ;;; Code:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
65 (provide 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
66
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67 (defconst delphi-version
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35624
diff changeset
68 (let ((revision "$Revision: 3.5 $"))
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 (string-match ": \\([^ ]+\\)" revision)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 (match-string 1 revision))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 "Version of this delphi mode.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72 ;;; $Log: delphi.el,v $
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35624
diff changeset
73 ;;; Revision 3.5 2001/01/26 20:54:03 fx
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35624
diff changeset
74 ;;; (delphi-comment-face, delphi-string-face)
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35624
diff changeset
75 ;;; (delphi-keyword-face, delphi-other-face): Fix :type.
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35624
diff changeset
76 ;;;
35624
6878c61d1877 (delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents: 27647
diff changeset
77 ;;; Revision 3.4 2000/02/09 07:04:15 blaak
6878c61d1877 (delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents: 27647
diff changeset
78 ;;; Make resourcestring a declaration region, like const and var.
6878c61d1877 (delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents: 27647
diff changeset
79 ;;;
27647
c8d739c1aaf0 Make resourcestring a declaration region, like const and var.
Ray Blaak <blaak@infomatch.com>
parents: 27551
diff changeset
80 ;;; Revision 3.3 2000/02/01 14:32:21 fx
c8d739c1aaf0 Make resourcestring a declaration region, like const and var.
Ray Blaak <blaak@infomatch.com>
parents: 27551
diff changeset
81 ;;; (delphi): Add :version to defgroup.
c8d739c1aaf0 Make resourcestring a declaration region, like const and var.
Ray Blaak <blaak@infomatch.com>
parents: 27551
diff changeset
82 ;;;
27551
2dd8115a9f72 (delphi): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 25317
diff changeset
83 ;;; Revision 3.2 1999/08/18 05:08:39 blaak
2dd8115a9f72 (delphi): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 25317
diff changeset
84 ;;; checked in with -k by blaak at 1999/08/18 05:08:39
2dd8115a9f72 (delphi): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 25317
diff changeset
85 ;;;
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
86 ;;; Revision 3.2 1999/08/04 05:09:19 blaak
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
87 ;;; Consider assembly sections as blocks, to indent them better.
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
88 ;;;
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
89 ;;; Revision 3.1 1999/08/04 04:45:47 blaak
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
90 ;;; Make auto-indent on newline optional
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
91 ;;;
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
92 ;;; Revision 3.0 1999/08/03 04:59:02 blaak
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
93 ;;; Re-release as an official Emacs language mode
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 ;;;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 (eval-and-compile
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 ;; Allow execution on pre Emacs 20 versions.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98 (or (fboundp 'when)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
99 (defmacro when (test &rest body)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100 `(if ,test (progn ,@body))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 (or (fboundp 'unless)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 (defmacro unless (test &rest body)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103 `(if (not ,test) (progn ,@body))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 (or (fboundp 'defgroup)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 (defmacro defgroup (group val docs &rest group-attributes)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 `(defvar ,group ,val ,docs)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 (or (fboundp 'defcustom)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 (defmacro defcustom (val-name val docs &rest custom-attributes)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 `(defvar ,val-name ,val ,docs)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 (or (fboundp 'cadr)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 (defmacro cadr (list) `(car (cdr ,list))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 (or (fboundp 'cddr)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 (defmacro cddr (list) `(cdr (cdr ,list))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 (or (fboundp 'with-current-buffer)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 (defmacro with-current-buffer (buf &rest forms)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 `(save-excursion (set-buffer ,buf) ,@forms)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 )
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 (defgroup delphi nil
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 "Major mode for editing Delphi source in Emacs"
27551
2dd8115a9f72 (delphi): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 25317
diff changeset
121 :version "21.1"
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 :group 'languages)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 (defconst delphi-debug nil
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 "True if in debug mode.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 (defcustom delphi-search-path "."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 "*Directories to search when finding external units. It is a list of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 directory strings. If only a single directory, it can be a single
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 string instead of a list. If a directory ends in \"...\" then that
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 directory is recursively searched."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 :type 'string
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 (defcustom delphi-indent-level 3
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 "*Indentation of Delphi statements with respect to containing block. E.g.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138 begin
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 // This is an indent of 3.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 end;"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 :type 'integer
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (defcustom delphi-compound-block-indent 0
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 "*Extra indentation for blocks in compound statements. E.g.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 // block indent = 0 vs // block indent = 2
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 if b then if b then
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 begin begin
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 end else begin end
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 end; else
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 begin
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 end;"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 :type 'integer
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 (defcustom delphi-case-label-indent delphi-indent-level
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 "*Extra indentation for case statement labels. E.g.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 // case indent = 0 vs // case indent = 3
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 case value of case value of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 v1: process_v1; v1: process_v1;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 v2: process_v2; v2: process_v2;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 else else
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 process_else; process_else;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 end; end;"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 :type 'integer
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 (defcustom delphi-verbose t ; nil
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 "*If true then delphi token processing progress is reported to the user."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 :type 'boolean
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
175 (defcustom delphi-tab-always-indents t
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 "*Non-nil means TAB in Delphi mode should always reindent the current line,
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 regardless of where in the line point is when the TAB command is used."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 :type 'boolean
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
181 (defcustom delphi-newline-always-indents t
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
182 "*Non-nil means NEWLINE in Delphi mode should always reindent the current
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
183 line, insert a blank line and move to the default indent column of the blank
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
184 line. If nil, then no indentation occurs, and NEWLINE does the usual
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
185 behaviour. This is useful when one needs to do customized indentation that
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
186 differs from the default."
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
187 :type 'boolean
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
188 :group 'delphi)
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
189
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 (defcustom delphi-comment-face 'font-lock-comment-face
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 "*Face used to color delphi comments."
35624
6878c61d1877 (delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents: 27647
diff changeset
192 :type 'face
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 (defcustom delphi-string-face 'font-lock-string-face
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 "*Face used to color delphi strings."
35624
6878c61d1877 (delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents: 27647
diff changeset
197 :type 'face
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 (defcustom delphi-keyword-face 'font-lock-keyword-face
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 "*Face used to color delphi keywords."
35624
6878c61d1877 (delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents: 27647
diff changeset
202 :type 'face
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205 (defcustom delphi-other-face nil
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 "*Face used to color everything else."
35624
6878c61d1877 (delphi-comment-face, delphi-string-face)
Dave Love <fx@gnu.org>
parents: 27647
diff changeset
207 :type 'face
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 :group 'delphi)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210 (defconst delphi-directives
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 '(absolute abstract assembler automated cdecl default dispid dynamic
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 export external far forward index inline message name near nodefault
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 overload override pascal private protected public published read readonly
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
214 register reintroduce resident resourcestring safecall stdcall stored
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
215 virtual write writeonly)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
216 "Delphi4 directives.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
217
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
218 (defconst delphi-keywords
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
219 (append
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
220 '(;; Keywords.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
221 and array as asm at begin case class const constructor contains
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
222 destructor dispinterface div do downto else end except exports
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223 file finalization finally for function goto if implementation implements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 in inherited initialization interface is label library mod nil not
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 of object on or out package packed procedure program property
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226 raise record repeat requires result self set shl shr then threadvar
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 to try type unit uses until var while with xor
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
228
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229 ;; These routines should be keywords, if Borland had the balls.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
230 break exit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
231
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
232 ;; We want directives to look like keywords.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
233 delphi-directives)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
234 "Delphi4 keywords.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
235
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
236 (defconst delphi-previous-terminators `(semicolon comma)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
237 "Expression/statement terminators that denote a previous expression.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
238
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
239 (defconst delphi-comments
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
240 '(comment-single-line comment-multi-line-1 comment-multi-line-2)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
241 "Tokens that represent comments.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243 (defconst delphi-strings
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
244 '(string double-quoted-string)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245 "Tokens that represent string literals.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
246
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247 (defconst delphi-whitespace `(space newline ,@delphi-comments)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248 "Tokens that are considered whitespace.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
249
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
250 (defconst delphi-routine-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
251 '(procedure function constructor destructor property)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
252 "Marks the start of a routine, or routine-ish looking expression.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
253
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
254 (defconst delphi-body-expr-statements '(if while for on)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
255 "Statements that have either a single statement or a block as a body and also
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
256 are followed by an expression.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 (defconst delphi-expr-statements `(case ,@delphi-body-expr-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259 "Expression statements contain expressions after their keyword.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
261 (defconst delphi-body-statements `(else ,@delphi-body-expr-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
262 "Statements that have either a single statement or a block as a body.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
263
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
264 (defconst delphi-expr-delimiters '(then do of)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
265 "Expression delimiter tokens.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
266
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
267 (defconst delphi-binary-ops
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
268 '(plus minus equals not-equals times divides div mod and or xor)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
269 "Delphi binary operations.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
270
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
271 (defconst delphi-visibilities '(public private protected published automated)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
272 "Class visibilities.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
273
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
274 (defconst delphi-block-statements
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
275 '(begin try case repeat initialization finalization asm)
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
276 "Statements that contain multiple substatements.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
277
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
278 (defconst delphi-mid-block-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
279 `(except finally ,@delphi-visibilities)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
280 "Statements that mark mid sections of the enclosing block.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
281
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
282 (defconst delphi-end-block-statements `(end until)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
283 "Statements that end block sections.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
284
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
285 (defconst delphi-match-block-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
286 `(,@delphi-end-block-statements ,@delphi-mid-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
287 "Statements that match the indentation of the parent block.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
288
27647
c8d739c1aaf0 Make resourcestring a declaration region, like const and var.
Ray Blaak <blaak@infomatch.com>
parents: 27551
diff changeset
289 (defconst delphi-decl-sections '(type const var label resourcestring)
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
290 "Denotes the start of a declaration section.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
292 (defconst delphi-class-types '(class object)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 "Class types.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
295 (defconst delphi-composite-types `(,@delphi-class-types record)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
296 "Types that contain declarations within them.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
297
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
298 (defconst delphi-unit-sections
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
299 '(interface implementation program library package)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
300 "Unit sections within which the indent is 0.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
301
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
302 (defconst delphi-use-clauses `(uses requires exports contains)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
303 "Statements that refer to foreign symbols.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
304
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
305 (defconst delphi-unit-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
306 `(,@delphi-use-clauses ,@delphi-unit-sections initialization finalization)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
307 "Statements indented at level 0.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
308
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
309 (defconst delphi-decl-delimiters
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
310 `(,@delphi-decl-sections ,@delphi-unit-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
311 ,@delphi-routine-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
312 "Statements that a declaration statement should align with.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
313
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
314 (defconst delphi-decl-matchers
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
315 `(begin ,@delphi-decl-sections)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
316 "Statements that should match to declaration statement indentation.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
317
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
318 (defconst delphi-enclosing-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
319 `(,@delphi-block-statements ,@delphi-mid-block-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
320 ,@delphi-decl-sections ,@delphi-use-clauses ,@delphi-routine-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
321 "Delimits an enclosing statement.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
322
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
323 (defconst delphi-previous-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
324 `(,@delphi-unit-statements ,@delphi-routine-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
325 "Delimits a previous statement.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
326
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327 (defconst delphi-previous-enclosing-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
328 `(,@delphi-block-statements ,@delphi-mid-block-statements
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
329 ,@delphi-decl-sections)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
330 "Delimits a previous enclosing statement.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
331
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
332 (defconst delphi-begin-enclosing-tokens
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
333 `(,@delphi-block-statements ,@delphi-mid-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334 "Tokens that a begin token indents from.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
336 (defconst delphi-begin-previous-tokens
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
337 `(,@delphi-decl-sections ,@delphi-routine-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
338 "Tokens that a begin token aligns with, but only if not part of a nested
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
339 routine.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
340
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
341 (defconst delphi-space-chars "\000-\011\013- ") ; all except \n
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
342 (defconst delphi-non-space-chars (concat "^" delphi-space-chars))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
343 (defconst delphi-spaces-re (concat "[" delphi-space-chars "]*"))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
344 (defconst delphi-leading-spaces-re (concat "^" delphi-spaces-re))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
345 (defconst delphi-word-chars "a-zA-Z0-9_")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
346
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
347 (defmacro delphi-save-match-data (&rest forms)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
348 ;; Executes the forms such that the current match data is preserved, so as
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
349 ;; not to disturb any existing search results.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
350 `(let ((data (match-data)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
351 (unwind-protect
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
352 (progn ,@forms)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
353 (set-match-data data))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
354
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
355 (defmacro delphi-save-excursion (&rest forms)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
356 ;; Executes the forms such that any movements have no effect, including
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
357 ;; searches.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
358 `(save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
359 (delphi-save-match-data
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
360 (let ((inhibit-point-motion-hooks t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
361 (deactivate-mark nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
362 (progn ,@forms)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
363
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
364 (defmacro delphi-save-state (&rest forms)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
365 ;; Executes the forms such that any buffer modifications do not have any side
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
366 ;; effects beyond the buffer's actual content changes.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
367 `(let ((delphi-ignore-changes t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
368 (old-supersession-threat
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
369 (symbol-function 'ask-user-about-supersession-threat))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
370 (buffer-read-only nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
371 (inhibit-read-only t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
372 (buffer-undo-list t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
373 (before-change-functions nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
374 (after-change-functions nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
375 (modified (buffer-modified-p)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
376 ;; Disable any queries about editing obsolete files.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
377 (fset 'ask-user-about-supersession-threat (lambda (fn)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
378 (unwind-protect
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
379 (progn ,@forms)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
380 (set-buffer-modified-p modified)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381 (fset 'ask-user-about-supersession-threat old-supersession-threat))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383 (defsubst delphi-is (element in-set)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
384 ;; If the element is in the set, the element cdr is returned, otherwise nil.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
385 (memq element in-set))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
386
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387 (defun delphi-string-of (start end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388 ;; Returns the buffer string from start to end.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
389 (buffer-substring-no-properties start end))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
390
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 (defun delphi-looking-at-string (p s)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
392 ;; True if point p marks the start of string s. s is not a regular
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
393 ;; expression.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
394 (let ((limit (+ p (length s))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395 (and (<= limit (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
396 (string= s (delphi-string-of p limit)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
397
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
398 (defun delphi-token-of (kind start end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
399 ;; Constructs a token from a kind symbol and its start/end points.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
400 `[,kind ,start ,end])
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
402 (defsubst delphi-token-kind (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
403 ;; Returns the kind symbol of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
404 (if token (aref token 0) nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
406 (defun delphi-set-token-kind (token to-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
407 ;; Sets the kind symbol of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
408 (if token (aset token 0 to-kind)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
409
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410 (defsubst delphi-token-start (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
411 ;; Returns the start point of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
412 (if token (aref token 1) (point-min)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
413
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
414 (defsubst delphi-token-end (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
415 ;; Returns the end point of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
416 (if token (aref token 2) (point-min)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
417
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
418 (defun delphi-set-token-start (token start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
419 ;; Sets the start point of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
420 (if token (aset token 1 start)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
421
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
422 (defun delphi-set-token-end (token end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
423 ;; Sets the end point of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
424 (if token (aset token 2 end)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
425
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
426 (defun delphi-token-string (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
427 ;; Returns the string image of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
428 (if token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
429 (delphi-string-of (delphi-token-start token) (delphi-token-end token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
430 ""))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
431
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
432 (defun delphi-in-token (p token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
433 ;; Returns true if the point p is within the token's start/end points.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
434 (and (<= (delphi-token-start token) p) (< p (delphi-token-end token))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
435
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
436 (defun delphi-column-of (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
437 ;; Returns the column of the point p.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
438 (save-excursion (goto-char p) (current-column)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
439
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
440 (defun delphi-face-of (token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
441 ;; Returns the face property appropriate for the token kind.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
442 (cond ((delphi-is token-kind delphi-comments) delphi-comment-face)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
443 ((delphi-is token-kind delphi-strings) delphi-string-face)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
444 ((delphi-is token-kind delphi-keywords) delphi-keyword-face)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
445 (delphi-other-face)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
446
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
447 (defvar delphi-progress-last-reported-point nil
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
448 "The last point at which progress was reported.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
449
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
450 (defconst delphi-parsing-progress-step 16384
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
451 "Number of chars to process before the next parsing progress report.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
452 (defconst delphi-scanning-progress-step 2048
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
453 "Number of chars to process before the next scanning progress report.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
454 (defconst delphi-fontifying-progress-step delphi-scanning-progress-step
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
455 "Number of chars to process before the next fontification progress report.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
456
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
457 (defun delphi-progress-start ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
458 ;; Initializes progress reporting.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
459 (setq delphi-progress-last-reported-point nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
460
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
461 (defun delphi-progress-done (&rest msgs)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
462 ;; Finalizes progress reporting.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
463 (setq delphi-progress-last-reported-point nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
464 (when delphi-verbose
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
465 (if (null msgs)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
466 (message "")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
467 (apply #'message msgs))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
468
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
469 (defun delphi-step-progress (p desc step-size)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
470 ;; If enough distance has elapsed since the last reported point, then report
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
471 ;; the current progress to the user.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
472 (cond ((null delphi-progress-last-reported-point)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
473 ;; This is the first progress step.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
474 (setq delphi-progress-last-reported-point p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
475
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
476 ((and delphi-verbose
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
477 (>= (abs (- p delphi-progress-last-reported-point)) step-size))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
478 ;; Report the percentage complete.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
479 (setq delphi-progress-last-reported-point p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
480 (message "%s %s ... %d%%"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
481 desc (buffer-name) (/ (* 100 p) (point-max))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
482
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
483 (defun delphi-next-line-start (&optional from-point)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
484 ;; Returns the first point of the next line.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
485 (let ((curr-point (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
486 (next nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
487 (if from-point (goto-char from-point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
488 (end-of-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
489 (setq next (min (1+ (point)) (point-max)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
490 (goto-char curr-point)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
491 next))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
492
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
493 (defun delphi-set-text-properties (from to properties)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
494 ;; Like `set-text-properties', except we do not consider this to be a buffer
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
495 ;; modification.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
496 (delphi-save-state
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
497 (set-text-properties from to properties)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
498
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
499 (defun delphi-literal-kind (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
500 ;; Returns the literal kind the point p is in (or nil if not in a literal).
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
501 (if (and (<= (point-min) p) (<= p (point-max)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
502 (get-text-property p 'token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
503
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
504 (defun delphi-literal-start-pattern (literal-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
505 ;; Returns the start pattern of the literal kind.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
506 (cdr (assoc literal-kind
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
507 '((comment-single-line . "//")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
508 (comment-multi-line-1 . "{")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
509 (comment-multi-line-2 . "(*")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
510 (string . "'")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
511 (double-quoted-string . "\"")))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
512
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
513 (defun delphi-literal-end-pattern (literal-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
514 ;; Returns the end pattern of the literal kind.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
515 (cdr (assoc literal-kind
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
516 '((comment-single-line . "\n")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
517 (comment-multi-line-1 . "}")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
518 (comment-multi-line-2 . "*)")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
519 (string . "'")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
520 (double-quoted-string . "\"")))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
521
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
522 (defun delphi-literal-stop-pattern (literal-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
523 ;; Returns the pattern that delimits end of the search for the literal kind.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
524 ;; These are regular expressions.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
525 (cdr (assoc literal-kind
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
526 '((comment-single-line . "\n")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
527 (comment-multi-line-1 . "}")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
528 (comment-multi-line-2 . "\\*)")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
529 ;; Strings cannot span lines.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
530 (string . "['\n]")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
531 (double-quoted-string . "[\"\n]")))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
532
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
533 (defun delphi-is-literal-start (p)
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
534 ;; True if the point p is at the start point of a (completed) literal.
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
535 (let* ((kind (delphi-literal-kind p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
536 (pattern (delphi-literal-start-pattern kind)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
537 (or (null kind) ; Non-literals are considered as start points.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
538 (delphi-looking-at-string p pattern))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
539
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
540 (defun delphi-is-literal-end (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
541 ;; True if the point p is at the end point of a (completed) literal.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
542 (let* ((kind (delphi-literal-kind (1- p)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
543 (pattern (delphi-literal-end-pattern kind)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
544 (or (null kind) ; Non-literals are considered as end points.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
545
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
546 (and (delphi-looking-at-string (- p (length pattern)) pattern)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
547 (or (not (delphi-is kind delphi-strings))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
548 ;; Special case: string delimiters are start/end ambiguous.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
549 ;; We have an end only if there is some string content (at
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
550 ;; least a starting delimiter).
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
551 (not (delphi-is-literal-end (1- p)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
552
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
553 ;; Special case: strings cannot span lines.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
554 (and (delphi-is kind delphi-strings) (eq ?\n (char-after (1- p)))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
555
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
556 (defun delphi-is-stable-literal (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
557 ;; True if the point p marks a stable point. That is, a point outside of a
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
558 ;; literal region, inside of a literal region, or adjacent to completed
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
559 ;; literal regions.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
560 (let ((at-start (delphi-is-literal-start p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
561 (at-end (delphi-is-literal-end p)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
562 (or (>= p (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
563 (and at-start at-end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
564 (and (not at-start) (not at-end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
565 (eq (delphi-literal-kind (1- p)) (delphi-literal-kind p))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
566
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
567 (defun delphi-complete-literal (literal-kind limit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
568 ;; Continues the search for a literal's true end point and returns the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
569 ;; point past the end pattern (if found) or the limit (if not found).
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
570 (let ((pattern (delphi-literal-stop-pattern literal-kind)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
571 (if (not (stringp pattern))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
572 (error "Invalid literal kind %S" literal-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
573 ;; Search up to the limit.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
574 (re-search-forward pattern limit 'goto-limit-on-fail)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
575 (point))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
576
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
577 (defun delphi-literal-text-properties (kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
578 ;; Creates a list of text properties for the literal kind.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
579 (if (and (boundp 'font-lock-mode)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
580 font-lock-mode)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
581 (list 'token kind 'face (delphi-face-of kind) 'lazy-lock t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
582 (list 'token kind)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
583
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
584 (defun delphi-parse-next-literal (limit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
585 ;; Searches for the next literal region (i.e. comment or string) and sets the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
586 ;; the point to its end (or the limit, if not found). The literal region is
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
587 ;; marked as such with a text property, to speed up tokenizing during face
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
588 ;; coloring and indentation scanning.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
589 (let ((search-start (point)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
590 (cond ((not (delphi-is-literal-end search-start))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
591 ;; We are completing an incomplete literal.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
592 (let ((kind (delphi-literal-kind (1- search-start))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
593 (delphi-complete-literal kind limit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
594 (delphi-set-text-properties
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
595 search-start (point) (delphi-literal-text-properties kind))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
596
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
597 ((re-search-forward
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
598 "\\(//\\)\\|\\({\\)\\|\\((\\*\\)\\|\\('\\)\\|\\(\"\\)"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
599 limit 'goto-limit-on-fail)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
600 ;; We found the start of a new literal. Find its end and mark it.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
601 (let ((kind (cond ((match-beginning 1) 'comment-single-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
602 ((match-beginning 2) 'comment-multi-line-1)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
603 ((match-beginning 3) 'comment-multi-line-2)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
604 ((match-beginning 4) 'string)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
605 ((match-beginning 5) 'double-quoted-string)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
606 (start (match-beginning 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
607 (delphi-set-text-properties search-start start nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
608 (delphi-complete-literal kind limit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
609 (delphi-set-text-properties
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
610 start (point) (delphi-literal-text-properties kind))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
611
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
612 ;; Nothing found. Mark it as a non-literal.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
613 ((delphi-set-text-properties search-start limit nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
614 (delphi-step-progress (point) "Parsing" delphi-parsing-progress-step)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
615
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
616 (defun delphi-literal-token-at (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
617 ;; Returns the literal token surrounding the point p, or nil if none.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
618 (let ((kind (delphi-literal-kind p)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
619 (when kind
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
620 (let ((start (previous-single-property-change (1+ p) 'token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
621 (end (next-single-property-change p 'token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
622 (delphi-token-of kind (or start (point-min)) (or end (point-max)))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
623
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
624 (defun delphi-point-token-at (p kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
625 ;; Returns the single character token at the point p.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
626 (delphi-token-of kind p (1+ p)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
627
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
628 (defsubst delphi-char-token-at (p char kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
629 ;; Returns the token at the point p that describes the specified character.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
630 ;; If not actually over such a character, nil is returned.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
631 (when (eq char (char-after p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
632 (delphi-token-of kind p (1+ p))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
633
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
634 (defun delphi-charset-token-at (p charset kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
635 ;; Returns the token surrounding point p that contains only members of the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
636 ;; character set.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
637 (let ((currp (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
638 (end nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
639 (start nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
640 (token nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
641 (goto-char p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
642 (when (> (skip-chars-forward charset) 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
643 (setq end (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
644 (goto-char (1+ p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
645 (skip-chars-backward charset)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
646 (setq token (delphi-token-of kind (point) end)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
647 (goto-char currp)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
648 token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
649
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
650 (defun delphi-space-token-at (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
651 ;; If point p is surrounded by space characters, then return the token of the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
652 ;; contiguous spaces.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
653 (delphi-charset-token-at p delphi-space-chars 'space))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
654
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
655 (defun delphi-word-token-at (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
656 ;; If point p is over a word (i.e. identifier characters), then return a word
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
657 ;; token. If the word is actually a keyword, then return the keyword token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
658 (let ((word (delphi-charset-token-at p delphi-word-chars 'word)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
659 (when word
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
660 (let* ((word-image (downcase (delphi-token-string word)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
661 (keyword (intern-soft word-image)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
662 (when (and (or keyword (string= "nil" word-image))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
663 (delphi-is keyword delphi-keywords))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
664 (delphi-set-token-kind word keyword))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
665 word))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
666
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
667 (defun delphi-explicit-token-at (p token-string kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
668 ;; If point p is anywhere in the token string then returns the resulting
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
669 ;; token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
670 (let ((token (delphi-charset-token-at p token-string kind)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
671 (when (and token (string= token-string (delphi-token-string token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
672 token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
673
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
674 (defun delphi-token-at (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
675 ;; Returns the token from parsing text at point p.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
676 (when (and (<= (point-min) p) (<= p (point-max)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
677 (cond ((delphi-literal-token-at p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
678
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
679 ((delphi-space-token-at p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
680
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
681 ((delphi-word-token-at p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
682
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
683 ((delphi-char-token-at p ?\( 'open-group))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
684 ((delphi-char-token-at p ?\) 'close-group))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
685 ((delphi-char-token-at p ?\[ 'open-group))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
686 ((delphi-char-token-at p ?\] 'close-group))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
687 ((delphi-char-token-at p ?\n 'newline))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
688 ((delphi-char-token-at p ?\; 'semicolon))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
689 ((delphi-char-token-at p ?. 'dot))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
690 ((delphi-char-token-at p ?, 'comma))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
691 ((delphi-char-token-at p ?= 'equals))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
692 ((delphi-char-token-at p ?+ 'plus))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
693 ((delphi-char-token-at p ?- 'minus))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
694 ((delphi-char-token-at p ?* 'times))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
695 ((delphi-char-token-at p ?/ 'divides))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
696 ((delphi-char-token-at p ?: 'colon))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
697
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
698 ((delphi-explicit-token-at p "<>" 'not-equals))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
699
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
700 ((delphi-point-token-at p 'punctuation)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
701
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
702 (defun delphi-current-token ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
703 ;; Returns the delphi source token under the current point.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
704 (delphi-token-at (point)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
705
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
706 (defun delphi-next-token (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
707 ;; Returns the token after the specified token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
708 (when token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
709 (let ((next (delphi-token-at (delphi-token-end token))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
710 (if next
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
711 (delphi-step-progress (delphi-token-start next) "Scanning"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
712 delphi-scanning-progress-step))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
713 next)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
714
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
715 (defun delphi-previous-token (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
716 ;; Returns the token before the specified token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
717 (when token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
718 (let ((previous (delphi-token-at (1- (delphi-token-start token)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
719 (if previous
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
720 (delphi-step-progress (delphi-token-start previous) "Scanning"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
721 delphi-scanning-progress-step))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
722 previous)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
723
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
724 (defun delphi-next-visible-token (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
725 ;; Returns the first non-space token after the specified token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
726 (let (next-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
727 (while (progn
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
728 (setq next-token (delphi-next-token token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
729 (delphi-is (delphi-token-kind next-token) '(space newline))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
730 next-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
731
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
732 (defun delphi-parse-region (from to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
733 ;; Parses the literal tokens in the region. The point is set to "to".
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
734 (save-restriction
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
735 (widen)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
736 (goto-char from)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
737 (while (< (point) to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
738 (delphi-parse-next-literal to))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
739
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
740 (defun delphi-parse-region-until-stable (from to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
741 ;; Parses at least the literal tokens in the region. After that, parsing
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
742 ;; continues as long as obsolete literal regions are encountered. The point
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
743 ;; is set to the encountered stable point.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
744 (save-restriction
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
745 (widen)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
746 (delphi-parse-region from to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
747 (while (not (delphi-is-stable-literal (point)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
748 (delphi-parse-next-literal (point-max)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
749
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
750 (defun delphi-fontify-region (from to &optional verbose)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
751 ;; Colors the text in the region according to Delphi rules.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
752 (delphi-save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
753 (delphi-save-state
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
754 (let ((p from)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
755 (delphi-verbose verbose)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
756 (token nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
757 (delphi-progress-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
758 (while (< p to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
759 ;; Color the token and move past it.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
760 (setq token (delphi-token-at p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
761 (add-text-properties
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
762 (delphi-token-start token) (delphi-token-end token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
763 (list 'face (delphi-face-of (delphi-token-kind token)) 'lazy-lock t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
764 (setq p (delphi-token-end token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
765 (delphi-step-progress p "Fontifying" delphi-fontifying-progress-step))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
766 (delphi-progress-done)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
767
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
768 (defconst delphi-ignore-changes t
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
769 "Internal flag to control if the delphi-mode responds to buffer changes.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
770 Defaults to t in case the delphi-after-change function is called on a
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
771 non-delphi buffer. Set to nil in a delphi buffer. To override, just do:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
772 (let ((delphi-ignore-changes t)) ...)")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
773
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
774 (defun delphi-after-change (change-start change-end old-length)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
775 ;; Called when the buffer has changed. Reparses the changed region.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
776 (unless delphi-ignore-changes
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
777 (let ((delphi-ignore-changes t)) ; Prevent recursive calls.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
778 (delphi-save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
779 (delphi-progress-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
780 ;; Reparse at least from the token previous to the change to the end of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
781 ;; line after the change.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
782 (delphi-parse-region-until-stable
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
783 (delphi-token-start (delphi-token-at (1- change-start)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
784 (progn (goto-char change-end) (end-of-line) (point)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
785 (delphi-progress-done)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
786
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
787 (defun delphi-group-start (from-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
788 ;; Returns the token that denotes the start of the ()/[] group.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
789 (let ((token (delphi-previous-token from-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
790 (token-kind nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
791 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
792 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
793 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
794 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
795 ;; Skip over nested groups.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
796 ((eq 'close-group token-kind) (setq token (delphi-group-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
797 ((eq 'open-group token-kind) (throw 'done token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
798 (setq token (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
799 ;; Start not found.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
800 nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
801
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
802 (defun delphi-group-end (from-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
803 ;; Returns the token that denotes the end of the ()/[] group.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
804 (let ((token (delphi-next-token from-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
805 (token-kind nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
806 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
807 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
808 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
809 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
810 ;; Skip over nested groups.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
811 ((eq 'open-group token-kind) (setq token (delphi-group-end token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
812 ((eq 'close-group token-kind) (throw 'done token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
813 (setq token (delphi-next-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
814 ;; end not found.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
815 nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
816
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
817 (defun delphi-indent-of (token &optional offset)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
818 ;; Returns the start column of the token, plus any offset.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
819 (let ((indent (+ (delphi-column-of (delphi-token-start token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
820 (if offset offset 0))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
821 (when delphi-debug
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
822 (delphi-debug-log
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
823 (concat "\n Indent of: %S %S"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
824 "\n column: %d indent: %d offset: %d")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
825 token (delphi-token-string token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
826 (delphi-column-of (delphi-token-start token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
827 indent (if offset offset 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
828 indent))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
829
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
830 (defun delphi-line-indent-of (from-token &optional offset &rest terminators)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
831 ;; Returns the column of first non-space character on the token's line, plus
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
832 ;; any offset. We also stop if one of the terminators or an open ( or [ is
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
833 ;; encountered.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
834 (let ((token (delphi-previous-token from-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
835 (last-token from-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
836 (kind nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
837 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
838 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
839 (setq kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
840 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
841 ;; Skip over ()/[] groups.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
842 ((eq 'close-group kind) (setq token (delphi-group-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
843
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
844 ;; Stop at the beginning of the line or an open group.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
845 ((delphi-is kind '(newline open-group)) (throw 'done nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
846
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
847 ;; Stop at one of the specified terminators.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
848 ((delphi-is kind terminators) (throw 'done nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
849 (unless (delphi-is kind delphi-whitespace) (setq last-token token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
850 (setq token (delphi-previous-token token))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
851 (delphi-indent-of last-token offset)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
852
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
853 (defun delphi-stmt-line-indent-of (from-token &optional offset)
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
854 ;; Like `delphi-line-indent-of' except is also stops on a use clause, and
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
855 ;; colons that precede statements (i.e. case labels).
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
856 (let ((token (delphi-previous-token from-token))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
857 (last-token from-token)
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
858 (kind nil))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
859 (catch 'done
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
860 (while token
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
861 (setq kind (delphi-token-kind token))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
862 (cond
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
863 ((and (eq 'colon kind)
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
864 (delphi-is (delphi-token-kind last-token)
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
865 `(,@delphi-block-statements
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
866 ,@delphi-expr-statements)))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
867 ;; We hit a label followed by a statement. Indent to the statement.
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
868 (throw 'done nil))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
869
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
870 ;; Skip over ()/[] groups.
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
871 ((eq 'close-group kind) (setq token (delphi-group-start token)))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
872
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
873 ((delphi-is kind `(newline open-group ,@delphi-use-clauses))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
874 ;; Stop at the beginning of the line, an open group, or a use clause
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
875 (throw 'done nil)))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
876 (unless (delphi-is kind delphi-whitespace) (setq last-token token))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
877 (setq token (delphi-previous-token token))))
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
878 (delphi-indent-of last-token offset)))
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
879
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
880 (defun delphi-open-group-indent (token last-token &optional offset)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
881 ;; Returns the indent relative to an unmatched ( or [.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
882 (when (eq 'open-group (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
883 (if last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
884 (delphi-indent-of last-token offset)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
885 ;; There is nothing following the ( or [. Indent from its line.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
886 (delphi-stmt-line-indent-of token delphi-indent-level))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
887
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
888 (defun delphi-composite-type-start (token last-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
889 ;; Returns true (actually the last-token) if the pair equals (= class) or (=
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
890 ;; record), and nil otherwise.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
891 (if (and (eq 'equals (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
892 (delphi-is (delphi-token-kind last-token) delphi-composite-types))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
893 last-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
894
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
895 (defun delphi-is-simple-class-type (at-token limit-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
896 ;; True if at-token is the start of a simple class type. E.g.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
897 ;; class of TClass;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
898 ;; class (TBaseClass);
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
899 ;; class;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
900 (when (delphi-is (delphi-token-kind at-token) delphi-class-types)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
901 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
902 ;; Scan until the semi colon.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
903 (let ((token (delphi-next-token at-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
904 (token-kind nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
905 (limit (delphi-token-start limit-token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
906 (while (and token (<= (delphi-token-start token) limit))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
907 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
908 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
909 ;; A semicolon delimits the search.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
910 ((eq 'semicolon token-kind) (throw 'done token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
911
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
912 ;; Skip over the inheritance list.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
913 ((eq 'open-group token-kind) (setq token (delphi-group-end token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
914
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
915 ;; Only allow "of" and whitespace, and an identifier
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
916 ((delphi-is token-kind `(of word ,@delphi-whitespace)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
917
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
918 ;; Otherwise we are not in a simple class declaration.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
919 ((throw 'done nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
920 (setq token (delphi-next-token token)))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
921
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
922 (defun delphi-block-start (from-token &optional stop-on-class)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
923 ;; Returns the token that denotes the start of the block.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
924 (let ((token (delphi-previous-token from-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
925 (last-token nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
926 (token-kind nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
927 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
928 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
929 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
930 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
931 ;; Skip over nested blocks.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
932 ((delphi-is token-kind delphi-end-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
933 (setq token (delphi-block-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
934
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
935 ;; Regular block start found.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
936 ((delphi-is token-kind delphi-block-statements) (throw 'done token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
937
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
938 ;; A class/record start also begins a block.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
939 ((delphi-composite-type-start token last-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
940 (throw 'done (if stop-on-class last-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
941 )
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
942 (unless (delphi-is token-kind delphi-whitespace)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
943 (setq last-token token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
944 (setq token (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
945 ;; Start not found.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
946 nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
947
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
948 (defun delphi-else-start (from-else)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
949 ;; Returns the token of the if or case statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
950 (let ((token (delphi-previous-token from-else))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
951 (token-kind nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
952 (semicolon-count 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
953 (if-count 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
954 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
955 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
956 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
957 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
958 ;; Skip over nested groups.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
959 ((eq 'close-group token-kind) (setq token (delphi-group-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
960
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
961 ;; Skip over any nested blocks.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
962 ((delphi-is token-kind delphi-end-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
963 (setq token (delphi-block-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
964
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
965 ((eq 'semicolon token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
966 ;; Semicolon means we are looking for an enclosing if, unless we
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
967 ;; are in a case statement. Keep counts of the semicolons and decide
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
968 ;; later.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
969 (setq semicolon-count (1+ semicolon-count)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
970
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
971 ((and (eq 'if token-kind) (= semicolon-count 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
972 ;; We only can match an if when there have been no intervening
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
973 ;; semicolons.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
974 (throw 'done token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
975
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
976 ((eq 'case token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
977 ;; We have hit a case statement start.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
978 (throw 'done token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
979 (setq token (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
980 ;; No if or case statement found.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
981 nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
982
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
983 (defun delphi-comment-content-start (comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
984 ;; Returns the point of the first non-space character in the comment.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
985 (let ((kind (delphi-token-kind comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
986 (when (delphi-is kind delphi-comments)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
987 (delphi-save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
988 (goto-char (+ (delphi-token-start comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
989 (length (delphi-literal-start-pattern kind))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
990 (skip-chars-forward delphi-space-chars)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
991 (point)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
992
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
993 (defun delphi-comment-block-start (comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
994 ;; Returns the starting comment token of a contiguous // comment block. If
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
995 ;; the comment is multiline (i.e. {...} or (*...*)), the original comment is
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
996 ;; returned.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
997 (if (not (eq 'comment-single-line (delphi-token-kind comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
998 comment
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
999 ;; Scan until we run out of // comments.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1000 (let ((prev-comment comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1001 (start-comment comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1002 (kind nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1003 (while (let ((kind (delphi-token-kind prev-comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1004 (cond ((eq kind 'space))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1005 ((eq kind 'comment-single-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1006 (setq start-comment prev-comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1007 (t nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1008 (setq prev-comment (delphi-previous-token prev-comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1009 start-comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1010
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1011 (defun delphi-comment-block-end (comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1012 ;; Returns the end comment token of a contiguous // comment block. If the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1013 ;; comment is multiline (i.e. {...} or (*...*)), the original comment is
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1014 ;; returned.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1015 (if (not (eq 'comment-single-line (delphi-token-kind comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1016 comment
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1017 ;; Scan until we run out of // comments.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1018 (let ((next-comment comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1019 (end-comment comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1020 (kind nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1021 (while (let ((kind (delphi-token-kind next-comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1022 (cond ((eq kind 'space))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1023 ((eq kind 'comment-single-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1024 (setq end-comment next-comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1025 (t nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1026 (setq next-comment (delphi-next-token next-comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1027 end-comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1028
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1029 (defun delphi-on-first-comment-line (comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1030 ;; Returns true if the current point is on the first line of the comment.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1031 (save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1032 (let ((comment-start (delphi-token-start comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1033 (current-point (point)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1034 (goto-char comment-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1035 (end-of-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1036 (and (<= comment-start current-point) (<= current-point (point))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1037
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1038 (defun delphi-comment-indent-of (comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1039 ;; Returns the correct indentation for the comment.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1040 (let ((start-comment (delphi-comment-block-start comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1041 (if (and (eq start-comment comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1042 (delphi-on-first-comment-line comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1043 ;; Indent as a statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1044 (delphi-enclosing-indent-of comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1045 (save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1046 (let ((kind (delphi-token-kind comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1047 (beginning-of-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1048 (cond ((eq 'comment-single-line kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1049 ;; Indent to the first comment in the // block.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1050 (delphi-indent-of start-comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1051
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1052 ((looking-at (concat delphi-leading-spaces-re
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1053 (delphi-literal-stop-pattern kind)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1054 ;; Indent multi-line comment terminators to the comment start.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1055 (delphi-indent-of comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1056
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1057 ;; Indent according to the comment's content start.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1058 ((delphi-column-of (delphi-comment-content-start comment)))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1059 ))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1060
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1061 (defun delphi-is-use-clause-end (at-token last-token last-colon from-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1062 ;; True if we are after the end of a uses type clause.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1063 (when (and last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1064 (not last-colon)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1065 (eq 'comma (delphi-token-kind at-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1066 (eq 'semicolon from-kind))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1067 ;; Scan for the uses statement, just to be sure.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1068 (let ((token (delphi-previous-token at-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1069 (token-kind nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1070 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1071 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1072 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1073 (cond ((delphi-is token-kind delphi-use-clauses)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1074 (throw 'done t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1075
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1076 ;; Whitespace, identifiers, strings, "in" keyword, and commas
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1077 ;; are allowed in use clauses.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1078 ((or (delphi-is token-kind '(word comma in newline))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1079 (delphi-is token-kind delphi-whitespace)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1080 (delphi-is token-kind delphi-strings)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1081
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1082 ;; Nothing else is.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1083 ((throw 'done nil)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1084 (setq token (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1085 nil))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1086
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1087 (defun delphi-is-block-after-expr-statement (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1088 ;; Returns true if we have a block token trailing an expression delimiter (of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1089 ;; presumably an expression statement).
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1090 (when (delphi-is (delphi-token-kind token) delphi-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1091 (let ((previous (delphi-previous-token token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1092 (previous-kind nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1093 (while (progn
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1094 (setq previous-kind (delphi-token-kind previous))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1095 (eq previous-kind 'space))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1096 (setq previous (delphi-previous-token previous)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1097 (or (delphi-is previous-kind delphi-expr-delimiters)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1098 (eq previous-kind 'else)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1099
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1100 (defun delphi-previous-indent-of (from-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1101 ;; Returns the indentation of the previous statement of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1102 (let ((token (delphi-previous-token from-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1103 (token-kind nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1104 (from-kind (delphi-token-kind from-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1105 (last-colon nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1106 (last-token nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1107 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1108 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1109 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1110 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1111 ;; An open ( or [ always is an indent point.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1112 ((eq 'open-group token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1113 (throw 'done (delphi-open-group-indent token last-token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1114
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1115 ;; Skip over any ()/[] groups.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1116 ((eq 'close-group token-kind) (setq token (delphi-group-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1117
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1118 ((delphi-is token-kind delphi-end-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1119 (if (eq 'newline (delphi-token-kind (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1120 ;; We can stop at an end token that is right up against the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1121 ;; margin.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1122 (throw 'done 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1123 ;; Otherwise, skip over any nested blocks.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1124 (setq token (delphi-block-start token))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1125
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1126 ;; Special case: if we encounter a ", word;" then we assume that we
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1127 ;; are in some kind of uses clause, and thus indent to column 0. This
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1128 ;; works because no other constructs are known to have that form.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1129 ;; This fixes the irritating case of having indents after a uses
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1130 ;; clause look like:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1131 ;; uses
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1132 ;; someUnit,
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1133 ;; someOtherUnit;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1134 ;; // this should be at column 0!
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1135 ((delphi-is-use-clause-end token last-token last-colon from-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1136 (throw 'done 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1137
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1138 ;; A previous terminator means we can stop. If we are on a directive,
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1139 ;; however, then we are not actually encountering a new statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1140 ((and last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1141 (delphi-is token-kind delphi-previous-terminators)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1142 (not (delphi-is (delphi-token-kind last-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1143 delphi-directives)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1144 (throw 'done (delphi-stmt-line-indent-of last-token 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1145
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1146 ;; Ignore whitespace.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1147 ((delphi-is token-kind delphi-whitespace))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1148
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1149 ;; Remember any ':' we encounter, since that affects how we indent to
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1150 ;; a case statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1151 ((eq 'colon token-kind) (setq last-colon token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1152
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1153 ;; A case statement delimits a previous statement. We indent labels
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1154 ;; specially.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1155 ((eq 'case token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1156 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1157 (if last-colon (delphi-line-indent-of last-colon)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1158 (delphi-line-indent-of token delphi-case-label-indent))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1159
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1160 ;; If we are in a use clause then commas mark an enclosing rather than
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1161 ;; a previous statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1162 ((delphi-is token-kind delphi-use-clauses)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1163 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1164 (if (eq 'comma from-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1165 (if last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1166 ;; Indent to first unit in use clause.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1167 (delphi-indent-of last-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1168 ;; Indent from use clause keyword.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1169 (delphi-line-indent-of token delphi-indent-level))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1170 ;; Indent to use clause keyword.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1171 (delphi-line-indent-of token))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1172
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1173 ;; Assembly sections always indent in from the asm keyword.
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1174 ((eq token-kind 'asm)
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1175 (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level)))
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1176
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1177 ;; An enclosing statement delimits a previous statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1178 ;; We try to use the existing indent of the previous statement,
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1179 ;; otherwise we calculate from the enclosing statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1180 ((delphi-is token-kind delphi-previous-enclosing-statements)
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1181 (throw 'done (if last-token
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1182 ;; Otherwise indent to the last token
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1183 (delphi-line-indent-of last-token)
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1184 ;; Just indent from the enclosing keyword
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1185 (delphi-line-indent-of token delphi-indent-level))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1186
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1187 ;; A class or record declaration also delimits a previous statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1188 ((delphi-composite-type-start token last-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1189 (throw
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1190 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1191 (if (delphi-is-simple-class-type last-token from-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1192 ;; c = class; or c = class of T; are previous statements.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1193 (delphi-line-indent-of token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1194 ;; Otherwise c = class ... or r = record ... are enclosing
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1195 ;; statements.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1196 (delphi-line-indent-of last-token delphi-indent-level))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1197
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1198 ;; We have a definite previous statement delimiter.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1199 ((delphi-is token-kind delphi-previous-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1200 (throw 'done (delphi-stmt-line-indent-of token 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1201 )
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1202 (unless (delphi-is token-kind delphi-whitespace)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1203 (setq last-token token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1204 (setq token (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1205 ;; We ran out of tokens. Indent to column 0.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1206 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1207
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1208 (defun delphi-section-indent-of (section-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1209 ;; Returns the indentation appropriate for begin/var/const/type/label
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1210 ;; tokens.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1211 (let* ((token (delphi-previous-token section-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1212 (token-kind nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1213 (last-token nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1214 (nested-block-count 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1215 (expr-delimited nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1216 (last-terminator nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1217 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1218 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1219 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1220 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1221 ;; Always stop at unmatched ( or [.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1222 ((eq token-kind 'open-group)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1223 (throw 'done (delphi-open-group-indent token last-token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1224
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1225 ;; Skip over any ()/[] groups.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1226 ((eq 'close-group token-kind) (setq token (delphi-group-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1227
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1228 ((delphi-is token-kind delphi-end-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1229 (if (eq 'newline (delphi-token-kind (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1230 ;; We can stop at an end token that is right up against the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1231 ;; margin.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1232 (throw 'done 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1233 ;; Otherwise, skip over any nested blocks.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1234 (setq token (delphi-block-start token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1235 nested-block-count (1+ nested-block-count))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1236
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1237 ;; Remember if we have encountered any forward routine declarations.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1238 ((eq 'forward token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1239 (setq nested-block-count (1+ nested-block-count)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1240
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1241 ;; Mark the completion of a nested routine traversal.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1242 ((and (delphi-is token-kind delphi-routine-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1243 (> nested-block-count 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1244 (setq nested-block-count (1- nested-block-count)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1245
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1246 ;; Remember if we have encountered any statement terminators.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1247 ((eq 'semicolon token-kind) (setq last-terminator token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1248
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1249 ;; Remember if we have encountered any expression delimiters.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1250 ((delphi-is token-kind delphi-expr-delimiters)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1251 (setq expr-delimited token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1252
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1253 ;; Enclosing body statements are delimiting. We indent the compound
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1254 ;; bodies specially.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1255 ((and (not last-terminator)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1256 (delphi-is token-kind delphi-body-statements))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1257 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1258 (delphi-stmt-line-indent-of token delphi-compound-block-indent)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1259
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1260 ;; An enclosing ":" means a label.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1261 ((and (eq 'colon token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1262 (delphi-is (delphi-token-kind section-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1263 delphi-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1264 (not last-terminator)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1265 (not expr-delimited)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1266 (not (eq 'equals (delphi-token-kind last-token))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1267 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1268 (delphi-stmt-line-indent-of token delphi-indent-level)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1269
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1270 ;; Block and mid block tokens are always enclosing
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1271 ((delphi-is token-kind delphi-begin-enclosing-tokens)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1272 (throw 'done
25161
ae69eef1b98b checked in with -k by blaak at 1999/08/03 06:17:58
Ray Blaak <blaak@infomatch.com>
parents: 25072
diff changeset
1273 (delphi-stmt-line-indent-of token delphi-indent-level)))
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1274
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1275 ;; Declaration sections and routines are delimiters, unless they
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1276 ;; are part of a nested routine.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1277 ((and (delphi-is token-kind delphi-decl-delimiters)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1278 (= 0 nested-block-count))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1279 (throw 'done (delphi-line-indent-of token 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1280
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1281 ;; Unit statements mean we indent right to the left.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1282 ((delphi-is token-kind delphi-unit-statements) (throw 'done 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1283 )
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1284 (unless (delphi-is token-kind delphi-whitespace)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1285 (setq last-token token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1286 (setq token (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1287 ;; We ran out of tokens. Indent to column 0.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1288 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1289
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1290 (defun delphi-enclosing-indent-of (from-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1291 ;; Returns the indentation offset from the enclosing statement of the token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1292 (let ((token (delphi-previous-token from-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1293 (from-kind (delphi-token-kind from-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1294 (token-kind nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1295 (stmt-start nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1296 (last-token nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1297 (equals-encountered nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1298 (before-equals nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1299 (expr-delimited nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1300 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1301 (while token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1302 (setq token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1303 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1304 ;; An open ( or [ always is an indent point.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1305 ((eq 'open-group token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1306 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1307 (delphi-open-group-indent
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1308 token last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1309 (if (delphi-is from-kind delphi-binary-ops)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1310 ;; Keep binary operations aligned with the open group.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1311 0
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1312 delphi-indent-level))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1313
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1314 ;; Skip over any ()/[] groups.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1315 ((eq 'close-group token-kind) (setq token (delphi-group-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1316
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1317 ;; Skip over any nested blocks.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1318 ((delphi-is token-kind delphi-end-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1319 (setq token (delphi-block-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1320
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1321 ;; An expression delimiter affects indentation depending on whether
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1322 ;; the point is before or after it. Remember that we encountered one.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1323 ;; Also remember the last encountered token, since if it exists it
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1324 ;; should be the actual indent point.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1325 ((delphi-is token-kind delphi-expr-delimiters)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1326 (setq expr-delimited token stmt-start last-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1327
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1328 ;; With a non-delimited expression statement we indent after the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1329 ;; statement's keyword, unless we are on the delimiter itself.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1330 ((and (not expr-delimited)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1331 (delphi-is token-kind delphi-expr-statements))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1332 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1333 (cond ((delphi-is from-kind delphi-expr-delimiters)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1334 ;; We are indenting a delimiter. Indent to the statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1335 (delphi-stmt-line-indent-of token 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1336
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1337 ((and last-token (delphi-is from-kind delphi-binary-ops))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1338 ;; Align binary ops with the expression.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1339 (delphi-indent-of last-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1340
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1341 (last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1342 ;; Indent in from the expression.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1343 (delphi-indent-of last-token delphi-indent-level))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1344
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1345 ;; Indent in from the statement's keyword.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1346 ((delphi-indent-of token delphi-indent-level)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1347
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1348 ;; A delimited case statement indents the label according to
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1349 ;; a special rule.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1350 ((eq 'case token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1351 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1352 (if stmt-start
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1353 ;; We are not actually indenting to the case statement,
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1354 ;; but are within a label expression.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1355 (delphi-stmt-line-indent-of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1356 stmt-start delphi-indent-level)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1357 ;; Indent from the case keyword.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1358 (delphi-stmt-line-indent-of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1359 token delphi-case-label-indent))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1360
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1361 ;; Body expression statements are enclosing. Indent from the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1362 ;; statement's keyword, unless we have a non-block statement following
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1363 ;; it.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1364 ((delphi-is token-kind delphi-body-expr-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1365 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1366 (delphi-stmt-line-indent-of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1367 (or stmt-start token) delphi-indent-level)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1368
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1369 ;; An else statement is enclosing, but it doesn't have an expression.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1370 ;; Thus we take into account last-token instead of stmt-start.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1371 ((eq 'else token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1372 (throw 'done (delphi-stmt-line-indent-of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1373 (or last-token token) delphi-indent-level)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1374
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1375 ;; We indent relative to an enclosing declaration section.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1376 ((delphi-is token-kind delphi-decl-sections)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1377 (throw 'done (delphi-indent-of (if last-token last-token token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1378 delphi-indent-level)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1379
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1380 ;; In unit sections we indent right to the left.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1381 ((delphi-is token-kind delphi-unit-sections) (throw 'done 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1382
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1383 ;; A previous terminator means we can stop.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1384 ((delphi-is token-kind delphi-previous-terminators)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1385 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1386 (cond ((and last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1387 (eq 'comma token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1388 (delphi-is from-kind delphi-binary-ops))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1389 ;; Align binary ops with the expression.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1390 (delphi-indent-of last-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1391
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1392 (last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1393 ;; Indent in from the expression.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1394 (delphi-indent-of last-token delphi-indent-level))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1395
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1396 ;; No enclosing expression; use the previous statment's
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1397 ;; indent.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1398 ((delphi-previous-indent-of token)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1399
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1400 ;; A block statement after an expression delimiter has its start
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1401 ;; column as the expression statement. E.g.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1402 ;; if (a = b)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1403 ;; and (a != c) then begin
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1404 ;; //...
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1405 ;; end;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1406 ;; Remember it for when we encounter the expression statement start.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1407 ((delphi-is-block-after-expr-statement token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1408 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1409 (cond (last-token (delphi-indent-of last-token delphi-indent-level))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1410
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1411 ((+ (delphi-section-indent-of token) delphi-indent-level)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1412
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1413 ;; Assembly sections always indent in from the asm keyword.
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1414 ((eq token-kind 'asm)
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1415 (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level)))
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1416
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1417 ;; Stop at an enclosing statement and indent from it.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1418 ((delphi-is token-kind delphi-enclosing-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1419 (throw 'done (delphi-stmt-line-indent-of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1420 (or last-token token) delphi-indent-level)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1421
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1422 ;; A class/record declaration is also enclosing.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1423 ((delphi-composite-type-start token last-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1424 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1425 (delphi-line-indent-of last-token delphi-indent-level)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1426
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1427 ;; A ":" we indent relative to its line beginning. If we are in a
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1428 ;; parameter list, then stop also if we hit a ";".
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1429 ((and (eq token-kind 'colon)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1430 (not expr-delimited)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1431 (not (delphi-is from-kind delphi-expr-delimiters))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1432 (not equals-encountered)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1433 (not (eq from-kind 'equals)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1434 (throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1435 (if last-token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1436 (delphi-indent-of last-token delphi-indent-level)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1437 (delphi-line-indent-of token delphi-indent-level 'semicolon))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1438
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1439 ;; If the ":" was not processed above and we have token after the "=",
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1440 ;; then indent from the "=". Ignore :=, however.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1441 ((and (eq token-kind 'colon) equals-encountered before-equals)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1442 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1443 ;; Ignore binary ops for now. It would do, for example:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1444 ;; val := 1 + 2
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1445 ;; + 3;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1446 ;; which is good, but also
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1447 ;; val := Foo
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1448 ;; (foo, args)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1449 ;; + 2;
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1450 ;; which doesn't look right.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1451 ;;;; Align binary ops with the before token.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1452 ;;((delphi-is from-kind delphi-binary-ops)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1453 ;;(throw 'done (delphi-indent-of before-equals 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1454
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1455 ;; Assignments (:=) we skip over to get a normal indent.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1456 ((eq (delphi-token-kind last-token) 'equals))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1457
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1458 ;; Otherwise indent in from the equals.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1459 ((throw 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1460 (delphi-indent-of before-equals delphi-indent-level)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1461
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1462 ;; Remember any "=" we encounter if it has not already been processed.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1463 ((eq token-kind 'equals)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1464 (setq equals-encountered token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1465 before-equals last-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1466 )
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1467 (unless (delphi-is token-kind delphi-whitespace)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1468 (setq last-token token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1469 (setq token (delphi-previous-token token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1470 ;; We ran out of tokens. Indent to column 0.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1471 0)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1472
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1473 (defun delphi-corrected-indentation ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1474 ;; Returns the corrected indentation for the current line.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1475 (delphi-save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1476 (delphi-progress-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1477 ;; Move to the first token on the line.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1478 (beginning-of-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1479 (skip-chars-forward delphi-space-chars)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1480 (let* ((token (delphi-current-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1481 (token-kind (delphi-token-kind token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1482 (indent
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1483 (cond ((eq 'close-group token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1484 ;; Indent to the matching start ( or [.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1485 (delphi-indent-of (delphi-group-start token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1486
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1487 ((delphi-is token-kind delphi-unit-statements) 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1488
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1489 ((delphi-is token-kind delphi-comments)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1490 ;; In a comment.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1491 (delphi-comment-indent-of token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1492
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1493 ((delphi-is token-kind delphi-decl-matchers)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1494 ;; Use a previous section/routine's indent.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1495 (delphi-section-indent-of token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1496
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1497 ((delphi-is token-kind delphi-match-block-statements)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1498 ;; Use the block's indentation.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1499 (let ((block-start
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1500 (delphi-block-start token 'stop-on-class)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1501 (cond
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1502 ;; When trailing a body statement, indent to
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1503 ;; the statement's keyword.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1504 ((delphi-is-block-after-expr-statement block-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1505 (delphi-section-indent-of block-start))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1506
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1507 ;; Otherwise just indent to the block start.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1508 ((delphi-stmt-line-indent-of block-start 0)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1509
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1510 ((eq 'else token-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1511 ;; Find the start of the if or case statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1512 (delphi-stmt-line-indent-of (delphi-else-start token) 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1513
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1514 ;; Otherwise indent in from enclosing statement.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1515 ((delphi-enclosing-indent-of
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1516 (if token token (delphi-token-at (1- (point)))))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1517 (delphi-progress-done)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1518 indent)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1519
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1520 (defun delphi-indent-line ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1521 "Indent the current line according to the current language construct. If
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1522 before the indent, the point is moved to the indent."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1523 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1524 (delphi-save-match-data
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1525 (let ((marked-point (point-marker)) ; Maintain our position reliably.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1526 (new-point nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1527 (line-start nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1528 (old-indent 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1529 (new-indent 0))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1530 (beginning-of-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1531 (setq line-start (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1532 (skip-chars-forward delphi-space-chars)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1533 (setq old-indent (current-column))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1534 (setq new-indent (delphi-corrected-indentation))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1535 (if (< marked-point (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1536 ;; If before the indent column, then move to it.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1537 (set-marker marked-point (point)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1538 ;; Advance our marked point after inserted spaces.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1539 (set-marker-insertion-type marked-point t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1540 (when (/= old-indent new-indent)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1541 (delete-region line-start (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1542 (insert (make-string new-indent ?\ )))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1543 (goto-char marked-point)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1544 (set-marker marked-point nil))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1545
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1546 (defvar delphi-mode-abbrev-table nil
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1547 "Abbrev table in use in delphi-mode buffers.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1548 (define-abbrev-table 'delphi-mode-abbrev-table ())
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1549
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1550 (defmacro delphi-ensure-buffer (buffer-var buffer-name)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1551 ;; Ensures there exists a buffer of the specified name in the specified
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1552 ;; variable.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1553 `(when (not (buffer-live-p ,buffer-var))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1554 (setq ,buffer-var (get-buffer-create ,buffer-name))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1555
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1556 (defun delphi-log-msg (to-buffer the-msg)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1557 ;; Writes a message to the end of the specified buffer.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1558 (with-current-buffer to-buffer
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1559 (save-selected-window
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1560 (switch-to-buffer-other-window to-buffer)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1561 (goto-char (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1562 (set-window-dot (get-buffer-window to-buffer) (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1563 (insert the-msg))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1564
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1565 ;; Debugging helpers:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1566
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1567 (defvar delphi-debug-buffer nil
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1568 "Buffer to write delphi-mode debug messages to. Created on demand.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1569
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1570 (defun delphi-debug-log (format-string &rest args)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1571 ;; Writes a message to the log buffer.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1572 (when delphi-debug
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1573 (delphi-ensure-buffer delphi-debug-buffer "*Delphi Debug Log*")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1574 (delphi-log-msg delphi-debug-buffer
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1575 (concat (format-time-string "%H:%M:%S " (current-time))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1576 (apply #'format (cons format-string args))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1577 "\n"))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1578
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1579 (defun delphi-debug-token-string (token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1580 (let* ((image (delphi-token-string token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1581 (has-newline (string-match "^\\([^\n]*\\)\n\\(.+\\)?$" image)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1582 (when has-newline
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1583 (setq image (concat (match-string 1 image)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1584 (if (match-beginning 2) "..."))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1585 image))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1586
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1587 (defun delphi-debug-show-current-token ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1588 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1589 (let ((token (delphi-current-token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1590 (delphi-debug-log "Token: %S %S" token (delphi-debug-token-string token))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1591
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1592 (defun delphi-debug-goto-point (p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1593 (interactive "NGoto char: ")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1594 (goto-char p))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1595
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1596 (defun delphi-debug-goto-next-token ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1597 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1598 (goto-char (delphi-token-start (delphi-next-token (delphi-current-token)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1599
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1600 (defun delphi-debug-goto-previous-token ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1601 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1602 (goto-char
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1603 (delphi-token-start (delphi-previous-token (delphi-current-token)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1604
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1605 (defun delphi-debug-show-current-string (from to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1606 (interactive "r")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1607 (delphi-debug-log "String: %S" (buffer-substring from to)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1608
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1609 (defun delphi-debug-show-is-stable ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1610 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1611 (delphi-debug-log "stable: %S prev: %S next: %S"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1612 (delphi-is-stable-literal (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1613 (delphi-literal-kind (1- (point)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1614 (delphi-literal-kind (point))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1615
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1616 (defun delphi-debug-unparse-buffer ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1617 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1618 (delphi-set-text-properties (point-min) (point-max) nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1619
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1620 (defun delphi-debug-parse-region (from to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1621 (interactive "r")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1622 (let ((delphi-verbose t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1623 (delphi-save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1624 (delphi-progress-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1625 (delphi-parse-region from to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1626 (delphi-progress-done "Parsing done"))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1627
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1628 (defun delphi-debug-parse-window ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1629 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1630 (delphi-debug-parse-region (window-start) (window-end)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1631
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1632 (defun delphi-debug-parse-buffer ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1633 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1634 (delphi-debug-parse-region (point-min) (point-max)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1635
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1636 (defun delphi-debug-fontify-window ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1637 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1638 (delphi-fontify-region (window-start) (window-end) t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1639
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1640 (defun delphi-debug-fontify-buffer ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1641 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1642 (delphi-fontify-region (point-min) (point-max) t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1643
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1644 (defun delphi-debug-tokenize-region (from to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1645 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1646 (delphi-save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1647 (delphi-progress-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1648 (goto-char from)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1649 (while (< (point) to)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1650 (goto-char (delphi-token-end (delphi-current-token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1651 (delphi-step-progress (point) "Tokenizing" delphi-scanning-progress-step))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1652 (delphi-progress-done "Tokenizing done")))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1653
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1654 (defun delphi-debug-tokenize-buffer ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1655 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1656 (delphi-debug-tokenize-region (point-min) (point-max)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1657
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1658 (defun delphi-debug-tokenize-window ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1659 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1660 (delphi-debug-tokenize-region (window-start) (window-end)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1661
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1662 (defun delphi-newline ()
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1663 "Terminate the current line with a newline and indent the next, unless
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1664 `delphi-newline-always-indents' is nil, in which case no reindenting occurs."
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1665 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1666 ;; Remove trailing spaces
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1667 (delete-horizontal-space)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1668 (newline)
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1669 (when delphi-newline-always-indents
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1670 ;; Indent both the (now) previous and current line first.
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1671 (save-excursion
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1672 (previous-line 1)
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1673 (delphi-indent-line))
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1674 (delphi-indent-line)))
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1675
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1676
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1677 (defun delphi-tab ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1678 "Indent the current line or insert a TAB, depending on the value of
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1679 `delphi-tab-always-indents' and the current line position."
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1680 (interactive)
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1681 (if (or delphi-tab-always-indents ; We are always indenting
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1682 ;; Or we are before the first non-space character on the line.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1683 (save-excursion (skip-chars-backward delphi-space-chars) (bolp)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1684 (delphi-indent-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1685 (insert "\t")))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1686
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1687
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1688 (defun delphi-is-directory (path)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1689 ;; True if the specified path is an existing directory.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1690 (let ((attributes (file-attributes path)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1691 (and attributes (car attributes))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1692
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1693 (defun delphi-is-file (path)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1694 ;; True if the specified file exists as a file.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1695 (let ((attributes (file-attributes path)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1696 (and attributes (null (car attributes)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1697
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1698 (defun delphi-search-directory (unit dir &optional recurse)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1699 ;; Searches for the unit in the specified directory. If recurse is true, then
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1700 ;; the directory is recursively searched. File name comparison is done in a
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1701 ;; case insensitive manner.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1702 (when (delphi-is-directory dir)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1703 (let ((files (directory-files dir))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1704 (unit-file (downcase unit)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1705 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1706 ;; Search for the file.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1707 (mapcar #'(lambda (file)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1708 (let ((path (concat dir "/" file)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1709 (if (and (string= unit-file (downcase file))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1710 (delphi-is-file path))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1711 (throw 'done path))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1712 files)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1713
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1714 ;; Not found. Search subdirectories.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1715 (when recurse
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1716 (mapcar #'(lambda (subdir)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1717 (unless (member subdir '("." ".."))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1718 (let ((path (delphi-search-directory
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1719 unit (concat dir "/" subdir) recurse)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1720 (if path (throw 'done path)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1721 files))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1722
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1723 ;; Not found.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1724 nil))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1725
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1726
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1727 (defun delphi-find-unit-in-directory (unit dir)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1728 ;; Searches for the unit in the specified directory. If the directory ends
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1729 ;; in \"...\", then it is recursively searched.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1730 (let ((dir-name dir)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1731 (recurse nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1732 ;; Check if we need to recursively search the directory.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1733 (if (string-match "^\\(.+\\)\\.\\.\\.$" dir-name)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1734 (setq dir-name (match-string 1 dir-name)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1735 recurse t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1736 ;; Ensure the trailing slash is removed.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1737 (if (string-match "^\\(.+\\)[\\\\/]$" dir-name)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1738 (setq dir-name (match-string 1 dir-name)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1739 (delphi-search-directory unit dir-name recurse)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1740
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1741 (defun delphi-find-unit-file (unit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1742 ;; Finds the specified delphi source file according to `delphi-search-path'.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1743 ;; If found, the full path is returned, otherwise nil is returned.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1744 (catch 'done
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1745 (cond ((null delphi-search-path)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1746 (delphi-find-unit-in-directory unit "."))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1747
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1748 ((stringp delphi-search-path)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1749 (delphi-find-unit-in-directory unit delphi-search-path))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1750
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1751 ((mapcar
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1752 #'(lambda (dir)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1753 (let ((file (delphi-find-unit-in-directory unit dir)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1754 (if file (throw 'done file))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1755 delphi-search-path)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1756 nil))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1757
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1758 (defun delphi-find-unit (unit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1759 "Finds the specified delphi source file according to `delphi-search-path'.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1760 If no extension is specified, .pas is assumed. Creates a buffer for the unit."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1761 (interactive "sDelphi unit name: ")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1762 (let* ((unit-file (if (string-match "^\\(.*\\)\\.[a-z]+$" unit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1763 unit
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1764 (concat unit ".pas")))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1765 (file (delphi-find-unit-file unit-file)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1766 (if (null file)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1767 (error "unit not found: %s" unit-file)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1768 (find-file file)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1769 (if (not (eq major-mode 'delphi-mode))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1770 (delphi-mode)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1771 file))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1772
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1773 (defun delphi-find-current-def ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1774 "Find the definition of the identifier under the current point."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1775 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1776 (error "delphi-find-current-def: not implemented yet"))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1777
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1778 (defun delphi-find-current-xdef ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1779 "Find the definition of the identifier under the current point, searching
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1780 in external units if necessary (as listed in the current unit's use clause).
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1781 The set of directories to search for a unit is specified by the global variable
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1782 delphi-search-path."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1783 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1784 (error "delphi-find-current-xdef: not implemented yet"))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1785
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1786 (defun delphi-find-current-body ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1787 "Find the body of the identifier under the current point, assuming
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1788 it is a routine."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1789 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1790 (error "delphi-find-current-body: not implemented yet"))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1791
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1792 (defun delphi-fill-comment ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1793 "Fills the text of the current comment, according to `fill-column'.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1794 An error is raised if not in a comment."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1795 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1796 (save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1797 (let* ((comment (delphi-current-token))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1798 (comment-kind (delphi-token-kind comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1799 (if (not (delphi-is comment-kind delphi-comments))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1800 (error "Not in a comment")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1801 (let* ((start-comment (delphi-comment-block-start comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1802 (end-comment (delphi-comment-block-end comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1803 (comment-start (delphi-token-start start-comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1804 (comment-end (delphi-token-end end-comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1805 (content-start (delphi-comment-content-start start-comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1806 (content-indent (delphi-column-of content-start))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1807 (content-prefix (make-string content-indent ?\ ))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1808 (content-prefix-re delphi-leading-spaces-re)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1809 (p nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1810 (marked-point (point-marker))) ; Maintain our position reliably.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1811 (when (eq 'comment-single-line comment-kind)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1812 ;; // style comments need more work.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1813 (setq content-prefix
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1814 (let ((comment-indent (delphi-column-of comment-start)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1815 (concat (make-string comment-indent ?\ ) "//"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1816 (make-string (- content-indent comment-indent 2)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1817 ?\ )))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1818 content-prefix-re (concat delphi-leading-spaces-re
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1819 "//"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1820 delphi-spaces-re)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1821 comment-end (if (delphi-is-literal-end comment-end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1822 ;; Don't include the trailing newline.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1823 (1- comment-end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1824 comment-end)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1825
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1826 ;; Advance our marked point after inserted spaces.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1827 (set-marker-insertion-type marked-point t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1828
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1829 ;; Ensure we can modify the buffer
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1830 (goto-char content-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1831 (insert " ")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1832 (delete-char -1)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1833
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1834 (narrow-to-region content-start comment-end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1835
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1836 ;; Strip off the comment prefixes
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1837 (setq p (point-min))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1838 (while (when (< p (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1839 (goto-char p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1840 (re-search-forward content-prefix-re nil t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1841 (replace-match "" nil nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1842 (setq p (1+ (point))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1843
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1844 ;; add an extra line to prevent the fill from doing it for us.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1845 (goto-char (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1846 (insert "\n")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1847
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1848 ;; Fill the comment contents.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1849 (let ((fill-column (- fill-column content-indent)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1850 (fill-region (point-min) (point-max)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1851
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1852 (goto-char (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1853 (delete-char -1)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1854
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1855 ;; Restore comment prefixes.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1856 (goto-char (point-min))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1857 (end-of-line) ; Don't reset the first line.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1858 (setq p (point))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1859 (while (when (< p (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1860 (goto-char p)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1861 (re-search-forward "^" nil t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1862 (replace-match content-prefix nil nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1863 (setq p (1+ (point))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1864
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1865 (setq comment-end (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1866 (widen)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1867
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1868 ;; Restore our position
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1869 (goto-char marked-point)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1870 (set-marker marked-point nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1871
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1872 ;; React to the entire fill change as a whole.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1873 (delphi-progress-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1874 (delphi-parse-region comment-start comment-end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1875 (delphi-progress-done))))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1876
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1877 (defun delphi-new-comment-line ()
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1878 "If in a // comment, does a newline, indented such that one is still in the
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1879 comment block. If not in a // comment, just does a normal newline."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1880 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1881 (let ((comment (delphi-current-token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1882 (if (not (eq 'comment-single-line (delphi-token-kind comment)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1883 ;; Not in a // comment. Just do the normal newline.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1884 (delphi-newline)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1885 (let* ((start-comment (delphi-comment-block-start comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1886 (comment-start (delphi-token-start start-comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1887 (content-start (delphi-comment-content-start start-comment))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1888 (prefix
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1889 (concat (make-string (delphi-column-of comment-start) ?\ ) "//"
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1890 (make-string (- content-start comment-start 2) ?\ ))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1891 (delete-horizontal-space)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1892 (newline)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1893 (insert prefix)))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1894
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1895 (defun delphi-match-token (token limit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1896 ;; Sets the match region used by (match-string 0) and friends to the token's
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1897 ;; region. Sets the current point to the end of the token (or limit).
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1898 (set-match-data nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1899 (if token
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1900 (let ((end (min (delphi-token-end token) limit)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1901 (set-match-data (list (delphi-token-start token) end))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1902 (goto-char end)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1903 token)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1904
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1905 (defconst delphi-font-lock-defaults
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1906 '(nil ; We have our own fontify routine, so keywords don't apply.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1907 t ; Syntactic fontification doesn't apply.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1908 nil ; Don't care about case since we don't use regexps to find tokens.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1909 nil ; Syntax alists don't apply.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1910 nil ; Syntax begin movement doesn't apply
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1911 (font-lock-fontify-region-function . delphi-fontify-region)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1912 (font-lock-verbose . delphi-fontifying-progress-step))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1913 "Delphi mode font-lock defaults. Syntactic fontification is ignored.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1914
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1915 (defvar delphi-debug-mode-map
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1916 (let ((kmap (make-sparse-keymap)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1917 (mapcar #'(lambda (binding) (define-key kmap (car binding) (cadr binding)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1918 '(("n" delphi-debug-goto-next-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1919 ("p" delphi-debug-goto-previous-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1920 ("t" delphi-debug-show-current-token)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1921 ("T" delphi-debug-tokenize-buffer)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1922 ("W" delphi-debug-tokenize-window)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1923 ("g" delphi-debug-goto-point)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1924 ("s" delphi-debug-show-current-string)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1925 ("a" delphi-debug-parse-buffer)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1926 ("w" delphi-debug-parse-window)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1927 ("f" delphi-debug-fontify-window)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1928 ("F" delphi-debug-fontify-buffer)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1929 ("r" delphi-debug-parse-region)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1930 ("c" delphi-debug-unparse-buffer)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1931 ("x" delphi-debug-show-is-stable)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1932 ))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1933 kmap)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1934 "Keystrokes for delphi-mode debug commands.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1935
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1936 (defvar delphi-mode-map
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1937 (let ((kmap (make-sparse-keymap)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1938 (mapcar #'(lambda (binding) (define-key kmap (car binding) (cadr binding)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1939 (list '("\r" delphi-newline)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1940 '("\t" delphi-tab)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1941 '("\177" backward-delete-char-untabify)
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1942 ;; '("\C-cd" delphi-find-current-def)
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1943 ;; '("\C-cx" delphi-find-current-xdef)
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1944 ;; '("\C-cb" delphi-find-current-body)
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1945 '("\C-cu" delphi-find-unit)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1946 '("\M-q" delphi-fill-comment)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1947 '("\M-j" delphi-new-comment-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1948 ;; Debug bindings:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1949 (list "\C-c\C-d" delphi-debug-mode-map)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1950 kmap)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1951 "Keymap used in Delphi mode.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1952
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1953 (defconst delphi-mode-syntax-table (make-syntax-table)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1954 "Delphi mode's syntax table. It is just a standard syntax table.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1955 This is ok since we do our own keyword/comment/string face coloring.")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1956
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1957 ;;;###autoload
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1958 (defun delphi-mode (&optional skip-initial-parsing)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1959 "Major mode for editing Delphi code. \\<delphi-mode-map>
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1960 \\[delphi-tab]\t- Indents the current line for Delphi code.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1961 \\[delphi-find-unit]\t- Search for a Delphi source file.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1962 \\[delphi-fill-comment]\t- Fill the current comment.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1963 \\[delphi-new-comment-line]\t- If in a // comment, do a new comment line.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1964
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1965 M-x indent-region also works for indenting a whole region.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1966
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1967 Customization:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1968
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1969 `delphi-indent-level' (default 3)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1970 Indentation of Delphi statements with respect to containing block.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1971 `delphi-compound-block-indent' (default 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1972 Extra indentation for blocks in compound statements.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1973 `delphi-case-label-indent' (default 0)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1974 Extra indentation for case statement labels.
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1975 `delphi-tab-always-indents' (default t)
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1976 Non-nil means TAB in Delphi mode should always reindent the current line,
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1977 regardless of where in the line point is when the TAB command is used.
25317
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1978 `delphi-newline-always-indents' (default t)
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1979 Non-nil means NEWLINE in Delphi mode should always reindent the current
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1980 line, insert a blank line and move to the default indent column of the
06136c6979f1 checked in with -k by blaak at 1999/08/18 05:08:39
Ray Blaak <blaak@infomatch.com>
parents: 25161
diff changeset
1981 blank line.
25072
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1982 `delphi-search-path' (default .)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1983 Directories to search when finding external units.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1984 `delphi-verbose' (default nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1985 If true then delphi token processing progress is reported to the user.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1986
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1987 Coloring:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1988
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1989 `delphi-comment-face' (default font-lock-comment-face)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1990 Face used to color delphi comments.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1991 `delphi-string-face' (default font-lock-string-face)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1992 Face used to color delphi strings.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1993 `delphi-keyword-face' (default font-lock-keyword-face)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1994 Face used to color delphi keywords.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1995 `delphi-other-face' (default nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1996 Face used to color everything else.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1997
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1998 Turning on Delphi mode calls the value of the variable delphi-mode-hook with
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1999 no args, if that value is non-nil."
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2000 (interactive)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2001 (kill-all-local-variables)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2002 (use-local-map delphi-mode-map)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2003 (setq major-mode 'delphi-mode)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2004 (setq mode-name "Delphi")
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2005
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2006 (setq local-abbrev-table delphi-mode-abbrev-table)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2007 (set-syntax-table delphi-mode-syntax-table)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2008
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2009 ;; Buffer locals:
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2010 (mapcar #'(lambda (var)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2011 (let ((var-symb (car var))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2012 (var-val (cadr var)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2013 (make-local-variable var-symb)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2014 (set var-symb var-val)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2015 (list '(indent-line-function delphi-indent-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2016 '(comment-indent-function delphi-indent-line)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2017 '(case-fold-search t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2018 '(delphi-progress-last-reported-point nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2019 '(delphi-ignore-changes nil)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2020 (list 'font-lock-defaults delphi-font-lock-defaults)))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2021
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2022 ;; We need to keep track of changes to the buffer to determine if we need
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2023 ;; to retokenize changed text.
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2024 (make-local-hook 'after-change-functions)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2025 (add-hook 'after-change-functions 'delphi-after-change nil t)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2026
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2027 (widen)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2028 (unless skip-initial-parsing
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2029 (delphi-save-excursion
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2030 (let ((delphi-verbose t))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2031 (delphi-progress-start)
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2032 (delphi-parse-region (point-min) (point-max))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2033 (delphi-progress-done))))
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2034
29873c097b15 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2035 (run-hooks 'delphi-mode-hook))
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35624
diff changeset
2036
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35624
diff changeset
2037 ;;; delphi.el ends here