annotate lisp/modes/pascal.el @ 183:e121b013d1f0 r20-3b18

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