comparison lisp/progmodes/pascal.el @ 49598:0d8b17d428b5

Trailing whitepace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 13:24:35 +0000
parents 21c763762fb2
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49597:e88404e8f2cf 49598:0d8b17d428b5
41 ;; pascal-auto-newline nil 41 ;; pascal-auto-newline nil
42 ;; pascal-tab-always-indent t 42 ;; pascal-tab-always-indent t
43 ;; pascal-auto-endcomments t 43 ;; pascal-auto-endcomments t
44 ;; pascal-auto-lineup '(all) 44 ;; pascal-auto-lineup '(all)
45 ;; pascal-toggle-completions nil 45 ;; pascal-toggle-completions nil
46 ;; pascal-type-keywords '("array" "file" "packed" "char" 46 ;; pascal-type-keywords '("array" "file" "packed" "char"
47 ;; "integer" "real" "string" "record") 47 ;; "integer" "real" "string" "record")
48 ;; pascal-start-keywords '("begin" "end" "function" "procedure" 48 ;; pascal-start-keywords '("begin" "end" "function" "procedure"
49 ;; "repeat" "until" "while" "read" "readln" 49 ;; "repeat" "until" "while" "read" "readln"
50 ;; "reset" "rewrite" "write" "writeln") 50 ;; "reset" "rewrite" "write" "writeln")
51 ;; pascal-separator-keywords '("downto" "else" "mod" "div" "then")) 51 ;; pascal-separator-keywords '("downto" "else" "mod" "div" "then"))
102 (defvar pascal-imenu-generic-expression 102 (defvar pascal-imenu-generic-expression
103 '((nil "^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" 2)) 103 '((nil "^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" 2))
104 "Imenu expression for Pascal-mode. See `imenu-generic-expression'.") 104 "Imenu expression for Pascal-mode. See `imenu-generic-expression'.")
105 105
106 (defvar pascal-keywords 106 (defvar pascal-keywords
107 '("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end" 107 '("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end"
108 "file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of" 108 "file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of"
109 "or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to" 109 "or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to"
110 "type" "until" "var" "while" "with" 110 "type" "until" "var" "while" "with"
111 ;; The following are not standard in pascal, but widely used. 111 ;; The following are not standard in pascal, but widely used.
112 "get" "put" "input" "output" "read" "readln" "reset" "rewrite" "write" 112 "get" "put" "input" "output" "read" "readln" "reset" "rewrite" "write"
113 "writeln")) 113 "writeln"))
114 114
136 136
137 (if pascal-mode-syntax-table 137 (if pascal-mode-syntax-table
138 () 138 ()
139 (setq pascal-mode-syntax-table (make-syntax-table)) 139 (setq pascal-mode-syntax-table (make-syntax-table))
140 (modify-syntax-entry ?\\ "." pascal-mode-syntax-table) 140 (modify-syntax-entry ?\\ "." pascal-mode-syntax-table)
141 (modify-syntax-entry ?( "()1" pascal-mode-syntax-table) 141 (modify-syntax-entry ?( "()1" pascal-mode-syntax-table)
142 (modify-syntax-entry ?) ")(4" pascal-mode-syntax-table) 142 (modify-syntax-entry ?) ")(4" pascal-mode-syntax-table)
143 (modify-syntax-entry ?* ". 23b" pascal-mode-syntax-table) 143 (modify-syntax-entry ?* ". 23b" pascal-mode-syntax-table)
144 (modify-syntax-entry ?{ "<" pascal-mode-syntax-table) 144 (modify-syntax-entry ?{ "<" pascal-mode-syntax-table)
145 (modify-syntax-entry ?} ">" pascal-mode-syntax-table) 145 (modify-syntax-entry ?} ">" pascal-mode-syntax-table)
146 (modify-syntax-entry ?+ "." pascal-mode-syntax-table) 146 (modify-syntax-entry ?+ "." pascal-mode-syntax-table)
281 (point))) 281 (point)))
282 282
283 (defun pascal-declaration-end () 283 (defun pascal-declaration-end ()
284 (let ((nest 1)) 284 (let ((nest 1))
285 (while (and (> nest 0) 285 (while (and (> nest 0)
286 (re-search-forward 286 (re-search-forward
287 "[:=]\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)" 287 "[:=]\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)"
288 (save-excursion (end-of-line 2) (point)) t)) 288 (save-excursion (end-of-line 2) (point)) t))
289 (cond ((match-beginning 1) (setq nest (1+ nest))) 289 (cond ((match-beginning 1) (setq nest (1+ nest)))
290 ((match-beginning 2) (setq nest (1- nest))) 290 ((match-beginning 2) (setq nest (1- nest)))
291 ((looking-at "[^(\n]+)") (setq nest 0)))))) 291 ((looking-at "[^(\n]+)") (setq nest 0))))))
292 292
298 (cond ((match-beginning 1) (setq nest 0)) 298 (cond ((match-beginning 1) (setq nest 0))
299 ((match-beginning 2) (setq nest (1- nest))) 299 ((match-beginning 2) (setq nest (1- nest)))
300 ((match-beginning 3) (setq nest (1+ nest))))) 300 ((match-beginning 3) (setq nest (1+ nest)))))
301 (= nest 0))) 301 (= nest 0)))
302 302
303 303
304 (defsubst pascal-within-string () 304 (defsubst pascal-within-string ()
305 (save-excursion 305 (save-excursion
306 (nth 3 (parse-partial-sexp (pascal-get-beg-of-line) (point))))) 306 (nth 3 (parse-partial-sexp (pascal-get-beg-of-line) (point)))))
307 307
308 308
418 ((and (looking-at "(\\*\\|\\*[^)]") 418 ((and (looking-at "(\\*\\|\\*[^)]")
419 (not (save-excursion 419 (not (save-excursion
420 (search-forward "*)" (pascal-get-end-of-line) t)))) 420 (search-forward "*)" (pascal-get-end-of-line) t))))
421 (setq setstar t)))) 421 (setq setstar t))))
422 ;; If last line was a star comment line then this one shall be too. 422 ;; If last line was a star comment line then this one shall be too.
423 (if (null setstar) 423 (if (null setstar)
424 (pascal-indent-line) 424 (pascal-indent-line)
425 (insert "* ")))) 425 (insert "* "))))
426 426
427 427
428 (defun electric-pascal-semi-or-dot () 428 (defun electric-pascal-semi-or-dot ()
600 (interactive) 600 (interactive)
601 (catch 'found 601 (catch 'found
602 (if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re))) 602 (if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re)))
603 (forward-sexp 1)) 603 (forward-sexp 1))
604 (let ((nest 0) (max -1) (func 0) 604 (let ((nest 0) (max -1) (func 0)
605 (reg (concat pascal-beg-block-re "\\|" 605 (reg (concat pascal-beg-block-re "\\|"
606 pascal-end-block-re "\\|" 606 pascal-end-block-re "\\|"
607 pascal-defun-re))) 607 pascal-defun-re)))
608 (while (re-search-backward reg nil 'move) 608 (while (re-search-backward reg nil 'move)
609 (cond ((let ((state (save-excursion 609 (cond ((let ((state (save-excursion
610 (parse-partial-sexp (point-min) (point))))) 610 (parse-partial-sexp (point-min) (point)))))
632 (forward-sexp 1)) 632 (forward-sexp 1))
633 (if (not (looking-at pascal-defun-re)) 633 (if (not (looking-at pascal-defun-re))
634 (pascal-beg-of-defun)) 634 (pascal-beg-of-defun))
635 (forward-char 1) 635 (forward-char 1)
636 (let ((nest 0) (func 1) 636 (let ((nest 0) (func 1)
637 (reg (concat pascal-beg-block-re "\\|" 637 (reg (concat pascal-beg-block-re "\\|"
638 pascal-end-block-re "\\|" 638 pascal-end-block-re "\\|"
639 pascal-defun-re))) 639 pascal-defun-re)))
640 (while (and (/= func 0) 640 (while (and (/= func 0)
641 (re-search-forward reg nil 'move)) 641 (re-search-forward reg nil 'move))
642 (cond ((let ((state (save-excursion 642 (cond ((let ((state (save-excursion
684 (if (not pos) 684 (if (not pos)
685 ;; Skip a whole block 685 ;; Skip a whole block
686 (catch 'found 686 (catch 'found
687 (while t 687 (while t
688 (re-search-forward regexp nil 'move) 688 (re-search-forward regexp nil 'move)
689 (setq nest (if (match-end 1) 689 (setq nest (if (match-end 1)
690 (1+ nest) 690 (1+ nest)
691 (1- nest))) 691 (1- nest)))
692 (cond ((eobp) 692 (cond ((eobp)
693 (throw 'found (point))) 693 (throw 'found (point)))
694 ((= 0 nest) 694 ((= 0 nest)
937 (= (following-char) ?\;)) 937 (= (following-char) ?\;))
938 (setq complete t)) 938 (setq complete t))
939 ))))) 939 )))))
940 940
941 ;; Return type of block and indent level. 941 ;; Return type of block and indent level.
942 (if (> par 0) ; Unclosed Parenthesis 942 (if (> par 0) ; Unclosed Parenthesis
943 (list 'contexp par) 943 (list 'contexp par)
944 (list type (pascal-indent-level)))))) 944 (list type (pascal-indent-level))))))
945 945
946 (defun pascal-indent-level () 946 (defun pascal-indent-level ()
947 "Return the indent-level the current statement has. 947 "Return the indent-level the current statement has.
972 (re-search-backward "\\<case\\>" nil t))) 972 (re-search-backward "\\<case\\>" nil t)))
973 (beg (point)) oldpos 973 (beg (point)) oldpos
974 (ind 0)) 974 (ind 0))
975 ;; Get right indent 975 ;; Get right indent
976 (while (< (point) end) 976 (while (< (point) end)
977 (if (re-search-forward 977 (if (re-search-forward
978 "^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:" 978 "^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:"
979 (marker-position end) 'move) 979 (marker-position end) 'move)
980 (forward-char -1)) 980 (forward-char -1))
981 (if (< (point) end) 981 (if (< (point) end)
982 (progn 982 (progn
1008 indent of the current line in parameterlist." 1008 indent of the current line in parameterlist."
1009 (save-excursion 1009 (save-excursion
1010 (let* ((oldpos (point)) 1010 (let* ((oldpos (point))
1011 (stpos (progn (goto-char (scan-lists (point) -1 1)) (point))) 1011 (stpos (progn (goto-char (scan-lists (point) -1 1)) (point)))
1012 (stcol (1+ (current-column))) 1012 (stcol (1+ (current-column)))
1013 (edpos (progn (pascal-declaration-end) 1013 (edpos (progn (pascal-declaration-end)
1014 (search-backward ")" (pascal-get-beg-of-line) t) 1014 (search-backward ")" (pascal-get-beg-of-line) t)
1015 (point))) 1015 (point)))
1016 (usevar (re-search-backward "\\<var\\>" stpos t))) 1016 (usevar (re-search-backward "\\<var\\>" stpos t)))
1017 (if arg (progn 1017 (if arg (progn
1018 ;; If arg, just return indent 1018 ;; If arg, just return indent
1030 (defun pascal-indent-declaration (&optional arg start end) 1030 (defun pascal-indent-declaration (&optional arg start end)
1031 "Indent current lines as declaration, lining up the `:'s or `='s." 1031 "Indent current lines as declaration, lining up the `:'s or `='s."
1032 (let ((pos (point-marker))) 1032 (let ((pos (point-marker)))
1033 (if (and (not (or arg start)) (not (pascal-declaration-beg))) 1033 (if (and (not (or arg start)) (not (pascal-declaration-beg)))
1034 () 1034 ()
1035 (let ((lineup (if (or (looking-at "\\<var\\>\\|\\<record\\>") arg start) 1035 (let ((lineup (if (or (looking-at "\\<var\\>\\|\\<record\\>") arg start)
1036 ":" "=")) 1036 ":" "="))
1037 (stpos (if start start 1037 (stpos (if start start
1038 (forward-word 2) (backward-word 1) (point))) 1038 (forward-word 2) (backward-word 1) (point)))
1039 (edpos (set-marker (make-marker) 1039 (edpos (set-marker (make-marker)
1040 (if end end 1040 (if end end
1106 ;; No lineup-string found 1106 ;; No lineup-string found
1107 (goto-char b) 1107 (goto-char b)
1108 (end-of-line) 1108 (end-of-line)
1109 (skip-chars-backward " \t") 1109 (skip-chars-backward " \t")
1110 (1+ (current-column)))))) 1110 (1+ (current-column))))))
1111 1111
1112 1112
1113 1113
1114 ;;; 1114 ;;;
1115 ;;; Completion 1115 ;;; Completion
1116 ;;; 1116 ;;;
1144 ((eq type 'procedure) "\\<\\(procedure\\)\\s +") 1144 ((eq type 'procedure) "\\<\\(procedure\\)\\s +")
1145 ((eq type 'function) "\\<\\(function\\)\\s +") 1145 ((eq type 'function) "\\<\\(function\\)\\s +")
1146 (t "\\<\\(function\\|procedure\\)\\s +")) 1146 (t "\\<\\(function\\|procedure\\)\\s +"))
1147 "\\<\\(" pascal-str "[a-zA-Z0-9_.]*\\)\\>")) 1147 "\\<\\(" pascal-str "[a-zA-Z0-9_.]*\\)\\>"))
1148 match) 1148 match)
1149 1149
1150 (if (not (looking-at "\\<\\(function\\|procedure\\)\\>")) 1150 (if (not (looking-at "\\<\\(function\\|procedure\\)\\>"))
1151 (re-search-backward "\\<\\(function\\|procedure\\)\\>" nil t)) 1151 (re-search-backward "\\<\\(function\\|procedure\\)\\>" nil t))
1152 (forward-char 1) 1152 (forward-char 1)
1153 1153
1154 ;; Search through all reachable functions 1154 ;; Search through all reachable functions
1169 match) 1169 match)
1170 ;; Traverse lines 1170 ;; Traverse lines
1171 (while (< (point) end) 1171 (while (< (point) end)
1172 (if (re-search-forward "[:=]" (pascal-get-end-of-line) t) 1172 (if (re-search-forward "[:=]" (pascal-get-end-of-line) t)
1173 ;; Traverse current line 1173 ;; Traverse current line
1174 (while (and (re-search-backward 1174 (while (and (re-search-backward
1175 (concat "\\((\\|\\<\\(var\\|type\\|const\\)\\>\\)\\|" 1175 (concat "\\((\\|\\<\\(var\\|type\\|const\\)\\>\\)\\|"
1176 pascal-symbol-re) 1176 pascal-symbol-re)
1177 (pascal-get-beg-of-line) t) 1177 (pascal-get-beg-of-line) t)
1178 (not (match-end 1))) 1178 (not (match-end 1)))
1179 (setq match (buffer-substring (match-beginning 0) (match-end 0))) 1179 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
1180 (if (string-match (concat "\\<" pascal-str) match) 1180 (if (string-match (concat "\\<" pascal-str) match)
1230 (setq twice 0))))))))) 1230 (setq twice 0)))))))))
1231 1231
1232 1232
1233 (defun pascal-keyword-completion (keyword-list) 1233 (defun pascal-keyword-completion (keyword-list)
1234 "Give list of all possible completions of keywords in KEYWORD-LIST." 1234 "Give list of all possible completions of keywords in KEYWORD-LIST."
1235 (mapcar '(lambda (s) 1235 (mapcar '(lambda (s)
1236 (if (string-match (concat "\\<" pascal-str) s) 1236 (if (string-match (concat "\\<" pascal-str) s)
1237 (if (or (null pascal-pred) 1237 (if (or (null pascal-pred)
1238 (funcall pascal-pred s)) 1238 (funcall pascal-pred s))
1239 (setq pascal-all (cons s pascal-all))))) 1239 (setq pascal-all (cons s pascal-all)))))
1240 keyword-list)) 1240 keyword-list))
1281 (pascal-keyword-completion pascal-start-keywords)) 1281 (pascal-keyword-completion pascal-start-keywords))
1282 (t;--Anywhere else 1282 (t;--Anywhere else
1283 (save-excursion (pascal-var-completion)) 1283 (save-excursion (pascal-var-completion))
1284 (pascal-func-completion 'function) 1284 (pascal-func-completion 'function)
1285 (pascal-keyword-completion pascal-separator-keywords)))) 1285 (pascal-keyword-completion pascal-separator-keywords))))
1286 1286
1287 ;; Now we have built a list of all matches. Give response to caller 1287 ;; Now we have built a list of all matches. Give response to caller
1288 (pascal-completion-response)))) 1288 (pascal-completion-response))))
1289 1289
1290 (defun pascal-completion-response () 1290 (defun pascal-completion-response ()
1291 (cond ((or (equal pascal-flag 'lambda) (null pascal-flag)) 1291 (cond ((or (equal pascal-flag 'lambda) (null pascal-flag))
1350 ;; Toggle-completions inserts whole labels 1350 ;; Toggle-completions inserts whole labels
1351 (if pascal-toggle-completions 1351 (if pascal-toggle-completions
1352 (progn 1352 (progn
1353 ;; Update entry number in list 1353 ;; Update entry number in list
1354 (setq pascal-last-completions allcomp 1354 (setq pascal-last-completions allcomp
1355 pascal-last-word-numb 1355 pascal-last-word-numb
1356 (if (>= pascal-last-word-numb (1- (length allcomp))) 1356 (if (>= pascal-last-word-numb (1- (length allcomp)))
1357 0 1357 0
1358 (1+ pascal-last-word-numb))) 1358 (1+ pascal-last-word-numb)))
1359 (setq pascal-last-word-shown (elt allcomp pascal-last-word-numb)) 1359 (setq pascal-last-word-shown (elt allcomp pascal-last-word-numb))
1360 ;; Display next match or same string if no match was found 1360 ;; Display next match or same string if no match was found
1372 ;; Give message about current status of completion 1372 ;; Give message about current status of completion
1373 (cond ((equal match 't) 1373 (cond ((equal match 't)
1374 (if (not (null (cdr allcomp))) 1374 (if (not (null (cdr allcomp)))
1375 (message "(Complete but not unique)") 1375 (message "(Complete but not unique)")
1376 (message "(Sole completion)"))) 1376 (message "(Sole completion)")))
1377 ;; Display buffer if the current completion didn't help 1377 ;; Display buffer if the current completion didn't help
1378 ;; on completing the label. 1378 ;; on completing the label.
1379 ((and (not (null (cdr allcomp))) (= (length pascal-str) 1379 ((and (not (null (cdr allcomp))) (= (length pascal-str)
1380 (length match))) 1380 (length match)))
1381 (with-output-to-temp-buffer "*Completions*" 1381 (with-output-to-temp-buffer "*Completions*"
1382 (display-completion-list allcomp)) 1382 (display-completion-list allcomp))
1445 ;; Build regular expression for functions 1445 ;; Build regular expression for functions
1446 (if (string= pascal-str "") 1446 (if (string= pascal-str "")
1447 (setq pascal-str (pascal-build-defun-re "[a-zA-Z_]")) 1447 (setq pascal-str (pascal-build-defun-re "[a-zA-Z_]"))
1448 (setq pascal-str (pascal-build-defun-re pascal-str))) 1448 (setq pascal-str (pascal-build-defun-re pascal-str)))
1449 (goto-char (point-min)) 1449 (goto-char (point-min))
1450 1450
1451 ;; Build a list of all possible completions 1451 ;; Build a list of all possible completions
1452 (while (re-search-forward pascal-str nil t) 1452 (while (re-search-forward pascal-str nil t)
1453 (setq match (buffer-substring (match-beginning 2) (match-end 2))) 1453 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
1454 (if (or (null pascal-pred) 1454 (if (or (null pascal-pred)
1455 (funcall pascal-pred match)) 1455 (funcall pascal-pred match))
1545 (use-local-map pascal-mode-map)))) 1545 (use-local-map pascal-mode-map))))
1546 1546
1547 (defun pascal-outline-change (b e pascal-flag) 1547 (defun pascal-outline-change (b e pascal-flag)
1548 (let ((modp (buffer-modified-p))) 1548 (let ((modp (buffer-modified-p)))
1549 (unwind-protect 1549 (unwind-protect
1550 (subst-char-in-region b e (if (= pascal-flag ?\n) 1550 (subst-char-in-region b e (if (= pascal-flag ?\n)
1551 ?\^M ?\n) pascal-flag) 1551 ?\^M ?\n) pascal-flag)
1552 (set-buffer-modified-p modp)))) 1552 (set-buffer-modified-p modp))))
1553 1553
1554 (defun pascal-show-all () 1554 (defun pascal-show-all ()
1555 "Show all of the text in the buffer." 1555 "Show all of the text in the buffer."