Mercurial > emacs
annotate lisp/progmodes/pascal.el @ 16646:6aeaedabbb62
(Fend_of_line, Fbeginning_of_line): Declared.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 09 Dec 1996 00:51:15 +0000 |
parents | 9811f1144bbf |
children | b758fbf989b7 |
rev | line source |
---|---|
13337 | 1 ;;; pascal.el --- major mode for editing pascal source in Emacs |
4934 | 2 |
13337 | 3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. |
4934 | 4 |
13337 | 5 ;; Author: Espen Skoglund (espensk@stud.cs.uit.no) |
6 ;; Keywords: languages | |
4934 | 7 |
13337 | 8 ;; This file is part of GNU Emacs. |
4934 | 9 |
14183 | 10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
13337 | 11 ;; it under the terms of the GNU General Public License as published by |
14183 | 12 ;; the Free Software Foundation; either version 2, or (at your option) |
13 ;; any later version. | |
4934 | 14 |
14183 | 15 ;; GNU Emacs is distributed in the hope that it will be useful, |
13337 | 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
4934 | 19 |
13337 | 20 ;; You should have received a copy of the GNU General Public License |
14183 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to |
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
4934 | 24 |
25 ;;; Commentary: | |
26 | |
14169 | 27 ;; USAGE |
28 ;; ===== | |
5723 | 29 |
14169 | 30 ;; Emacs should enter Pascal mode when you find a Pascal source file. |
31 ;; When you have entered Pascal mode, you may get more info by pressing | |
32 ;; C-h m. You may also get online help describing various functions by: | |
33 ;; C-h f <Name of function you want described> | |
5723 | 34 |
14169 | 35 ;; If you want to customize Pascal mode to fit you better, you may add |
36 ;; these lines (the values of the variables presented here are the defaults): | |
37 ;; | |
38 ;; ;; User customization for Pascal mode | |
39 ;; (setq pascal-indent-level 3 | |
40 ;; pascal-case-indent 2 | |
41 ;; pascal-auto-newline nil | |
42 ;; pascal-tab-always-indent t | |
43 ;; pascal-auto-endcomments t | |
44 ;; pascal-auto-lineup '(all) | |
45 ;; pascal-toggle-completions nil | |
46 ;; pascal-type-keywords '("array" "file" "packed" "char" | |
47 ;; "integer" "real" "string" "record") | |
48 ;; pascal-start-keywords '("begin" "end" "function" "procedure" | |
49 ;; "repeat" "until" "while" "read" "readln" | |
50 ;; "reset" "rewrite" "write" "writeln") | |
51 ;; pascal-separator-keywords '("downto" "else" "mod" "div" "then")) | |
4934 | 52 |
14169 | 53 ;; KNOWN BUGS / BUGREPORTS |
54 ;; ======================= | |
55 ;; As far as I know, there are no bugs in the current version of this | |
56 ;; package. This may not be true however, since I never use this mode | |
57 ;; myself and therefore would never notice them anyway. If you do | |
58 ;; find any bugs, you may submit them to: espensk@stud.cs.uit.no | |
59 ;; as well as to bug-gnu-emacs@prep.ai.mit.edu. | |
5723 | 60 |
61 ;;; Code: | |
4934 | 62 |
63 (defvar pascal-mode-abbrev-table nil | |
64 "Abbrev table in use in Pascal-mode buffers.") | |
65 (define-abbrev-table 'pascal-mode-abbrev-table ()) | |
66 | |
67 (defvar pascal-mode-map () | |
68 "Keymap used in Pascal mode.") | |
5723 | 69 (if pascal-mode-map |
70 () | |
71 (setq pascal-mode-map (make-sparse-keymap)) | |
72 (define-key pascal-mode-map ";" 'electric-pascal-semi-or-dot) | |
73 (define-key pascal-mode-map "." 'electric-pascal-semi-or-dot) | |
74 (define-key pascal-mode-map ":" 'electric-pascal-colon) | |
75 (define-key pascal-mode-map "=" 'electric-pascal-equal) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
76 (define-key pascal-mode-map "#" 'electric-pascal-hash) |
5723 | 77 (define-key pascal-mode-map "\r" 'electric-pascal-terminate-line) |
78 (define-key pascal-mode-map "\t" 'electric-pascal-tab) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
79 (define-key pascal-mode-map "\M-\t" 'pascal-complete-word) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
80 (define-key pascal-mode-map "\M-?" 'pascal-show-completions) |
5723 | 81 (define-key pascal-mode-map "\177" 'backward-delete-char-untabify) |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
82 (define-key pascal-mode-map "\M-\C-h" 'pascal-mark-defun) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
83 (define-key pascal-mode-map "\C-c\C-b" 'pascal-insert-block) |
5723 | 84 (define-key pascal-mode-map "\M-*" 'pascal-star-comment) |
85 (define-key pascal-mode-map "\C-c\C-c" 'pascal-comment-area) | |
86 (define-key pascal-mode-map "\C-c\C-u" 'pascal-uncomment-area) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
87 (define-key pascal-mode-map "\M-\C-a" 'pascal-beg-of-defun) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
88 (define-key pascal-mode-map "\M-\C-e" 'pascal-end-of-defun) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
89 (define-key pascal-mode-map "\C-c\C-d" 'pascal-goto-defun) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
90 (define-key pascal-mode-map "\C-c\C-o" 'pascal-outline) |
4934 | 91 ;;; A command to change the whole buffer won't be used terribly |
92 ;;; often, so no need for a key binding. | |
5723 | 93 ; (define-key pascal-mode-map "\C-cd" 'pascal-downcase-keywords) |
94 ; (define-key pascal-mode-map "\C-cu" 'pascal-upcase-keywords) | |
95 ; (define-key pascal-mode-map "\C-cc" 'pascal-capitalize-keywords) | |
96 ) | |
12689
83ef0f002ecf
(pascal-mode): Added imenu support.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
97 |
83ef0f002ecf
(pascal-mode): Added imenu support.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
98 (defvar pascal-imenu-generic-expression |
83ef0f002ecf
(pascal-mode): Added imenu support.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
99 '("^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" . (2)) |
83ef0f002ecf
(pascal-mode): Added imenu support.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
100 "Imenu expression for Pascal-mode. See `imenu-generic-expression'.") |
5723 | 101 |
102 (defvar pascal-keywords | |
103 '("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end" | |
104 "file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of" | |
105 "or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to" | |
106 "type" "until" "var" "while" "with" | |
107 ;; The following are not standard in pascal, but widely used. | |
108 "get" "put" "input" "output" "read" "readln" "reset" "rewrite" "write" | |
109 "writeln")) | |
4934 | 110 |
5723 | 111 ;;; |
112 ;;; Regular expressions used to calculate indent, etc. | |
113 ;;; | |
114 (defconst pascal-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>") | |
115 (defconst pascal-beg-block-re "\\<\\(begin\\|case\\|record\\|repeat\\)\\>") | |
116 (defconst pascal-end-block-re "\\<\\(end\\|until\\)\\>") | |
117 (defconst pascal-declaration-re "\\<\\(const\\|label\\|type\\|var\\)\\>") | |
118 (defconst pascal-defun-re "\\<\\(function\\|procedure\\|program\\)\\>") | |
6123
3c66892f0083
(pascal-sub-block-re): Recognize for and with.
Richard M. Stallman <rms@gnu.org>
parents:
5723
diff
changeset
|
119 (defconst pascal-sub-block-re "\\<\\(if\\|else\\|for\\|while\\|with\\)\\>") |
6153
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
120 (defconst pascal-noindent-re "\\<\\(begin\\|end\\|until\\|else\\)\\>") |
5723 | 121 (defconst pascal-nosemi-re "\\<\\(begin\\|repeat\\|then\\|do\\|else\\)\\>") |
122 (defconst pascal-autoindent-lines-re | |
123 "\\<\\(label\\|var\\|type\\|const\\|until\\|end\\|begin\\|repeat\\|else\\)\\>") | |
124 | |
125 ;;; Strings used to mark beginning and end of excluded text | |
126 (defconst pascal-exclude-str-start "{-----\\/----- EXCLUDED -----\\/-----") | |
127 (defconst pascal-exclude-str-end " -----/\\----- EXCLUDED -----/\\-----}") | |
4934 | 128 |
129 (defvar pascal-mode-syntax-table nil | |
130 "Syntax table in use in Pascal-mode buffers.") | |
131 | |
132 (if pascal-mode-syntax-table | |
133 () | |
134 (setq pascal-mode-syntax-table (make-syntax-table)) | |
11104
ef10b4684bb5
(pascal-mode-syntax-table): Give \ punctuation syntax.
Richard M. Stallman <rms@gnu.org>
parents:
10534
diff
changeset
|
135 (modify-syntax-entry ?\\ "." pascal-mode-syntax-table) |
5723 | 136 (modify-syntax-entry ?( "()1" pascal-mode-syntax-table) |
137 (modify-syntax-entry ?) ")(4" pascal-mode-syntax-table) | |
4934 | 138 (modify-syntax-entry ?* ". 23" pascal-mode-syntax-table) |
5723 | 139 (modify-syntax-entry ?{ "<" pascal-mode-syntax-table) |
140 (modify-syntax-entry ?} ">" pascal-mode-syntax-table) | |
141 (modify-syntax-entry ?+ "." pascal-mode-syntax-table) | |
142 (modify-syntax-entry ?- "." pascal-mode-syntax-table) | |
143 (modify-syntax-entry ?= "." pascal-mode-syntax-table) | |
144 (modify-syntax-entry ?% "." pascal-mode-syntax-table) | |
145 (modify-syntax-entry ?< "." pascal-mode-syntax-table) | |
146 (modify-syntax-entry ?> "." pascal-mode-syntax-table) | |
147 (modify-syntax-entry ?& "." pascal-mode-syntax-table) | |
148 (modify-syntax-entry ?| "." pascal-mode-syntax-table) | |
149 (modify-syntax-entry ?_ "w" pascal-mode-syntax-table) | |
150 (modify-syntax-entry ?\' "\"" pascal-mode-syntax-table)) | |
4934 | 151 |
9387
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
152 (defvar pascal-font-lock-keywords |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
153 (list |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
154 '("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\(\\sw+\\)?" |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
155 (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t)) |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
156 ; ("type" "const" "real" "integer" "char" "boolean" "var" |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
157 ; "record" "array" "file") |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
158 (cons (concat "\\<\\(array\\|boolean\\|c\\(har\\|onst\\)\\|file\\|" |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
159 "integer\\|re\\(al\\|cord\\)\\|type\\|var\\)\\>") |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
160 'font-lock-type-face) |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
161 '("\\<\\(label\\|external\\|forward\\)\\>" . font-lock-reference-face) |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
162 '("\\<\\([0-9]+\\)[ \t]*:" 1 font-lock-reference-face) |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
163 ; ("of" "to" "for" "if" "then" "else" "case" "while" |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
164 ; "do" "until" "and" "or" "not" "in" "with" "repeat" "begin" "end") |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
165 (concat "\\<\\(" |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
166 "and\\|begin\\|case\\|do\\|e\\(lse\\|nd\\)\\|for\\|i[fn]\\|" |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
167 "not\\|o[fr]\\|repeat\\|t\\(hen\\|o\\)\\|until\\|w\\(hile\\|ith\\)" |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
168 "\\)\\>") |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
169 '("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?" |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
170 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))) |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
171 "Additional expressions to highlight in Pascal mode.") |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
172 |
5723 | 173 (defvar pascal-indent-level 3 |
4934 | 174 "*Indentation of Pascal statements with respect to containing block.") |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
175 |
5723 | 176 (defvar pascal-case-indent 2 |
177 "*Indentation for case statements.") | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
178 |
5723 | 179 (defvar pascal-auto-newline nil |
14000
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
180 "*Non-nil means automatically newline after semicolons and the punctuation |
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
181 mark after an end.") |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
182 |
5723 | 183 (defvar pascal-tab-always-indent t |
184 "*Non-nil means TAB in Pascal mode should always reindent the current line, | |
185 regardless of where in the line point is when the TAB command is used.") | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
186 |
5723 | 187 (defvar pascal-auto-endcomments t |
188 "*Non-nil means a comment { ... } is set after the ends which ends cases and | |
189 functions. The name of the function or case will be set between the braces.") | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
190 |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
191 (defvar pascal-auto-lineup '(all) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
192 "*List of contexts where auto lineup of :'s or ='s should be done. |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
193 Elements can be of type: 'paramlist', 'declaration' or 'case', which will |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
194 do auto lineup in parameterlist, declarations or case-statements |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
195 respectively. The word 'all' will do all lineups. '(case paramlist) for |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
196 instance will do lineup in case-statements and parameterlist, while '(all) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
197 will do all lineups.") |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
198 |
5723 | 199 (defvar pascal-toggle-completions nil |
12882
83fd8f17cfe4
(pascal-mode): Set comment-start.
Richard M. Stallman <rms@gnu.org>
parents:
12689
diff
changeset
|
200 "*Non-nil means \\<pascal-mode-map>\\[pascal-complete-word] should try all possible completions one by one. |
83fd8f17cfe4
(pascal-mode): Set comment-start.
Richard M. Stallman <rms@gnu.org>
parents:
12689
diff
changeset
|
201 Repeated use of \\[pascal-complete-word] will show you all of them. |
83fd8f17cfe4
(pascal-mode): Set comment-start.
Richard M. Stallman <rms@gnu.org>
parents:
12689
diff
changeset
|
202 Normally, when there is more than one possible completion, |
83fd8f17cfe4
(pascal-mode): Set comment-start.
Richard M. Stallman <rms@gnu.org>
parents:
12689
diff
changeset
|
203 it displays a list of all possible completions.") |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
204 |
5723 | 205 (defvar pascal-type-keywords |
206 '("array" "file" "packed" "char" "integer" "real" "string" "record") | |
207 "*Keywords for types used when completing a word in a declaration or parmlist. | |
208 \(eg. integer, real, char.) The types defined within the Pascal program | |
209 will be completed runtime, and should not be added to this list.") | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
210 |
5723 | 211 (defvar pascal-start-keywords |
212 '("begin" "end" "function" "procedure" "repeat" "until" "while" | |
213 "read" "readln" "reset" "rewrite" "write" "writeln") | |
214 "*Keywords to complete when standing at the first word of a statement. | |
215 \(eg. begin, repeat, until, readln.) | |
216 The procedures and variables defined within the Pascal program | |
217 will be completed runtime and should not be added to this list.") | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
218 |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
219 (defvar pascal-separator-keywords |
5723 | 220 '("downto" "else" "mod" "div" "then") |
221 "*Keywords to complete when NOT standing at the first word of a statement. | |
222 \(eg. downto, else, mod, then.) | |
223 Variables and function names defined within the | |
224 Pascal program are completed runtime and should not be added to this list.") | |
225 | |
226 ;;; | |
227 ;;; Macros | |
228 ;;; | |
229 | |
230 (defsubst pascal-get-beg-of-line (&optional arg) | |
231 (save-excursion | |
232 (beginning-of-line arg) | |
233 (point))) | |
234 | |
235 (defsubst pascal-get-end-of-line (&optional arg) | |
236 (save-excursion | |
237 (end-of-line arg) | |
238 (point))) | |
239 | |
240 (defun pascal-declaration-end () | |
241 (let ((nest 1)) | |
242 (while (and (> nest 0) | |
243 (re-search-forward | |
244 "[:=]\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)" | |
245 (save-excursion (end-of-line 2) (point)) t)) | |
246 (cond ((match-beginning 1) (setq nest (1+ nest))) | |
14776
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
247 ((match-beginning 2) (setq nest (1- nest))) |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
248 ((looking-at "[^(\n]+)") (setq nest 0)))))) |
5723 | 249 |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
250 |
5723 | 251 (defun pascal-declaration-beg () |
252 (let ((nest 1)) | |
253 (while (and (> nest 0) | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
254 (re-search-backward "[:=]\\|\\<\\(type\\|var\\|label\\|const\\)\\>\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)" (pascal-get-beg-of-line 0) t)) |
5723 | 255 (cond ((match-beginning 1) (setq nest 0)) |
256 ((match-beginning 2) (setq nest (1- nest))) | |
257 ((match-beginning 3) (setq nest (1+ nest))))) | |
258 (= nest 0))) | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
259 |
5723 | 260 |
261 (defsubst pascal-within-string () | |
262 (save-excursion | |
263 (nth 3 (parse-partial-sexp (pascal-get-beg-of-line) (point))))) | |
264 | |
4934 | 265 |
266 ;;;###autoload | |
267 (defun pascal-mode () | |
5723 | 268 "Major mode for editing Pascal code. \\<pascal-mode-map> |
269 TAB indents for Pascal code. Delete converts tabs to spaces as it moves back. | |
270 | |
271 \\[pascal-complete-word] completes the word around current point with respect \ | |
272 to position in code | |
273 \\[pascal-show-completions] shows all possible completions at this point. | |
274 | |
275 Other useful functions are: | |
276 | |
277 \\[pascal-mark-defun]\t- Mark function. | |
278 \\[pascal-insert-block]\t- insert begin ... end; | |
279 \\[pascal-star-comment]\t- insert (* ... *) | |
280 \\[pascal-comment-area]\t- Put marked area in a comment, fixing nested comments. | |
281 \\[pascal-uncomment-area]\t- Uncomment an area commented with \ | |
282 \\[pascal-comment-area]. | |
283 \\[pascal-beg-of-defun]\t- Move to beginning of current function. | |
284 \\[pascal-end-of-defun]\t- Move to end of current function. | |
285 \\[pascal-goto-defun]\t- Goto function prompted for in the minibuffer. | |
286 \\[pascal-outline]\t- Enter pascal-outline-mode (see also pascal-outline). | |
287 | |
288 Variables controlling indentation/edit style: | |
289 | |
290 pascal-indent-level (default 3) | |
291 Indentation of Pascal statements with respect to containing block. | |
292 pascal-case-indent (default 2) | |
293 Indentation for case statements. | |
294 pascal-auto-newline (default nil) | |
14000
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
295 Non-nil means automatically newline after semicolons and the punctuation |
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
296 mark after an end. |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
297 pascal-tab-always-indent (default t) |
4934 | 298 Non-nil means TAB in Pascal mode should always reindent the current line, |
299 regardless of where in the line point is when the TAB command is used. | |
5723 | 300 pascal-auto-endcomments (default t) |
301 Non-nil means a comment { ... } is set after the ends which ends cases and | |
302 functions. The name of the function or case will be set between the braces. | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
303 pascal-auto-lineup (default t) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
304 List of contexts where auto lineup of :'s or ='s hould be done. |
4934 | 305 |
5723 | 306 See also the user variables pascal-type-keywords, pascal-start-keywords and |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
307 pascal-separator-keywords. |
4934 | 308 |
309 Turning on Pascal mode calls the value of the variable pascal-mode-hook with | |
310 no args, if that value is non-nil." | |
311 (interactive) | |
312 (kill-all-local-variables) | |
313 (use-local-map pascal-mode-map) | |
314 (setq major-mode 'pascal-mode) | |
315 (setq mode-name "Pascal") | |
316 (setq local-abbrev-table pascal-mode-abbrev-table) | |
317 (set-syntax-table pascal-mode-syntax-table) | |
318 (make-local-variable 'indent-line-function) | |
319 (setq indent-line-function 'pascal-indent-line) | |
16622
9811f1144bbf
(pascal-mode): Make comment-indent-function buffer local.
Richard M. Stallman <rms@gnu.org>
parents:
16466
diff
changeset
|
320 (make-local-variable 'comment-indent-function) |
5723 | 321 (setq comment-indent-function 'pascal-indent-comment) |
4934 | 322 (make-local-variable 'parse-sexp-ignore-comments) |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
323 (setq parse-sexp-ignore-comments nil) |
4934 | 324 (make-local-variable 'case-fold-search) |
325 (setq case-fold-search t) | |
12882
83fd8f17cfe4
(pascal-mode): Set comment-start.
Richard M. Stallman <rms@gnu.org>
parents:
12689
diff
changeset
|
326 (make-local-variable 'comment-start) |
83fd8f17cfe4
(pascal-mode): Set comment-start.
Richard M. Stallman <rms@gnu.org>
parents:
12689
diff
changeset
|
327 (setq comment-start "{") |
9387
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
328 (make-local-variable 'comment-start-skip) |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
329 (setq comment-start-skip "(\\*+ *\\|{ *") |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
330 (make-local-variable 'comment-end) |
ccd27c6ef48d
(pascal-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8689
diff
changeset
|
331 (setq comment-end "}") |
12689
83ef0f002ecf
(pascal-mode): Added imenu support.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
332 ;; Font lock support |
9479
ef7c2b4dfee4
* pascal.el: (pascal-mode): Set font-lock-defaults.
Simon Marshall <simon@gnu.org>
parents:
9387
diff
changeset
|
333 (make-local-variable 'font-lock-defaults) |
ef7c2b4dfee4
* pascal.el: (pascal-mode): Set font-lock-defaults.
Simon Marshall <simon@gnu.org>
parents:
9387
diff
changeset
|
334 (setq font-lock-defaults '(pascal-font-lock-keywords nil t)) |
12689
83ef0f002ecf
(pascal-mode): Added imenu support.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
335 ;; Imenu support |
83ef0f002ecf
(pascal-mode): Added imenu support.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
336 (make-local-variable 'imenu-generic-expression) |
83ef0f002ecf
(pascal-mode): Added imenu support.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
337 (setq imenu-generic-expression pascal-imenu-generic-expression) |
4934 | 338 (run-hooks 'pascal-mode-hook)) |
339 | |
5723 | 340 |
341 | |
4934 | 342 ;;; |
343 ;;; Electric functions | |
344 ;;; | |
345 (defun electric-pascal-terminate-line () | |
346 "Terminate line and indent next line." | |
347 (interactive) | |
5723 | 348 ;; First, check if current line should be indented |
4934 | 349 (save-excursion |
350 (beginning-of-line) | |
351 (skip-chars-forward " \t") | |
5723 | 352 (if (looking-at pascal-autoindent-lines-re) |
4934 | 353 (pascal-indent-line))) |
5723 | 354 (delete-horizontal-space) ; Removes trailing whitespaces |
4934 | 355 (newline) |
5723 | 356 ;; Indent next line |
4934 | 357 (pascal-indent-line) |
358 ;; Maybe we should set some endcomments | |
359 (if pascal-auto-endcomments | |
360 (pascal-set-auto-comments)) | |
361 ;; Check if we shall indent inside comment | |
362 (let ((setstar nil)) | |
363 (save-excursion | |
364 (forward-line -1) | |
365 (skip-chars-forward " \t") | |
5723 | 366 (cond ((looking-at "\\*[ \t]+)") |
4934 | 367 ;; Delete region between `*' and `)' if there is only whitespaces. |
368 (forward-char 1) | |
5723 | 369 (delete-horizontal-space)) |
4934 | 370 ((and (looking-at "(\\*\\|\\*[^)]") |
371 (not (save-excursion | |
372 (search-forward "*)" (pascal-get-end-of-line) t)))) | |
373 (setq setstar t)))) | |
374 ;; If last line was a star comment line then this one shall be too. | |
5723 | 375 (if (null setstar) |
376 (pascal-indent-line) | |
377 (insert "* ")))) | |
4934 | 378 |
379 | |
5723 | 380 (defun electric-pascal-semi-or-dot () |
381 "Insert `;' or `.' character and reindent the line." | |
4934 | 382 (interactive) |
383 (insert last-command-char) | |
384 (save-excursion | |
385 (beginning-of-line) | |
386 (pascal-indent-line)) | |
387 (if pascal-auto-newline | |
388 (electric-pascal-terminate-line))) | |
389 | |
390 (defun electric-pascal-colon () | |
5723 | 391 "Insert `:' and do all indentions except line indent on this line." |
4934 | 392 (interactive) |
393 (insert last-command-char) | |
5723 | 394 ;; Do nothing if within string. |
395 (if (pascal-within-string) | |
396 () | |
397 (save-excursion | |
398 (beginning-of-line) | |
399 (pascal-indent-line)) | |
400 (let ((pascal-tab-always-indent nil)) | |
401 (pascal-indent-command)))) | |
402 | |
4934 | 403 (defun electric-pascal-equal () |
5723 | 404 "Insert `=', and do indention if within type declaration." |
4934 | 405 (interactive) |
406 (insert last-command-char) | |
5723 | 407 (if (eq (car (pascal-calculate-indent)) 'declaration) |
4934 | 408 (let ((pascal-tab-always-indent nil)) |
409 (pascal-indent-command)))) | |
410 | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
411 (defun electric-pascal-hash () |
14000
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
412 "Insert `#', and indent to column 0 if this is a CPP directive." |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
413 (interactive) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
414 (insert last-command-char) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
415 (if (save-excursion (beginning-of-line) (looking-at "^[ \t]*#")) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
416 (save-excursion (beginning-of-line) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
417 (delete-horizontal-space)))) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
418 |
4934 | 419 (defun electric-pascal-tab () |
5723 | 420 "Function called when TAB is pressed in Pascal mode." |
4934 | 421 (interactive) |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
422 ;; Do nothing if within a string or in a CPP directive. |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
423 (if (or (pascal-within-string) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
424 (and (not (bolp)) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
425 (save-excursion (beginning-of-line) (eq (following-char) ?#)))) |
5723 | 426 (insert "\t") |
427 ;; If pascal-tab-always-indent, indent the beginning of the line. | |
428 (if pascal-tab-always-indent | |
429 (save-excursion | |
430 (beginning-of-line) | |
431 (pascal-indent-line)) | |
14776
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
432 (if (save-excursion |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
433 (skip-chars-backward " \t") |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
434 (bolp)) |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
435 (pascal-indent-line) |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
436 (insert "\t"))) |
5723 | 437 (pascal-indent-command))) |
438 | |
439 | |
4934 | 440 |
441 ;;; | |
442 ;;; Interactive functions | |
443 ;;; | |
444 (defun pascal-insert-block () | |
5723 | 445 "Insert Pascal begin ... end; block in the code with right indentation." |
4934 | 446 (interactive) |
447 (pascal-indent-line) | |
448 (insert "begin") | |
449 (electric-pascal-terminate-line) | |
450 (save-excursion | |
451 (electric-pascal-terminate-line) | |
452 (insert "end;") | |
453 (beginning-of-line) | |
454 (pascal-indent-line))) | |
455 | |
456 (defun pascal-star-comment () | |
5723 | 457 "Insert Pascal star comment at point." |
4934 | 458 (interactive) |
459 (pascal-indent-line) | |
460 (insert "(*") | |
461 (electric-pascal-terminate-line) | |
462 (save-excursion | |
463 (electric-pascal-terminate-line) | |
5723 | 464 (delete-horizontal-space) |
465 (insert ")")) | |
466 (insert " ")) | |
4934 | 467 |
5723 | 468 (defun pascal-mark-defun () |
4934 | 469 "Mark the current pascal function (or procedure). |
5723 | 470 This puts the mark at the end, and point at the beginning." |
4934 | 471 (interactive) |
472 (push-mark (point)) | |
5723 | 473 (pascal-end-of-defun) |
4934 | 474 (push-mark (point)) |
5723 | 475 (pascal-beg-of-defun) |
476 (if (fboundp 'zmacs-activate-region) | |
477 (zmacs-activate-region))) | |
4934 | 478 |
479 (defun pascal-comment-area (start end) | |
5723 | 480 "Put the region into a Pascal comment. |
481 The comments that are in this area are \"deformed\": | |
482 `*)' becomes `!(*' and `}' becomes `!{'. | |
483 These deformed comments are returned to normal if you use | |
484 \\[pascal-uncomment-area] to undo the commenting. | |
485 | |
486 The commented area starts with `pascal-exclude-str-start', and ends with | |
487 `pascal-include-str-end'. But if you change these variables, | |
488 \\[pascal-uncomment-area] won't recognize the comments." | |
4934 | 489 (interactive "r") |
490 (save-excursion | |
491 ;; Insert start and endcomments | |
492 (goto-char end) | |
493 (if (and (save-excursion (skip-chars-forward " \t") (eolp)) | |
494 (not (save-excursion (skip-chars-backward " \t") (bolp)))) | |
495 (forward-line 1) | |
496 (beginning-of-line)) | |
5723 | 497 (insert pascal-exclude-str-end) |
4934 | 498 (setq end (point)) |
499 (newline) | |
500 (goto-char start) | |
501 (beginning-of-line) | |
5723 | 502 (insert pascal-exclude-str-start) |
4934 | 503 (newline) |
504 ;; Replace end-comments within commented area | |
505 (goto-char end) | |
506 (save-excursion | |
507 (while (re-search-backward "\\*)" start t) | |
508 (replace-match "!(*" t t))) | |
509 (save-excursion | |
510 (while (re-search-backward "}" start t) | |
511 (replace-match "!{" t t))))) | |
512 | |
513 (defun pascal-uncomment-area () | |
5723 | 514 "Uncomment a commented area; change deformed comments back to normal. |
515 This command does nothing if the pointer is not in a commented | |
4934 | 516 area. See also `pascal-comment-area'." |
517 (interactive) | |
518 (save-excursion | |
519 (let ((start (point)) | |
520 (end (point))) | |
521 ;; Find the boundaries of the comment | |
522 (save-excursion | |
5723 | 523 (setq start (progn (search-backward pascal-exclude-str-start nil t) |
4934 | 524 (point))) |
5723 | 525 (setq end (progn (search-forward pascal-exclude-str-end nil t) |
4934 | 526 (point)))) |
527 ;; Check if we're really inside a comment | |
528 (if (or (equal start (point)) (<= end (point))) | |
529 (message "Not standing within commented area.") | |
530 (progn | |
531 ;; Remove endcomment | |
532 (goto-char end) | |
533 (beginning-of-line) | |
534 (let ((pos (point))) | |
535 (end-of-line) | |
536 (delete-region pos (1+ (point)))) | |
537 ;; Change comments back to normal | |
538 (save-excursion | |
539 (while (re-search-backward "!{" start t) | |
540 (replace-match "}" t t))) | |
541 (save-excursion | |
542 (while (re-search-backward "!(\\*" start t) | |
543 (replace-match "*)" t t))) | |
544 ;; Remove startcomment | |
545 (goto-char start) | |
546 (beginning-of-line) | |
547 (let ((pos (point))) | |
548 (end-of-line) | |
549 (delete-region pos (1+ (point))))))))) | |
550 | |
5723 | 551 (defun pascal-beg-of-defun () |
552 "Move backward to the beginning of the current function or procedure." | |
4934 | 553 (interactive) |
5723 | 554 (catch 'found |
555 (if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re))) | |
556 (forward-sexp 1)) | |
557 (let ((nest 0) (max -1) (func 0) | |
558 (reg (concat pascal-beg-block-re "\\|" | |
559 pascal-end-block-re "\\|" | |
560 pascal-defun-re))) | |
561 (while (re-search-backward reg nil 'move) | |
562 (cond ((let ((state (save-excursion | |
563 (parse-partial-sexp (point-min) (point))))) | |
564 (or (nth 3 state) (nth 4 state))) ; Inside string or comment | |
565 ()) | |
566 ((match-end 1) ; begin|case|record|repeat | |
567 (if (and (looking-at "\\<record\\>") (>= max 0)) | |
568 (setq func (1- func))) | |
569 (setq nest (1+ nest) | |
570 max (max nest max))) | |
571 ((match-end 2) ; end|until | |
572 (if (and (= nest max) (>= max 0)) | |
573 (setq func (1+ func))) | |
574 (setq nest (1- nest))) | |
575 ((match-end 3) ; function|procedure | |
576 (if (= 0 func) | |
577 (throw 'found t) | |
578 (setq func (1- func))))))) | |
579 nil)) | |
4934 | 580 |
5723 | 581 (defun pascal-end-of-defun () |
582 "Move forward to the end of the current function or procedure." | |
4934 | 583 (interactive) |
5723 | 584 (if (looking-at "\\s ") |
585 (forward-sexp 1)) | |
586 (if (not (looking-at pascal-defun-re)) | |
587 (pascal-beg-of-defun)) | |
588 (forward-char 1) | |
589 (let ((nest 0) (func 1) | |
590 (reg (concat pascal-beg-block-re "\\|" | |
591 pascal-end-block-re "\\|" | |
592 pascal-defun-re))) | |
593 (while (and (/= func 0) | |
594 (re-search-forward reg nil 'move)) | |
595 (cond ((let ((state (save-excursion | |
596 (parse-partial-sexp (point-min) (point))))) | |
597 (or (nth 3 state) (nth 4 state))) ; Inside string or comment | |
598 ()) | |
599 ((match-end 1) | |
600 (setq nest (1+ nest)) | |
601 (if (save-excursion | |
602 (goto-char (match-beginning 0)) | |
603 (looking-at "\\<record\\>")) | |
604 (setq func (1+ func)))) | |
605 ((match-end 2) | |
606 (setq nest (1- nest)) | |
607 (if (= nest 0) | |
608 (setq func (1- func)))) | |
609 ((match-end 3) | |
610 (setq func (1+ func)))))) | |
611 (forward-line 1)) | |
4934 | 612 |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
613 (defun pascal-end-of-statement () |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
614 "Move forward to end of current statement." |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
615 (interactive) |
15230
307b7c77a5e5
(pascal-end-of-statement, pascal-calculate-indent):
Richard M. Stallman <rms@gnu.org>
parents:
14776
diff
changeset
|
616 (let ((parse-sexp-ignore-comments t) |
307b7c77a5e5
(pascal-end-of-statement, pascal-calculate-indent):
Richard M. Stallman <rms@gnu.org>
parents:
14776
diff
changeset
|
617 (nest 0) pos |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
618 (regexp (concat "\\(" pascal-beg-block-re "\\)\\|\\(" |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
619 pascal-end-block-re "\\)"))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
620 (if (not (looking-at "[ \t\n]")) (forward-sexp -1)) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
621 (or (looking-at pascal-beg-block-re) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
622 ;; Skip to end of statement |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
623 (setq pos (catch 'found |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
624 (while t |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
625 (forward-sexp 1) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
626 (cond ((looking-at "[ \t]*;") |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
627 (skip-chars-forward "^;") |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
628 (forward-char 1) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
629 (throw 'found (point))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
630 ((save-excursion |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
631 (forward-sexp -1) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
632 (looking-at pascal-beg-block-re)) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
633 (goto-char (match-beginning 0)) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
634 (throw 'found nil)) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
635 ((eobp) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
636 (throw 'found (point)))))))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
637 (if (not pos) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
638 ;; Skip a whole block |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
639 (catch 'found |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
640 (while t |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
641 (re-search-forward regexp nil 'move) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
642 (setq nest (if (match-end 1) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
643 (1+ nest) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
644 (1- nest))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
645 (cond ((eobp) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
646 (throw 'found (point))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
647 ((= 0 nest) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
648 (throw 'found (pascal-end-of-statement)))))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
649 pos))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
650 |
4934 | 651 (defun pascal-downcase-keywords () |
5723 | 652 "Downcase all Pascal keywords in the buffer." |
4934 | 653 (interactive) |
654 (pascal-change-keywords 'downcase-word)) | |
655 | |
656 (defun pascal-upcase-keywords () | |
5723 | 657 "Upcase all Pascal keywords in the buffer." |
4934 | 658 (interactive) |
659 (pascal-change-keywords 'upcase-word)) | |
660 | |
661 (defun pascal-capitalize-keywords () | |
5723 | 662 "Capitalize all Pascal keywords in the buffer." |
4934 | 663 (interactive) |
664 (pascal-change-keywords 'capitalize-word)) | |
665 | |
5723 | 666 ;; Change the keywords according to argument. |
4934 | 667 (defun pascal-change-keywords (change-word) |
668 (save-excursion | |
5723 | 669 (let ((keyword-re (concat "\\<\\(" |
670 (mapconcat 'identity pascal-keywords "\\|") | |
671 "\\)\\>"))) | |
672 (goto-char (point-min)) | |
673 (while (re-search-forward keyword-re nil t) | |
674 (funcall change-word -1))))) | |
675 | |
676 | |
4934 | 677 |
678 ;;; | |
679 ;;; Other functions | |
680 ;;; | |
681 (defun pascal-set-auto-comments () | |
5723 | 682 "Insert `{ case }' or `{ NAME }' on this line if appropriate. |
683 Insert `{ case }' if there is an `end' on the line which | |
684 ends a case block. Insert `{ NAME }' if there is an `end' | |
685 on the line which ends a function or procedure named NAME." | |
4934 | 686 (save-excursion |
687 (forward-line -1) | |
688 (skip-chars-forward " \t") | |
5723 | 689 (if (and (looking-at "\\<end;") |
4934 | 690 (not (save-excursion |
691 (end-of-line) | |
5723 | 692 (search-backward "{" (pascal-get-beg-of-line) t)))) |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
693 (let ((type (car (pascal-calculate-indent)))) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
694 (if (eq type 'declaration) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
695 () |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
696 (if (eq type 'case) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
697 ;; This is a case block |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
698 (progn |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
699 (end-of-line) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
700 (delete-horizontal-space) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
701 (insert " { case }")) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
702 (let ((nest 1)) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
703 ;; Check if this is the end of a function |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
704 (save-excursion |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
705 (while (not (or (looking-at pascal-defun-re) (bobp))) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
706 (backward-sexp 1) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
707 (cond ((looking-at pascal-beg-block-re) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
708 (setq nest (1- nest))) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
709 ((looking-at pascal-end-block-re) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
710 (setq nest (1+ nest))))) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
711 (if (bobp) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
712 (setq nest 1))) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
713 (if (zerop nest) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
714 (progn |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
715 (end-of-line) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
716 (delete-horizontal-space) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
717 (insert " { ") |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
718 (let (b e) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
719 (save-excursion |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
720 (setq b (progn (pascal-beg-of-defun) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
721 (skip-chars-forward "^ \t") |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
722 (skip-chars-forward " \t") |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
723 (point)) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
724 e (progn (skip-chars-forward "a-zA-Z0-9_") |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
725 (point)))) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
726 (insert-buffer-substring (current-buffer) b e)) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
727 (insert " }")))))))))) |
4934 | 728 |
5723 | 729 |
730 | |
4934 | 731 ;;; |
5723 | 732 ;;; Indentation |
733 ;;; | |
734 (defconst pascal-indent-alist | |
735 '((block . (+ ind pascal-indent-level)) | |
736 (case . (+ ind pascal-case-indent)) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
737 (caseblock . ind) (cpp . 0) |
5723 | 738 (declaration . (+ ind pascal-indent-level)) |
739 (paramlist . (pascal-indent-paramlist t)) | |
740 (comment . (pascal-indent-comment t)) | |
741 (defun . ind) (contexp . ind) | |
742 (unknown . 0) (string . 0))) | |
743 | |
4934 | 744 (defun pascal-indent-command () |
5723 | 745 "Indent for special part of code." |
746 (let* ((indent-str (pascal-calculate-indent)) | |
747 (type (car indent-str)) | |
748 (ind (car (cdr indent-str)))) | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
749 (cond ((and (eq type 'paramlist) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
750 (or (memq 'all pascal-auto-lineup) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
751 (memq 'paramlist pascal-auto-lineup))) |
5723 | 752 (pascal-indent-paramlist) |
753 (pascal-indent-paramlist)) | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
754 ((and (eq type 'declaration) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
755 (or (memq 'all pascal-auto-lineup) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
756 (memq 'declaration pascal-auto-lineup))) |
5723 | 757 (pascal-indent-declaration)) |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
758 ((and (eq type 'case) (not (looking-at "^[ \t]*$")) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
759 (or (memq 'all pascal-auto-lineup) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
760 (memq 'case pascal-auto-lineup))) |
5723 | 761 (pascal-indent-case))) |
762 (if (looking-at "[ \t]+$") | |
763 (skip-chars-forward " \t")))) | |
4934 | 764 |
765 (defun pascal-indent-line () | |
5723 | 766 "Indent current line as a Pascal statement." |
767 (let* ((indent-str (pascal-calculate-indent)) | |
768 (type (car indent-str)) | |
769 (ind (car (cdr indent-str)))) | |
770 (if (looking-at "^[0-9a-zA-Z]+[ \t]*:[^=]") | |
771 (search-forward ":" nil t)) | |
772 (delete-horizontal-space) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
773 ;; Some things should not be indented |
5723 | 774 (if (or (and (eq type 'declaration) (looking-at pascal-declaration-re)) |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
775 (eq type 'cpp) |
5723 | 776 (looking-at pascal-defun-re)) |
777 () | |
778 ;; Other things should have no extra indent | |
779 (if (looking-at pascal-noindent-re) | |
780 (indent-to ind) | |
781 ;; But most lines are treated this way: | |
782 (indent-to (eval (cdr (assoc type pascal-indent-alist)))) | |
783 )))) | |
4934 | 784 |
5723 | 785 (defun pascal-calculate-indent () |
786 "Calculate the indent of the current Pascal line. | |
787 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)." | |
788 (save-excursion | |
15230
307b7c77a5e5
(pascal-end-of-statement, pascal-calculate-indent):
Richard M. Stallman <rms@gnu.org>
parents:
14776
diff
changeset
|
789 (let* ((parse-sexp-ignore-comments t) |
307b7c77a5e5
(pascal-end-of-statement, pascal-calculate-indent):
Richard M. Stallman <rms@gnu.org>
parents:
14776
diff
changeset
|
790 (oldpos (point)) |
5723 | 791 (state (save-excursion (parse-partial-sexp (point-min) (point)))) |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
792 (nest 0) (par 0) (complete (looking-at "[ \t]*end\\>")) |
6153
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
793 (elsed (looking-at "[ \t]*else\\>")) |
5723 | 794 (type (catch 'nesting |
795 ;; Check if inside a string, comment or parenthesis | |
796 (cond ((nth 3 state) (throw 'nesting 'string)) | |
797 ((nth 4 state) (throw 'nesting 'comment)) | |
798 ((> (car state) 0) | |
799 (goto-char (scan-lists (point) -1 (car state))) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
800 (setq par (1+ (current-column)))) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
801 ((save-excursion (beginning-of-line) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
802 (eq (following-char) ?#)) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
803 (throw 'nesting 'cpp))) |
5723 | 804 ;; Loop until correct indent is found |
805 (while t | |
806 (backward-sexp 1) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
807 (cond (;--Escape from case statements |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
808 (and (looking-at "[A-Za-z0-9]+[ \t]*:[^=]") |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
809 (not complete) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
810 (save-excursion (skip-chars-backward " \t") |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
811 (bolp)) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
812 (= (save-excursion |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
813 (end-of-line) (backward-sexp) (point)) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
814 (point)) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
815 (> (save-excursion (goto-char oldpos) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
816 (beginning-of-line) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
817 (point)) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
818 (point))) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
819 (throw 'nesting 'caseblock)) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
820 (;--Nest block outwards |
5723 | 821 (looking-at pascal-beg-block-re) |
822 (if (= nest 0) | |
823 (cond ((looking-at "case\\>") | |
824 (throw 'nesting 'case)) | |
825 ((looking-at "record\\>") | |
826 (throw 'nesting 'declaration)) | |
6153
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
827 (t (throw 'nesting 'block))) |
5723 | 828 (setq nest (1- nest)))) |
829 (;--Nest block inwards | |
830 (looking-at pascal-end-block-re) | |
6153
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
831 (if (and (looking-at "end\\s ") |
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
832 elsed (not complete)) |
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
833 (throw 'nesting 'block)) |
5723 | 834 (setq complete t |
835 nest (1+ nest))) | |
836 (;--Defun (or parameter list) | |
837 (looking-at pascal-defun-re) | |
838 (if (= 0 par) | |
839 (throw 'nesting 'defun) | |
840 (setq par 0) | |
841 (let ((n 0)) | |
842 (while (re-search-forward | |
843 "\\(\\<record\\>\\)\\|\\<end\\>" | |
844 oldpos t) | |
845 (if (match-end 1) | |
846 (setq n (1+ n)) (setq n (1- n)))) | |
847 (if (> n 0) | |
848 (throw 'nesting 'declaration) | |
849 (throw 'nesting 'paramlist))))) | |
850 (;--Declaration part | |
851 (looking-at pascal-declaration-re) | |
6153
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
852 (if (save-excursion |
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
853 (goto-char oldpos) |
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
854 (forward-line -1) |
40e4038bd544
(pascal-calculate-indent): Fixed indentation bug
Richard M. Stallman <rms@gnu.org>
parents:
6123
diff
changeset
|
855 (looking-at "^[ \t]*$")) |
5723 | 856 (throw 'nesting 'unknown) |
857 (throw 'nesting 'declaration))) | |
858 (;--If, else or while statement | |
859 (and (not complete) | |
860 (looking-at pascal-sub-block-re)) | |
861 (throw 'nesting 'block)) | |
862 (;--Found complete statement | |
863 (save-excursion (forward-sexp 1) | |
864 (= (following-char) ?\;)) | |
865 (setq complete t)) | |
866 (;--No known statements | |
867 (bobp) | |
868 (throw 'nesting 'unknown)) | |
869 ))))) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
870 |
5723 | 871 ;; Return type of block and indent level. |
872 (if (> par 0) ; Unclosed Parenthesis | |
873 (list 'contexp par) | |
874 (list type (pascal-indent-level)))))) | |
4934 | 875 |
5723 | 876 (defun pascal-indent-level () |
877 "Return the indent-level the current statement has. | |
878 Do not count labels, case-statements or records." | |
4934 | 879 (save-excursion |
880 (beginning-of-line) | |
5723 | 881 (if (looking-at "[ \t]*[0-9a-zA-Z]+[ \t]*:[^=]") |
882 (search-forward ":" nil t) | |
883 (if (looking-at ".*=[ \t]*record\\>") | |
884 (search-forward "=" nil t))) | |
4934 | 885 (skip-chars-forward " \t") |
886 (current-column))) | |
887 | |
5723 | 888 (defun pascal-indent-comment (&optional arg) |
889 "Indent current line as comment. | |
890 If optional arg is non-nil, just return the | |
891 column number the line should be indented to." | |
892 (let* ((stcol (save-excursion | |
893 (re-search-backward "(\\*\\|{" nil t) | |
894 (1+ (current-column))))) | |
895 (if arg stcol | |
896 (delete-horizontal-space) | |
897 (indent-to stcol)))) | |
898 | |
899 (defun pascal-indent-case () | |
900 "Indent within case statements." | |
15230
307b7c77a5e5
(pascal-end-of-statement, pascal-calculate-indent):
Richard M. Stallman <rms@gnu.org>
parents:
14776
diff
changeset
|
901 (let ((savepos (point-marker)) |
307b7c77a5e5
(pascal-end-of-statement, pascal-calculate-indent):
Richard M. Stallman <rms@gnu.org>
parents:
14776
diff
changeset
|
902 (end (prog2 |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
903 (end-of-line) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
904 (point-marker) |
5723 | 905 (re-search-backward "\\<case\\>" nil t))) |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
906 (beg (point)) oldpos |
5723 | 907 (ind 0)) |
908 ;; Get right indent | |
909 (while (< (point) (marker-position end)) | |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
910 (if (re-search-forward |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
911 "^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:" |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
912 (marker-position end) 'move) |
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
913 (forward-char -1)) |
14776
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
914 (if (< (point) (marker-position end)) |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
915 (progn |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
916 (delete-horizontal-space) |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
917 (if (> (current-column) ind) |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
918 (setq ind (current-column))) |
d392e3ffa1bb
(pascal-declaration-end): Now locates the end of a parameterlist correctly.
Richard M. Stallman <rms@gnu.org>
parents:
14183
diff
changeset
|
919 (pascal-end-of-statement)))) |
5723 | 920 (goto-char beg) |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
921 (setq oldpos (marker-position end)) |
5723 | 922 ;; Indent all case statements |
923 (while (< (point) (marker-position end)) | |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
924 (if (re-search-forward |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
925 "^[ \t]*[^][ \t,\\.:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:" |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
926 (marker-position end) 'move) |
5723 | 927 (forward-char -1)) |
928 (indent-to (1+ ind)) | |
929 (if (/= (following-char) ?:) | |
930 () | |
931 (forward-char 1) | |
932 (delete-horizontal-space) | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
933 (insert " ")) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
934 (setq oldpos (point)) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
935 (pascal-end-of-statement)) |
15230
307b7c77a5e5
(pascal-end-of-statement, pascal-calculate-indent):
Richard M. Stallman <rms@gnu.org>
parents:
14776
diff
changeset
|
936 (goto-char savepos))) |
5723 | 937 |
938 (defun pascal-indent-paramlist (&optional arg) | |
939 "Indent current line in parameterlist. | |
940 If optional arg is non-nil, just return the | |
941 indent of the current line in parameterlist." | |
942 (save-excursion | |
943 (let* ((oldpos (point)) | |
944 (stpos (progn (goto-char (scan-lists (point) -1 1)) (point))) | |
945 (stcol (1+ (current-column))) | |
946 (edpos (progn (pascal-declaration-end) | |
947 (search-backward ")" (pascal-get-beg-of-line) t) | |
948 (point))) | |
949 (usevar (re-search-backward "\\<var\\>" stpos t))) | |
950 (if arg (progn | |
951 ;; If arg, just return indent | |
952 (goto-char oldpos) | |
953 (beginning-of-line) | |
954 (if (or (not usevar) (looking-at "[ \t]*var\\>")) | |
955 stcol (+ 4 stcol))) | |
956 (goto-char stpos) | |
957 (forward-char 1) | |
958 (delete-horizontal-space) | |
959 (if (and usevar (not (looking-at "var\\>"))) | |
960 (indent-to (+ 4 stcol))) | |
961 (pascal-indent-declaration nil stpos edpos))))) | |
962 | |
963 (defun pascal-indent-declaration (&optional arg start end) | |
964 "Indent current lines as declaration, lining up the `:'s or `='s." | |
965 (let ((pos (point-marker))) | |
966 (if (and (not (or arg start)) (not (pascal-declaration-beg))) | |
967 () | |
968 (let ((lineup (if (or (looking-at "\\<var\\>\\|\\<record\\>") arg start) | |
969 ":" "=")) | |
970 (stpos (if start start | |
971 (forward-word 2) (backward-word 1) (point))) | |
972 (edpos (set-marker (make-marker) | |
973 (if end end | |
974 (max (progn (pascal-declaration-end) | |
975 (point)) | |
976 pos)))) | |
977 ind) | |
978 | |
979 (goto-char stpos) | |
980 ;; Indent lines in record block | |
981 (if arg | |
982 (while (<= (point) (marker-position edpos)) | |
983 (beginning-of-line) | |
984 (delete-horizontal-space) | |
985 (if (looking-at "end\\>") | |
986 (indent-to arg) | |
987 (indent-to (+ arg pascal-indent-level))) | |
988 (forward-line 1))) | |
989 | |
990 ;; Do lineup | |
991 (setq ind (pascal-get-lineup-indent stpos edpos lineup)) | |
992 (goto-char stpos) | |
16466
2c5c58435c00
(pascal-indent-declaration): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
15230
diff
changeset
|
993 (while (and (<= (point) (marker-position edpos)) |
2c5c58435c00
(pascal-indent-declaration): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
15230
diff
changeset
|
994 (not (eobp))) |
5723 | 995 (if (search-forward lineup (pascal-get-end-of-line) 'move) |
996 (forward-char -1)) | |
997 (delete-horizontal-space) | |
998 (indent-to ind) | |
999 (if (not (looking-at lineup)) | |
1000 (forward-line 1) ; No more indent if there is no : or = | |
1001 (forward-char 1) | |
1002 (delete-horizontal-space) | |
1003 (insert " ") | |
1004 ;; Indent record block | |
1005 (if (looking-at "record\\>") | |
1006 (pascal-indent-declaration (current-column))) | |
1007 (forward-line 1))))) | |
1008 | |
1009 ;; If arg - move point | |
1010 (if arg (forward-line -1) | |
1011 (goto-char (marker-position pos))))) | |
1012 | |
1013 ; "Return the indent level that will line up several lines within the region | |
1014 ;from b to e nicely. The lineup string is str." | |
1015 (defun pascal-get-lineup-indent (b e str) | |
1016 (save-excursion | |
1017 (let ((ind 0) | |
1018 (reg (concat str "\\|\\(\\<record\\>\\)")) | |
1019 nest) | |
1020 (goto-char b) | |
1021 ;; Get rightmost position | |
1022 (while (< (point) e) | |
1023 (setq nest 1) | |
1024 (if (re-search-forward reg (min e (pascal-get-end-of-line 2)) 'move) | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1025 (progn |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1026 ;; Skip record blocks |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1027 (if (match-beginning 1) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1028 (pascal-declaration-end) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1029 (progn |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1030 (goto-char (match-beginning 0)) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1031 (skip-chars-backward " \t") |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1032 (if (> (current-column) ind) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1033 (setq ind (current-column))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1034 (goto-char (match-end 0))))))) |
5723 | 1035 ;; In case no lineup was found |
1036 (if (> ind 0) | |
1037 (1+ ind) | |
1038 ;; No lineup-string found | |
1039 (goto-char b) | |
1040 (end-of-line) | |
1041 (skip-chars-backward " \t") | |
1042 (1+ (current-column)))))) | |
1043 | |
1044 | |
4934 | 1045 |
5723 | 1046 ;;; |
1047 ;;; Completion | |
1048 ;;; | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1049 (defvar pascal-str nil) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1050 (defvar pascal-all nil) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1051 (defvar pascal-pred nil) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1052 (defvar pascal-buffer-to-use nil) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1053 (defvar pascal-flag nil) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1054 |
5723 | 1055 (defun pascal-string-diff (str1 str2) |
1056 "Return index of first letter where STR1 and STR2 differs." | |
1057 (catch 'done | |
1058 (let ((diff 0)) | |
1059 (while t | |
1060 (if (or (> (1+ diff) (length str1)) | |
1061 (> (1+ diff) (length str2))) | |
1062 (throw 'done diff)) | |
1063 (or (equal (aref str1 diff) (aref str2 diff)) | |
1064 (throw 'done diff)) | |
1065 (setq diff (1+ diff)))))) | |
1066 | |
1067 ;; Calculate all possible completions for functions if argument is `function', | |
1068 ;; completions for procedures if argument is `procedure' or both functions and | |
1069 ;; procedures otherwise. | |
1070 | |
1071 (defun pascal-func-completion (type) | |
1072 ;; Build regular expression for function/procedure names | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1073 (if (string= pascal-str "") |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1074 (setq pascal-str "[a-zA-Z_]")) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1075 (let ((pascal-str (concat (cond |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1076 ((eq type 'procedure) "\\<\\(procedure\\)\\s +") |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1077 ((eq type 'function) "\\<\\(function\\)\\s +") |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1078 (t "\\<\\(function\\|procedure\\)\\s +")) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1079 "\\<\\(" pascal-str "[a-zA-Z0-9_.]*\\)\\>")) |
5723 | 1080 match) |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1081 |
5723 | 1082 (if (not (looking-at "\\<\\(function\\|procedure\\)\\>")) |
1083 (re-search-backward "\\<\\(function\\|procedure\\)\\>" nil t)) | |
1084 (forward-char 1) | |
1085 | |
1086 ;; Search through all reachable functions | |
1087 (while (pascal-beg-of-defun) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1088 (if (re-search-forward pascal-str (pascal-get-end-of-line) t) |
5723 | 1089 (progn (setq match (buffer-substring (match-beginning 2) |
1090 (match-end 2))) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1091 (if (or (null pascal-pred) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1092 (funcall pascal-pred match)) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1093 (setq pascal-all (cons match pascal-all))))) |
5723 | 1094 (goto-char (match-beginning 0))))) |
1095 | |
1096 (defun pascal-get-completion-decl () | |
1097 ;; Macro for searching through current declaration (var, type or const) | |
14000
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
1098 ;; for matches of `str' and adding the occurrence tp `all' |
5723 | 1099 (let ((end (save-excursion (pascal-declaration-end) |
1100 (point))) | |
1101 match) | |
1102 ;; Traverse lines | |
1103 (while (< (point) end) | |
1104 (if (re-search-forward "[:=]" (pascal-get-end-of-line) t) | |
1105 ;; Traverse current line | |
1106 (while (and (re-search-backward | |
1107 (concat "\\((\\|\\<\\(var\\|type\\|const\\)\\>\\)\\|" | |
1108 pascal-symbol-re) | |
1109 (pascal-get-beg-of-line) t) | |
1110 (not (match-end 1))) | |
1111 (setq match (buffer-substring (match-beginning 0) (match-end 0))) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1112 (if (string-match (concat "\\<" pascal-str) match) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1113 (if (or (null pascal-pred) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1114 (funcall pascal-pred match)) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1115 (setq pascal-all (cons match pascal-all)))))) |
5723 | 1116 (if (re-search-forward "\\<record\\>" (pascal-get-end-of-line) t) |
1117 (pascal-declaration-end) | |
1118 (forward-line 1))))) | |
1119 | |
1120 (defun pascal-type-completion () | |
1121 "Calculate all possible completions for types." | |
1122 (let ((start (point)) | |
1123 goon) | |
1124 ;; Search for all reachable type declarations | |
1125 (while (or (pascal-beg-of-defun) | |
1126 (setq goon (not goon))) | |
1127 (save-excursion | |
1128 (if (and (< start (prog1 (save-excursion (pascal-end-of-defun) | |
1129 (point)) | |
1130 (forward-char 1))) | |
1131 (re-search-forward | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1132 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>" |
5723 | 1133 start t) |
1134 (not (match-end 1))) | |
1135 ;; Check current type declaration | |
1136 (pascal-get-completion-decl)))))) | |
1137 | |
1138 (defun pascal-var-completion () | |
1139 "Calculate all possible completions for variables (or constants)." | |
1140 (let ((start (point)) | |
1141 goon twice) | |
1142 ;; Search for all reachable var declarations | |
1143 (while (or (pascal-beg-of-defun) | |
1144 (setq goon (not goon))) | |
1145 (save-excursion | |
1146 (if (> start (prog1 (save-excursion (pascal-end-of-defun) | |
1147 (point)))) | |
14000
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
1148 () ; Declarations not reachable |
5723 | 1149 (if (search-forward "(" (pascal-get-end-of-line) t) |
1150 ;; Check parameterlist | |
1151 (pascal-get-completion-decl)) | |
1152 (setq twice 2) | |
1153 (while (>= (setq twice (1- twice)) 0) | |
1154 (cond ((and (re-search-forward | |
1155 (concat "\\<\\(var\\|const\\)\\>\\|" | |
1156 "\\<\\(begin\\|function\\|procedure\\)\\>") | |
1157 start t) | |
1158 (not (match-end 2))) | |
1159 ;; Check var/const declarations | |
1160 (pascal-get-completion-decl)) | |
1161 ((match-end 2) | |
1162 (setq twice 0))))))))) | |
1163 | |
1164 | |
1165 (defun pascal-keyword-completion (keyword-list) | |
1166 "Give list of all possible completions of keywords in KEYWORD-LIST." | |
1167 (mapcar '(lambda (s) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1168 (if (string-match (concat "\\<" pascal-str) s) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1169 (if (or (null pascal-pred) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1170 (funcall pascal-pred s)) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1171 (setq pascal-all (cons s pascal-all))))) |
5723 | 1172 keyword-list)) |
1173 | |
1174 ;; Function passed to completing-read, try-completion or | |
1175 ;; all-completions to get completion on STR. If predicate is non-nil, | |
1176 ;; it must be a function to be called for every match to check if this | |
1177 ;; should really be a match. If flag is t, the function returns a list | |
1178 ;; of all possible completions. If it is nil it returns a string, the | |
1179 ;; longest possible completion, or t if STR is an exact match. If flag | |
1180 ;; is 'lambda, the function returns t if STR is an exact match, nil | |
1181 ;; otherwise. | |
1182 | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1183 (defun pascal-completion (pascal-str pascal-pred pascal-flag) |
4934 | 1184 (save-excursion |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1185 (let ((pascal-all nil)) |
5723 | 1186 ;; Set buffer to use for searching labels. This should be set |
14000
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
1187 ;; within functions which use pascal-completions |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1188 (set-buffer pascal-buffer-to-use) |
5723 | 1189 |
1190 ;; Determine what should be completed | |
1191 (let ((state (car (pascal-calculate-indent)))) | |
1192 (cond (;--Within a declaration or parameterlist | |
1193 (or (eq state 'declaration) (eq state 'paramlist) | |
1194 (and (eq state 'defun) | |
1195 (save-excursion | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1196 (re-search-backward ")[ \t]*:" |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1197 (pascal-get-beg-of-line) t)))) |
5723 | 1198 (if (or (eq state 'paramlist) (eq state 'defun)) |
1199 (pascal-beg-of-defun)) | |
1200 (pascal-type-completion) | |
1201 (pascal-keyword-completion pascal-type-keywords)) | |
1202 (;--Starting a new statement | |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1203 (and (not (eq state 'contexp)) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1204 (save-excursion |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1205 (skip-chars-backward "a-zA-Z0-9_.") |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1206 (backward-sexp 1) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1207 (or (looking-at pascal-nosemi-re) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1208 (progn |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1209 (forward-sexp 1) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1210 (looking-at "\\s *\\(;\\|:[^=]\\)"))))) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1211 (save-excursion (pascal-var-completion)) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1212 (pascal-func-completion 'procedure) |
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1213 (pascal-keyword-completion pascal-start-keywords)) |
5723 | 1214 (t;--Anywhere else |
1215 (save-excursion (pascal-var-completion)) | |
1216 (pascal-func-completion 'function) | |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
1217 (pascal-keyword-completion pascal-separator-keywords)))) |
8689
499bf32bfd9b
(pascal-auto-lineup): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6942
diff
changeset
|
1218 |
5723 | 1219 ;; Now we have built a list of all matches. Give response to caller |
1220 (pascal-completion-response)))) | |
4934 | 1221 |
5723 | 1222 (defun pascal-completion-response () |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1223 (cond ((or (equal pascal-flag 'lambda) (null pascal-flag)) |
5723 | 1224 ;; This was not called by all-completions |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1225 (if (null pascal-all) |
5723 | 1226 ;; Return nil if there was no matching label |
1227 nil | |
1228 ;; Get longest string common in the labels | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1229 (let* ((elm (cdr pascal-all)) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1230 (match (car pascal-all)) |
5723 | 1231 (min (length match)) |
1232 exact tmp) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1233 (if (string= match pascal-str) |
5723 | 1234 ;; Return t if first match was an exact match |
1235 (setq match t) | |
1236 (while (not (null elm)) | |
1237 ;; Find longest common string | |
1238 (if (< (setq tmp (pascal-string-diff match (car elm))) min) | |
1239 (progn | |
1240 (setq min tmp) | |
1241 (setq match (substring match 0 min)))) | |
1242 ;; Terminate with match=t if this is an exact match | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1243 (if (string= (car elm) pascal-str) |
5723 | 1244 (progn |
1245 (setq match t) | |
1246 (setq elm nil)) | |
1247 (setq elm (cdr elm))))) | |
1248 ;; If this is a test just for exact match, return nil ot t | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1249 (if (and (equal pascal-flag 'lambda) (not (equal match 't))) |
5723 | 1250 nil |
1251 match)))) | |
1252 ;; If flag is t, this was called by all-completions. Return | |
1253 ;; list of all possible completions | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1254 (pascal-flag |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1255 pascal-all))) |
5723 | 1256 |
1257 (defvar pascal-last-word-numb 0) | |
1258 (defvar pascal-last-word-shown nil) | |
1259 (defvar pascal-last-completions nil) | |
1260 | |
1261 (defun pascal-complete-word () | |
1262 "Complete word at current point. | |
1263 \(See also `pascal-toggle-completions', `pascal-type-keywords', | |
6316
1032840397be
(pascal-indent-case): Handle comma separated list.
Richard M. Stallman <rms@gnu.org>
parents:
6153
diff
changeset
|
1264 `pascal-start-keywords' and `pascal-separator-keywords'.)" |
5723 | 1265 (interactive) |
1266 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | |
1267 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1268 (pascal-str (buffer-substring b e)) |
5723 | 1269 ;; The following variable is used in pascal-completion |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1270 (pascal-buffer-to-use (current-buffer)) |
5723 | 1271 (allcomp (if (and pascal-toggle-completions |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1272 (string= pascal-last-word-shown pascal-str)) |
5723 | 1273 pascal-last-completions |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1274 (all-completions pascal-str 'pascal-completion))) |
5723 | 1275 (match (if pascal-toggle-completions |
1276 "" (try-completion | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1277 pascal-str (mapcar '(lambda (elm) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1278 (cons elm 0)) allcomp))))) |
5723 | 1279 ;; Delete old string |
1280 (delete-region b e) | |
1281 | |
1282 ;; Toggle-completions inserts whole labels | |
1283 (if pascal-toggle-completions | |
4934 | 1284 (progn |
5723 | 1285 ;; Update entry number in list |
1286 (setq pascal-last-completions allcomp | |
1287 pascal-last-word-numb | |
1288 (if (>= pascal-last-word-numb (1- (length allcomp))) | |
1289 0 | |
1290 (1+ pascal-last-word-numb))) | |
1291 (setq pascal-last-word-shown (elt allcomp pascal-last-word-numb)) | |
1292 ;; Display next match or same string if no match was found | |
1293 (if (not (null allcomp)) | |
1294 (insert "" pascal-last-word-shown) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1295 (insert "" pascal-str) |
5723 | 1296 (message "(No match)"))) |
14000
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
1297 ;; The other form of completion does not necessarily do that. |
5723 | 1298 |
1299 ;; Insert match if found, or the original string if no match | |
1300 (if (or (null match) (equal match 't)) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1301 (progn (insert "" pascal-str) |
5723 | 1302 (message "(No match)")) |
1303 (insert "" match)) | |
1304 ;; Give message about current status of completion | |
1305 (cond ((equal match 't) | |
1306 (if (not (null (cdr allcomp))) | |
1307 (message "(Complete but not unique)") | |
1308 (message "(Sole completion)"))) | |
1309 ;; Display buffer if the current completion didn't help | |
1310 ;; on completing the label. | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1311 ((and (not (null (cdr allcomp))) (= (length pascal-str) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1312 (length match))) |
5723 | 1313 (with-output-to-temp-buffer "*Completions*" |
1314 (display-completion-list allcomp)) | |
1315 ;; Wait for a keypress. Then delete *Completion* window | |
1316 (momentary-string-display "" (point)) | |
1317 (delete-window (get-buffer-window (get-buffer "*Completions*"))) | |
1318 ))))) | |
1319 | |
1320 (defun pascal-show-completions () | |
1321 "Show all possible completions at current point." | |
1322 (interactive) | |
1323 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | |
1324 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1325 (pascal-str (buffer-substring b e)) |
5723 | 1326 ;; The following variable is used in pascal-completion |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1327 (pascal-buffer-to-use (current-buffer)) |
5723 | 1328 (allcomp (if (and pascal-toggle-completions |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1329 (string= pascal-last-word-shown pascal-str)) |
5723 | 1330 pascal-last-completions |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1331 (all-completions pascal-str 'pascal-completion)))) |
5723 | 1332 ;; Show possible completions in a temporary buffer. |
1333 (with-output-to-temp-buffer "*Completions*" | |
1334 (display-completion-list allcomp)) | |
1335 ;; Wait for a keypress. Then delete *Completion* window | |
1336 (momentary-string-display "" (point)) | |
1337 (delete-window (get-buffer-window (get-buffer "*Completions*"))))) | |
1338 | |
1339 | |
1340 (defun pascal-get-default-symbol () | |
1341 "Return symbol around current point as a string." | |
1342 (save-excursion | |
1343 (buffer-substring (progn | |
1344 (skip-chars-backward " \t") | |
1345 (skip-chars-backward "a-zA-Z0-9_") | |
1346 (point)) | |
1347 (progn | |
1348 (skip-chars-forward "a-zA-Z0-9_") | |
1349 (point))))) | |
1350 | |
1351 (defun pascal-build-defun-re (str &optional arg) | |
1352 "Return function/procedure starting with STR as regular expression. | |
1353 With optional second arg non-nil, STR is the complete name of the instruction." | |
1354 (if arg | |
1355 (concat "^\\(function\\|procedure\\)[ \t]+\\(" str "\\)\\>") | |
1356 (concat "^\\(function\\|procedure\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>"))) | |
1357 | |
1358 ;; Function passed to completing-read, try-completion or | |
1359 ;; all-completions to get completion on any function name. If | |
1360 ;; predicate is non-nil, it must be a function to be called for every | |
1361 ;; match to check if this should really be a match. If flag is t, the | |
1362 ;; function returns a list of all possible completions. If it is nil | |
1363 ;; it returns a string, the longest possible completion, or t if STR | |
1364 ;; is an exact match. If flag is 'lambda, the function returns t if | |
1365 ;; STR is an exact match, nil otherwise. | |
1366 | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1367 (defun pascal-comp-defun (pascal-str pascal-pred pascal-flag) |
5723 | 1368 (save-excursion |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1369 (let ((pascal-all nil) |
5723 | 1370 match) |
1371 | |
1372 ;; Set buffer to use for searching labels. This should be set | |
14000
36dc9ede3562
(pascal-auto-newline, pascal-mode, electric-pascal-hash):
Karl Heuer <kwzh@gnu.org>
parents:
13337
diff
changeset
|
1373 ;; within functions which use pascal-completions |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1374 (set-buffer pascal-buffer-to-use) |
5723 | 1375 |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1376 (let ((pascal-str pascal-str)) |
5723 | 1377 ;; Build regular expression for functions |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1378 (if (string= pascal-str "") |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1379 (setq pascal-str (pascal-build-defun-re "[a-zA-Z_]")) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1380 (setq pascal-str (pascal-build-defun-re pascal-str))) |
5723 | 1381 (goto-char (point-min)) |
1382 | |
1383 ;; Build a list of all possible completions | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1384 (while (re-search-forward pascal-str nil t) |
5723 | 1385 (setq match (buffer-substring (match-beginning 2) (match-end 2))) |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1386 (if (or (null pascal-pred) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1387 (funcall pascal-pred match)) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1388 (setq pascal-all (cons match pascal-all))))) |
5723 | 1389 |
1390 ;; Now we have built a list of all matches. Give response to caller | |
1391 (pascal-completion-response)))) | |
1392 | |
1393 (defun pascal-goto-defun () | |
1394 "Move to specified Pascal function/procedure. | |
1395 The default is a name found in the buffer around point." | |
1396 (interactive) | |
1397 (let* ((default (pascal-get-default-symbol)) | |
1398 ;; The following variable is used in pascal-comp-function | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1399 (pascal-buffer-to-use (current-buffer)) |
5723 | 1400 (default (if (pascal-comp-defun default nil 'lambda) |
1401 default "")) | |
1402 (label (if (not (string= default "")) | |
1403 ;; Do completion with default | |
1404 (completing-read (concat "Label: (default " default ") ") | |
1405 'pascal-comp-defun nil t "") | |
1406 ;; There is no default value. Complete without it | |
1407 (completing-read "Label: " | |
1408 'pascal-comp-defun nil t "")))) | |
1409 ;; If there was no response on prompt, use default value | |
1410 (if (string= label "") | |
1411 (setq label default)) | |
1412 ;; Goto right place in buffer if label is not an empty string | |
1413 (or (string= label "") | |
1414 (progn | |
1415 (goto-char (point-min)) | |
1416 (re-search-forward (pascal-build-defun-re label t)) | |
1417 (beginning-of-line))))) | |
1418 | |
1419 | |
4934 | 1420 |
5723 | 1421 ;;; |
1422 ;;; Pascal-outline-mode | |
1423 ;;; | |
1424 (defvar pascal-outline-map nil "Keymap used in Pascal Outline mode.") | |
1425 | |
1426 (if pascal-outline-map | |
1427 nil | |
1428 (if (boundp 'set-keymap-name) | |
1429 (set-keymap-name pascal-outline-map 'pascal-outline-map)) | |
1430 (if (not (boundp 'set-keymap-parent)) | |
1431 (setq pascal-outline-map (copy-keymap pascal-mode-map)) | |
1432 (setq pascal-outline-map (make-sparse-keymap)) | |
1433 (set-keymap-parent pascal-outline-map pascal-mode-map)) | |
10446
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
1434 (define-key pascal-outline-map "\M-\C-a" 'pascal-outline-prev-defun) |
034609a036b1
(pascal-mode-map, pascal-outline-map):
Richard M. Stallman <rms@gnu.org>
parents:
9479
diff
changeset
|
1435 (define-key pascal-outline-map "\M-\C-e" 'pascal-outline-next-defun) |
6942
90305d5fe5aa
(pascal-outline-map): Move pascal-outline-goto-defun to C-c C-d.
Richard M. Stallman <rms@gnu.org>
parents:
6316
diff
changeset
|
1436 (define-key pascal-outline-map "\C-c\C-d" 'pascal-outline-goto-defun) |
5723 | 1437 (define-key pascal-outline-map "\C-c\C-s" 'pascal-show-all) |
1438 (define-key pascal-outline-map "\C-c\C-h" 'pascal-hide-other-defuns)) | |
1439 | |
1440 (defvar pascal-outline-mode nil "Non-nil while using Pascal Outline mode.") | |
1441 (make-variable-buffer-local 'pascal-outline-mode) | |
1442 (set-default 'pascal-outline-mode nil) | |
1443 (if (not (assoc 'pascal-outline-mode minor-mode-alist)) | |
1444 (setq minor-mode-alist (append minor-mode-alist | |
1445 (list '(pascal-outline-mode " Outl"))))) | |
1446 | |
1447 (defun pascal-outline (&optional arg) | |
1448 "Outline-line minor mode for Pascal mode. | |
1449 When in Pascal Outline mode, portions | |
1450 of the text being edited may be made invisible. \\<pascal-outline-map> | |
1451 | |
1452 Pascal Outline mode provides some additional commands. | |
1453 | |
1454 \\[pascal-outline-prev-defun]\ | |
1455 \t- Move to previous function/procedure, hiding everything else. | |
1456 \\[pascal-outline-next-defun]\ | |
1457 \t- Move to next function/procedure, hiding everything else. | |
1458 \\[pascal-outline-goto-defun]\ | |
1459 \t- Goto function/procedure prompted for in minibuffer, | |
1460 \t hide all other functions. | |
1461 \\[pascal-show-all]\t- Show the whole buffer. | |
1462 \\[pascal-hide-other-defuns]\ | |
1463 \t- Hide everything but the current function (function under the cursor). | |
1464 \\[pascal-outline]\t- Leave pascal-outline-mode." | |
1465 (interactive "P") | |
1466 (setq pascal-outline-mode | |
1467 (if (null arg) (not pascal-outline-mode) t)) | |
1468 (if (boundp 'redraw-mode-line) | |
1469 (redraw-mode-line)) | |
1470 (if pascal-outline-mode | |
1471 (progn | |
1472 (setq selective-display t) | |
1473 (use-local-map pascal-outline-map)) | |
1474 (progn | |
1475 (setq selective-display nil) | |
1476 (pascal-show-all) | |
1477 (use-local-map pascal-mode-map)))) | |
1478 | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1479 (defun pascal-outline-change (b e pascal-flag) |
5723 | 1480 (let ((modp (buffer-modified-p))) |
1481 (unwind-protect | |
10534
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1482 (subst-char-in-region b e (if (= pascal-flag ?\n) |
38b5efae433a
(pascal-*-completion, pascal-comp-defun)
Richard M. Stallman <rms@gnu.org>
parents:
10446
diff
changeset
|
1483 ?\^M ?\n) pascal-flag) |
5723 | 1484 (set-buffer-modified-p modp)))) |
1485 | |
1486 (defun pascal-show-all () | |
1487 "Show all of the text in the buffer." | |
1488 (interactive) | |
1489 (pascal-outline-change (point-min) (point-max) ?\n)) | |
1490 | |
1491 (defun pascal-hide-other-defuns () | |
1492 "Show only the current defun." | |
1493 (interactive) | |
1494 (save-excursion | |
1495 (let ((beg (progn (if (not (looking-at "\\(function\\|procedure\\)\\>")) | |
1496 (pascal-beg-of-defun)) | |
1497 (point))) | |
1498 (end (progn (pascal-end-of-defun) | |
1499 (backward-sexp 1) | |
1500 (search-forward "\n\\|\^M" nil t) | |
1501 (point))) | |
1502 (opoint (point-min))) | |
1503 (goto-char (point-min)) | |
1504 | |
1505 ;; Hide all functions before current function | |
1506 (while (re-search-forward "^\\(function\\|procedure\\)\\>" beg 'move) | |
1507 (pascal-outline-change opoint (1- (match-beginning 0)) ?\^M) | |
1508 (setq opoint (point)) | |
1509 ;; Functions may be nested | |
1510 (if (> (progn (pascal-end-of-defun) (point)) beg) | |
1511 (goto-char opoint))) | |
1512 (if (> beg opoint) | |
1513 (pascal-outline-change opoint (1- beg) ?\^M)) | |
1514 | |
1515 ;; Show current function | |
1516 (pascal-outline-change beg end ?\n) | |
1517 ;; Hide nested functions | |
1518 (forward-char 1) | |
1519 (while (re-search-forward "^\\(function\\|procedure\\)\\>" end 'move) | |
1520 (setq opoint (point)) | |
1521 (pascal-end-of-defun) | |
1522 (pascal-outline-change opoint (point) ?\^M)) | |
1523 | |
1524 (goto-char end) | |
1525 (setq opoint end) | |
1526 | |
1527 ;; Hide all function after current function | |
1528 (while (re-search-forward "^\\(function\\|procedure\\)\\>" nil 'move) | |
1529 (pascal-outline-change opoint (1- (match-beginning 0)) ?\^M) | |
1530 (setq opoint (point)) | |
1531 (pascal-end-of-defun)) | |
1532 (pascal-outline-change opoint (point-max) ?\^M) | |
1533 | |
1534 ;; Hide main program | |
1535 (if (< (progn (forward-line -1) (point)) end) | |
4934 | 1536 (progn |
5723 | 1537 (goto-char beg) |
1538 (pascal-end-of-defun) | |
1539 (backward-sexp 1) | |
1540 (pascal-outline-change (point) (point-max) ?\^M)))))) | |
1541 | |
1542 (defun pascal-outline-next-defun () | |
1543 "Move to next function/procedure, hiding all others." | |
1544 (interactive) | |
1545 (pascal-end-of-defun) | |
1546 (pascal-hide-other-defuns)) | |
4934 | 1547 |
5723 | 1548 (defun pascal-outline-prev-defun () |
1549 "Move to previous function/procedure, hiding all others." | |
1550 (interactive) | |
1551 (pascal-beg-of-defun) | |
1552 (pascal-hide-other-defuns)) | |
4934 | 1553 |
5723 | 1554 (defun pascal-outline-goto-defun () |
1555 "Move to specified function/procedure, hiding all others." | |
1556 (interactive) | |
1557 (pascal-goto-defun) | |
1558 (pascal-hide-other-defuns)) | |
1559 | |
1560 ;;; pascal.el ends here |