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