comparison lisp/modes/pascal.el @ 181:bfd6434d15b3 r20-3b17

Import from CVS: tag r20-3b17
author cvs
date Mon, 13 Aug 2007 09:53:19 +0200
parents 6075d714658b
children
comparison
equal deleted inserted replaced
180:add28d59e586 181:bfd6434d15b3
1 ;;; pascal.el --- major mode for editing pascal source in Emacs 1 ;;; pascal.el --- major mode for editing pascal source in Emacs
2 2
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. 3 ;; Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4 4
5 ;; Author: Espen Skoglund (espensk@stud.cs.uit.no) 5 ;; Author: Espen Skoglund (espensk@stud.cs.uit.no)
6 ;; Keywords: languages 6 ;; Keywords: languages
7 7
8 ;; This file is part of XEmacs. 8 ;; This file is part of XEmacs.
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of 16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details. 18 ;; General Public License for more details.
19 19
20 ;; You should have received a copy of the GNU General Public License 20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the 21 ;; along with XEmacs; see the file COPYING. If not, write to
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA. 23 ;; Boston, MA 02111-1307, USA.
24 24
25 ;;; Synched up with: FSF 19.34 25 ;;; Synched up with: FSF 19.34
26 26
27 ;;; Commentary: 27 ;;; Commentary:
44 ;; pascal-tab-always-indent t 44 ;; pascal-tab-always-indent t
45 ;; pascal-auto-endcomments t 45 ;; pascal-auto-endcomments t
46 ;; pascal-auto-lineup '(all) 46 ;; pascal-auto-lineup '(all)
47 ;; pascal-toggle-completions nil 47 ;; pascal-toggle-completions nil
48 ;; pascal-type-keywords '("array" "file" "packed" "char" 48 ;; pascal-type-keywords '("array" "file" "packed" "char"
49 ;; "integer" "real" "string" "record") 49 ;; "integer" "real" "string" "record")
50 ;; pascal-start-keywords '("begin" "end" "function" "procedure" 50 ;; pascal-start-keywords '("begin" "end" "function" "procedure"
51 ;; "repeat" "until" "while" "read" "readln" 51 ;; "repeat" "until" "while" "read" "readln"
52 ;; "reset" "rewrite" "write" "writeln") 52 ;; "reset" "rewrite" "write" "writeln")
53 ;; pascal-separator-keywords '("downto" "else" "mod" "div" "then")) 53 ;; pascal-separator-keywords '("downto" "else" "mod" "div" "then"))
54 54
55 ;; KNOWN BUGS / BUGREPORTS 55 ;; KNOWN BUGS / BUGREPORTS
56 ;; ======================= 56 ;; =======================
57 ;; As far as I know, there are no bugs in the current version of this 57 ;; As far as I know, there are no bugs in the current version of this
66 "Version of `pascal.el'.") 66 "Version of `pascal.el'.")
67 67
68 (defgroup pascal nil 68 (defgroup pascal nil
69 "Major mode for editing Pascal source in Emacs" 69 "Major mode for editing Pascal source in Emacs"
70 :group 'languages) 70 :group 'languages)
71
72 71
73 (defvar pascal-mode-abbrev-table nil 72 (defvar pascal-mode-abbrev-table nil
74 "Abbrev table in use in Pascal-mode buffers.") 73 "Abbrev table in use in Pascal-mode buffers.")
75 (define-abbrev-table 'pascal-mode-abbrev-table ()) 74 (define-abbrev-table 'pascal-mode-abbrev-table ())
76 75
102 ; (define-key pascal-mode-map "\C-cd" 'pascal-downcase-keywords) 101 ; (define-key pascal-mode-map "\C-cd" 'pascal-downcase-keywords)
103 ; (define-key pascal-mode-map "\C-cu" 'pascal-upcase-keywords) 102 ; (define-key pascal-mode-map "\C-cu" 'pascal-upcase-keywords)
104 ; (define-key pascal-mode-map "\C-cc" 'pascal-capitalize-keywords) 103 ; (define-key pascal-mode-map "\C-cc" 'pascal-capitalize-keywords)
105 ) 104 )
106 105
107 ;(defvar pascal-imenu-generic-expression 106 (defvar pascal-imenu-generic-expression
108 ; '("^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" . (2)) 107 '("^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" . (2))
109 ; "Imenu expression for Pascal-mode. See `imenu-generic-expression'.") 108 "Imenu expression for Pascal-mode. See `imenu-generic-expression'.")
110 109
111 (defvar pascal-keywords 110 (defvar pascal-keywords
112 '("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end" 111 '("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end"
113 "file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of" 112 "file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of"
114 "or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to" 113 "or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to"
156 (modify-syntax-entry ?& "." pascal-mode-syntax-table) 155 (modify-syntax-entry ?& "." pascal-mode-syntax-table)
157 (modify-syntax-entry ?| "." pascal-mode-syntax-table) 156 (modify-syntax-entry ?| "." pascal-mode-syntax-table)
158 (modify-syntax-entry ?_ "_" pascal-mode-syntax-table) 157 (modify-syntax-entry ?_ "_" pascal-mode-syntax-table)
159 (modify-syntax-entry ?\' "\"" pascal-mode-syntax-table)) 158 (modify-syntax-entry ?\' "\"" pascal-mode-syntax-table))
160 159
161 (defvar pascal-font-lock-keywords 160 (defvar pascal-font-lock-keywords (purecopy
162 (list 161 (list
163 '("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\(\\sw+\\)?" 162 '("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\(\\[a-z]\\)?"
164 (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t)) 163 1 font-lock-keyword-face)
164 '("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\([a-z][a-z0-9_]*\\)"
165 3 font-lock-function-name-face t)
165 ; ("type" "const" "real" "integer" "char" "boolean" "var" 166 ; ("type" "const" "real" "integer" "char" "boolean" "var"
166 ; "record" "array" "file") 167 ; "record" "array" "file")
167 (cons (concat "\\<\\(array\\|boolean\\|c\\(har\\|onst\\)\\|file\\|" 168 (cons (concat "\\<\\(array\\|boolean\\|c\\(har\\|onst\\)\\|file\\|"
168 "integer\\|re\\(al\\|cord\\)\\|type\\|var\\)\\>") 169 "integer\\|re\\(al\\|cord\\)\\|type\\|var\\)\\>")
169 'font-lock-type-face) 170 'font-lock-type-face)
170 '("\\<\\(label\\|external\\|forward\\)\\>" . font-lock-reference-face) 171 '("\\<\\(label\\|external\\|forward\\)\\>" . font-lock-reference-face)
171 '("\\<\\([0-9]+\\)[ \t]*:" 1 font-lock-reference-face) 172 '("\\<\\([0-9]+\\)[ \t]*:" 1 font-lock-function-name-face)
172 ; ("of" "to" "for" "if" "then" "else" "case" "while" 173 ; ("of" "to" "for" "if" "then" "else" "case" "while"
173 ; "do" "until" "and" "or" "not" "in" "with" "repeat" "begin" "end") 174 ; "do" "until" "and" "or" "not" "in" "with" "repeat" "begin" "end")
174 (concat "\\<\\(" 175 (concat "\\<\\("
175 "and\\|begin\\|case\\|do\\|e\\(lse\\|nd\\)\\|for\\|i[fn]\\|" 176 "and\\|begin\\|case\\|do\\|e\\(lse\\|nd\\)\\|for\\|i[fn]\\|"
176 "not\\|o[fr]\\|repeat\\|t\\(hen\\|o\\)\\|until\\|w\\(hile\\|ith\\)" 177 "not\\|o[fr]\\|repeat\\|t\\(hen\\|o\\)\\|until\\|w\\(hile\\|ith\\)"
177 "\\)\\>") 178 "\\)\\>")
178 '("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?" 179 '("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
179 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))) 180 1 font-lock-keyword-face)
181 '("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
182 2 font-lock-keyword-face nil t)))
180 "Additional expressions to highlight in Pascal mode.") 183 "Additional expressions to highlight in Pascal mode.")
184 (put 'pascal-mode 'font-lock-defaults '(pascal-font-lock-keywords nil t))
181 185
182 (defcustom pascal-indent-level 3 186 (defcustom pascal-indent-level 3
183 "*Indentation of Pascal statements with respect to containing block." 187 "*Indentation of Pascal statements with respect to containing block."
184 :type 'integer 188 :type 'integer
185 :group 'pascal) 189 :group 'pascal)
219 (const declaration) 223 (const declaration)
220 (const case))) 224 (const case)))
221 :group 'pascal) 225 :group 'pascal)
222 226
223 (defcustom pascal-toggle-completions nil 227 (defcustom pascal-toggle-completions nil
224 "*Non-nil means that \\<pascal-mode-map>\\[pascal-complete-word] should try all pRepeated use of \\[pascal-complete-word] will show you all of them. 228 "*Non-nil means that repeated use of \
225 Normally, when there is more than one possible completion, 229 \\<pascal-mode-map>\\[pascal-complete-word] will toggle the possible
226 it displays a list of all possible completions." 230 completions in the minibuffer. Normally, when there is more than one possible
231 completion, a buffer will display all completions."
227 :type 'boolean 232 :type 'boolean
228 :group 'pascal) 233 :group 'pascal)
229 234
230 (defcustom pascal-type-keywords 235 (defcustom pascal-type-keywords
231 '("array" "file" "packed" "char" "integer" "real" "string" "record") 236 '("array" "file" "packed" "char" "integer" "real" "string" "record")
358 (make-local-variable 'comment-start-skip) 363 (make-local-variable 'comment-start-skip)
359 (setq comment-start-skip "(\\*+ *\\|{ *") 364 (setq comment-start-skip "(\\*+ *\\|{ *")
360 (make-local-variable 'comment-end) 365 (make-local-variable 'comment-end)
361 (setq comment-end "}") 366 (setq comment-end "}")
362 ;; Font lock support 367 ;; Font lock support
363 ;;(make-local-variable 'font-lock-defaults) 368 ;(make-local-variable 'font-lock-defaults)
364 ;;(setq font-lock-defaults '(pascal-font-lock-keywords nil t)) 369 ;(setq font-lock-defaults '(pascal-font-lock-keywords nil t))
365 ;; Imenu support 370 ;; Imenu support
366 ;; (make-local-variable 'imenu-generic-expression) 371 (make-local-variable 'imenu-generic-expression)
367 ;; (setq imenu-generic-expression pascal-imenu-generic-expression) 372 (setq imenu-generic-expression pascal-imenu-generic-expression)
368 (run-hooks 'pascal-mode-hook)) 373 (run-hooks 'pascal-mode-hook))
369 374
370 375
371 376
372 ;;; 377 ;;;
917 922
918 (defun pascal-indent-comment (&optional arg) 923 (defun pascal-indent-comment (&optional arg)
919 "Indent current line as comment. 924 "Indent current line as comment.
920 If optional arg is non-nil, just return the 925 If optional arg is non-nil, just return the
921 column number the line should be indented to." 926 column number the line should be indented to."
922 (let* ((stcol (save-excursion 927 (let* ((stcol (save-excursion
923 (re-search-backward "(\\*\\|{" nil t) 928 (re-search-backward "(\\*\\|{" nil t)
924 (1+ (current-column))))) 929 (1+ (current-column)))))
925 (if arg stcol 930 (if arg stcol
926 (delete-horizontal-space) 931 (delete-horizontal-space)
927 (indent-to stcol)))) 932 (indent-to stcol))))
928 933
929 (defun pascal-indent-case () 934 (defun pascal-indent-case ()
930 "Indent within case statements." 935 "Indent within case statements."
931 (let ((savepos (point-marker)) 936 (let ((savepos (point-marker))
932 (end (prog2 937 (end (prog2
1004 (max (progn (pascal-declaration-end) 1009 (max (progn (pascal-declaration-end)
1005 (point)) 1010 (point))
1006 pos)))) 1011 pos))))
1007 ind) 1012 ind)
1008 1013
1009 (if (= (point-max) edpos)
1010 (save-excursion
1011 (goto-char (point-max))
1012 (insert "\n")))
1013 (goto-char stpos) 1014 (goto-char stpos)
1014 ;; Indent lines in record block 1015 ;; Indent lines in record block
1015 (if arg 1016 (if arg
1016 (while (<= (point) edpos) 1017 (while (<= (point) edpos)
1017 (beginning-of-line) 1018 (beginning-of-line)
1022 (forward-line 1))) 1023 (forward-line 1)))
1023 1024
1024 ;; Do lineup 1025 ;; Do lineup
1025 (setq ind (pascal-get-lineup-indent stpos edpos lineup)) 1026 (setq ind (pascal-get-lineup-indent stpos edpos lineup))
1026 (goto-char stpos) 1027 (goto-char stpos)
1027 (while (<= (point) edpos) 1028 (while (and (<= (point) edpos) (not (eobp)))
1028 (if (search-forward lineup (pascal-get-end-of-line) 'move) 1029 (if (search-forward lineup (pascal-get-end-of-line) 'move)
1029 (forward-char -1)) 1030 (forward-char -1))
1030 (delete-horizontal-space) 1031 (delete-horizontal-space)
1031 (indent-to ind) 1032 (indent-to ind)
1032 (if (not (looking-at lineup)) 1033 (if (not (looking-at lineup))
1060 (progn 1061 (progn
1061 (goto-char (match-beginning 0)) 1062 (goto-char (match-beginning 0))
1062 (skip-chars-backward " \t") 1063 (skip-chars-backward " \t")
1063 (if (> (current-column) ind) 1064 (if (> (current-column) ind)
1064 (setq ind (current-column))) 1065 (setq ind (current-column)))
1065 (goto-char (match-end 0))))))) 1066 (goto-char (match-end 0))
1067 (end-of-line)
1068 )))))
1066 ;; In case no lineup was found 1069 ;; In case no lineup was found
1067 (if (> ind 0) 1070 (if (> ind 0)
1068 (1+ ind) 1071 (1+ ind)
1069 ;; No lineup-string found 1072 ;; No lineup-string found
1070 (goto-char b) 1073 (goto-char b)
1124 (setq pascal-all (cons match pascal-all))))) 1127 (setq pascal-all (cons match pascal-all)))))
1125 (goto-char (match-beginning 0))))) 1128 (goto-char (match-beginning 0)))))
1126 1129
1127 (defun pascal-get-completion-decl () 1130 (defun pascal-get-completion-decl ()
1128 ;; Macro for searching through current declaration (var, type or const) 1131 ;; Macro for searching through current declaration (var, type or const)
1129 ;; for matches of `str' and adding the occurrence tp `all' 1132 ;; for matches of `str' and adding the occurrence to `all'
1130 (let ((end (save-excursion (pascal-declaration-end) 1133 (let ((end (save-excursion (pascal-declaration-end)
1131 (point))) 1134 (point)))
1132 match) 1135 match)
1133 ;; Traverse lines 1136 ;; Traverse lines
1134 (while (< (point) end) 1137 (while (< (point) end)