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