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