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

Trailing whitepace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 13:24:35 +0000
parents 753f0d7fee84
children f48326c934af d7ddb3e565de
comparison
equal deleted inserted replaced
49597:e88404e8f2cf 49598:0d8b17d428b5
36 ;; one can put in .emacs: 36 ;; one can put in .emacs:
37 ;; 37 ;;
38 ;; (add-hook 'delphi-mode-hook 'turn-on-font-lock) 38 ;; (add-hook 'delphi-mode-hook 'turn-on-font-lock)
39 39
40 ;; If font-lock is not loaded by default, you might have to do: 40 ;; If font-lock is not loaded by default, you might have to do:
41 ;; 41 ;;
42 ;; (autoload 'font-lock-mode "font-lock") 42 ;; (autoload 'font-lock-mode "font-lock")
43 ;; (autoload 'turn-on-font-lock "font-lock") 43 ;; (autoload 'turn-on-font-lock "font-lock")
44 ;; (setq font-lock-support-mode 'lazy-lock-mode) 44 ;; (setq font-lock-support-mode 'lazy-lock-mode)
45 ;; 45 ;;
46 ;; Lazy lock is very necessary for faster screen updates. 46 ;; Lazy lock is very necessary for faster screen updates.
63 ;;; Code: 63 ;;; Code:
64 64
65 (provide 'delphi) 65 (provide 'delphi)
66 66
67 (defconst delphi-version 67 (defconst delphi-version
68 (let ((revision "$Revision: 3.7 $")) 68 (let ((revision "$Revision: 3.8 $"))
69 (string-match ": \\([^ ]+\\)" revision) 69 (string-match ": \\([^ ]+\\)" revision)
70 (match-string 1 revision)) 70 (match-string 1 revision))
71 "Version of this delphi mode.") 71 "Version of this delphi mode.")
72 72
73 (eval-and-compile 73 (eval-and-compile
185 :group 'delphi) 185 :group 'delphi)
186 186
187 (defconst delphi-directives 187 (defconst delphi-directives
188 '(absolute abstract assembler automated cdecl default dispid dynamic 188 '(absolute abstract assembler automated cdecl default dispid dynamic
189 export external far forward index inline message name near nodefault 189 export external far forward index inline message name near nodefault
190 overload override pascal private protected public published read readonly 190 overload override pascal private protected public published read readonly
191 register reintroduce resident resourcestring safecall stdcall stored 191 register reintroduce resident resourcestring safecall stdcall stored
192 virtual write writeonly) 192 virtual write writeonly)
193 "Delphi4 directives.") 193 "Delphi4 directives.")
194 194
195 (defconst delphi-keywords 195 (defconst delphi-keywords
196 (append 196 (append
197 '(;; Keywords. 197 '(;; Keywords.
198 and array as asm at begin case class const constructor contains 198 and array as asm at begin case class const constructor contains
199 destructor dispinterface div do downto else end except exports 199 destructor dispinterface div do downto else end except exports
200 file finalization finally for function goto if implementation implements 200 file finalization finally for function goto if implementation implements
201 in inherited initialization interface is label library mod nil not 201 in inherited initialization interface is label library mod nil not
202 of object on or out package packed procedure program property 202 of object on or out package packed procedure program property
203 raise record repeat requires result self set shl shr then threadvar 203 raise record repeat requires result self set shl shr then threadvar
204 to try type unit uses until var while with xor 204 to try type unit uses until var while with xor
205 205
206 ;; These routines should be keywords, if Borland had the balls. 206 ;; These routines should be keywords, if Borland had the balls.
207 break exit) 207 break exit)
208 208
246 "Delphi binary operations.") 246 "Delphi binary operations.")
247 247
248 (defconst delphi-visibilities '(public private protected published automated) 248 (defconst delphi-visibilities '(public private protected published automated)
249 "Class visibilities.") 249 "Class visibilities.")
250 250
251 (defconst delphi-block-statements 251 (defconst delphi-block-statements
252 '(begin try case repeat initialization finalization asm) 252 '(begin try case repeat initialization finalization asm)
253 "Statements that contain multiple substatements.") 253 "Statements that contain multiple substatements.")
254 254
255 (defconst delphi-mid-block-statements 255 (defconst delphi-mid-block-statements
256 `(except finally ,@delphi-visibilities) 256 `(except finally ,@delphi-visibilities)
524 (or (not (delphi-is kind delphi-strings)) 524 (or (not (delphi-is kind delphi-strings))
525 ;; Special case: string delimiters are start/end ambiguous. 525 ;; Special case: string delimiters are start/end ambiguous.
526 ;; We have an end only if there is some string content (at 526 ;; We have an end only if there is some string content (at
527 ;; least a starting delimiter). 527 ;; least a starting delimiter).
528 (not (delphi-is-literal-end (1- p))))) 528 (not (delphi-is-literal-end (1- p)))))
529 529
530 ;; Special case: strings cannot span lines. 530 ;; Special case: strings cannot span lines.
531 (and (delphi-is kind delphi-strings) (eq ?\n (char-after (1- p))))))) 531 (and (delphi-is kind delphi-strings) (eq ?\n (char-after (1- p)))))))
532 532
533 (defun delphi-is-stable-literal (p) 533 (defun delphi-is-stable-literal (p)
534 ;; True if the point p marks a stable point. That is, a point outside of a 534 ;; True if the point p marks a stable point. That is, a point outside of a
566 (let ((search-start (point))) 566 (let ((search-start (point)))
567 (cond ((not (delphi-is-literal-end search-start)) 567 (cond ((not (delphi-is-literal-end search-start))
568 ;; We are completing an incomplete literal. 568 ;; We are completing an incomplete literal.
569 (let ((kind (delphi-literal-kind (1- search-start)))) 569 (let ((kind (delphi-literal-kind (1- search-start))))
570 (delphi-complete-literal kind limit) 570 (delphi-complete-literal kind limit)
571 (delphi-set-text-properties 571 (delphi-set-text-properties
572 search-start (point) (delphi-literal-text-properties kind)))) 572 search-start (point) (delphi-literal-text-properties kind))))
573 573
574 ((re-search-forward 574 ((re-search-forward
575 "\\(//\\)\\|\\({\\)\\|\\((\\*\\)\\|\\('\\)\\|\\(\"\\)" 575 "\\(//\\)\\|\\({\\)\\|\\((\\*\\)\\|\\('\\)\\|\\(\"\\)"
576 limit 'goto-limit-on-fail) 576 limit 'goto-limit-on-fail)
581 ((match-beginning 4) 'string) 581 ((match-beginning 4) 'string)
582 ((match-beginning 5) 'double-quoted-string))) 582 ((match-beginning 5) 'double-quoted-string)))
583 (start (match-beginning 0))) 583 (start (match-beginning 0)))
584 (delphi-set-text-properties search-start start nil) 584 (delphi-set-text-properties search-start start nil)
585 (delphi-complete-literal kind limit) 585 (delphi-complete-literal kind limit)
586 (delphi-set-text-properties 586 (delphi-set-text-properties
587 start (point) (delphi-literal-text-properties kind)))) 587 start (point) (delphi-literal-text-properties kind))))
588 588
589 ;; Nothing found. Mark it as a non-literal. 589 ;; Nothing found. Mark it as a non-literal.
590 ((delphi-set-text-properties search-start limit nil))) 590 ((delphi-set-text-properties search-start limit nil)))
591 (delphi-step-progress (point) "Parsing" delphi-parsing-progress-step))) 591 (delphi-step-progress (point) "Parsing" delphi-parsing-progress-step)))
733 (token nil)) 733 (token nil))
734 (delphi-progress-start) 734 (delphi-progress-start)
735 (while (< p to) 735 (while (< p to)
736 ;; Color the token and move past it. 736 ;; Color the token and move past it.
737 (setq token (delphi-token-at p)) 737 (setq token (delphi-token-at p))
738 (add-text-properties 738 (add-text-properties
739 (delphi-token-start token) (delphi-token-end token) 739 (delphi-token-start token) (delphi-token-end token)
740 (list 'face (delphi-face-of (delphi-token-kind token)) 'lazy-lock t)) 740 (list 'face (delphi-face-of (delphi-token-kind token)) 'lazy-lock t))
741 (setq p (delphi-token-end token)) 741 (setq p (delphi-token-end token))
742 (delphi-step-progress p "Fontifying" delphi-fontifying-progress-step)) 742 (delphi-step-progress p "Fontifying" delphi-fontifying-progress-step))
743 (delphi-progress-done))))) 743 (delphi-progress-done)))))
754 (let ((delphi-ignore-changes t)) ; Prevent recursive calls. 754 (let ((delphi-ignore-changes t)) ; Prevent recursive calls.
755 (delphi-save-excursion 755 (delphi-save-excursion
756 (delphi-progress-start) 756 (delphi-progress-start)
757 ;; Reparse at least from the token previous to the change to the end of 757 ;; Reparse at least from the token previous to the change to the end of
758 ;; line after the change. 758 ;; line after the change.
759 (delphi-parse-region-until-stable 759 (delphi-parse-region-until-stable
760 (delphi-token-start (delphi-token-at (1- change-start))) 760 (delphi-token-start (delphi-token-at (1- change-start)))
761 (progn (goto-char change-end) (end-of-line) (point))) 761 (progn (goto-char change-end) (end-of-line) (point)))
762 (delphi-progress-done))))) 762 (delphi-progress-done)))))
763 763
764 (defun delphi-group-start (from-token) 764 (defun delphi-group-start (from-token)
812 (last-token from-token) 812 (last-token from-token)
813 (kind nil)) 813 (kind nil))
814 (catch 'done 814 (catch 'done
815 (while token 815 (while token
816 (setq kind (delphi-token-kind token)) 816 (setq kind (delphi-token-kind token))
817 (cond 817 (cond
818 ;; Skip over ()/[] groups. 818 ;; Skip over ()/[] groups.
819 ((eq 'close-group kind) (setq token (delphi-group-start token))) 819 ((eq 'close-group kind) (setq token (delphi-group-start token)))
820 820
821 ;; Stop at the beginning of the line or an open group. 821 ;; Stop at the beginning of the line or an open group.
822 ((delphi-is kind '(newline open-group)) (throw 'done nil)) 822 ((delphi-is kind '(newline open-group)) (throw 'done nil))
834 (last-token from-token) 834 (last-token from-token)
835 (kind nil)) 835 (kind nil))
836 (catch 'done 836 (catch 'done
837 (while token 837 (while token
838 (setq kind (delphi-token-kind token)) 838 (setq kind (delphi-token-kind token))
839 (cond 839 (cond
840 ((and (eq 'colon kind) 840 ((and (eq 'colon kind)
841 (delphi-is (delphi-token-kind last-token) 841 (delphi-is (delphi-token-kind last-token)
842 `(,@delphi-block-statements 842 `(,@delphi-block-statements
843 ,@delphi-expr-statements))) 843 ,@delphi-expr-statements)))
844 ;; We hit a label followed by a statement. Indent to the statement. 844 ;; We hit a label followed by a statement. Indent to the statement.
845 (throw 'done nil)) 845 (throw 'done nil))
846 846
847 ;; Skip over ()/[] groups. 847 ;; Skip over ()/[] groups.
914 914
915 ;; A class/record start also begins a block. 915 ;; A class/record start also begins a block.
916 ((delphi-composite-type-start token last-token) 916 ((delphi-composite-type-start token last-token)
917 (throw 'done (if stop-on-class last-token token))) 917 (throw 'done (if stop-on-class last-token token)))
918 ) 918 )
919 (unless (delphi-is token-kind delphi-whitespace) 919 (unless (delphi-is token-kind delphi-whitespace)
920 (setq last-token token)) 920 (setq last-token token))
921 (setq token (delphi-previous-token token))) 921 (setq token (delphi-previous-token token)))
922 ;; Start not found. 922 ;; Start not found.
923 nil))) 923 nil)))
924 924
1035 ((delphi-column-of (delphi-comment-content-start comment))))))) 1035 ((delphi-column-of (delphi-comment-content-start comment)))))))
1036 )) 1036 ))
1037 1037
1038 (defun delphi-is-use-clause-end (at-token last-token last-colon from-kind) 1038 (defun delphi-is-use-clause-end (at-token last-token last-colon from-kind)
1039 ;; True if we are after the end of a uses type clause. 1039 ;; True if we are after the end of a uses type clause.
1040 (when (and last-token 1040 (when (and last-token
1041 (not last-colon) 1041 (not last-colon)
1042 (eq 'comma (delphi-token-kind at-token)) 1042 (eq 'comma (delphi-token-kind at-token))
1043 (eq 'semicolon from-kind)) 1043 (eq 'semicolon from-kind))
1044 ;; Scan for the uses statement, just to be sure. 1044 ;; Scan for the uses statement, just to be sure.
1045 (let ((token (delphi-previous-token at-token)) 1045 (let ((token (delphi-previous-token at-token))
1146 (delphi-line-indent-of token delphi-indent-level)) 1146 (delphi-line-indent-of token delphi-indent-level))
1147 ;; Indent to use clause keyword. 1147 ;; Indent to use clause keyword.
1148 (delphi-line-indent-of token)))) 1148 (delphi-line-indent-of token))))
1149 1149
1150 ;; Assembly sections always indent in from the asm keyword. 1150 ;; Assembly sections always indent in from the asm keyword.
1151 ((eq token-kind 'asm) 1151 ((eq token-kind 'asm)
1152 (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level))) 1152 (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level)))
1153 1153
1154 ;; An enclosing statement delimits a previous statement. 1154 ;; An enclosing statement delimits a previous statement.
1155 ;; We try to use the existing indent of the previous statement, 1155 ;; We try to use the existing indent of the previous statement,
1156 ;; otherwise we calculate from the enclosing statement. 1156 ;; otherwise we calculate from the enclosing statement.
1234 (throw 'done 1234 (throw 'done
1235 (delphi-stmt-line-indent-of token delphi-compound-block-indent))) 1235 (delphi-stmt-line-indent-of token delphi-compound-block-indent)))
1236 1236
1237 ;; An enclosing ":" means a label. 1237 ;; An enclosing ":" means a label.
1238 ((and (eq 'colon token-kind) 1238 ((and (eq 'colon token-kind)
1239 (delphi-is (delphi-token-kind section-token) 1239 (delphi-is (delphi-token-kind section-token)
1240 delphi-block-statements) 1240 delphi-block-statements)
1241 (not last-terminator) 1241 (not last-terminator)
1242 (not expr-delimited) 1242 (not expr-delimited)
1243 (not (eq 'equals (delphi-token-kind last-token)))) 1243 (not (eq 'equals (delphi-token-kind last-token))))
1244 (throw 'done 1244 (throw 'done
1268 ;; Returns the indentation offset from the enclosing statement of the token. 1268 ;; Returns the indentation offset from the enclosing statement of the token.
1269 (let ((token (delphi-previous-token from-token)) 1269 (let ((token (delphi-previous-token from-token))
1270 (from-kind (delphi-token-kind from-token)) 1270 (from-kind (delphi-token-kind from-token))
1271 (token-kind nil) 1271 (token-kind nil)
1272 (stmt-start nil) 1272 (stmt-start nil)
1273 (last-token nil) 1273 (last-token nil)
1274 (equals-encountered nil) 1274 (equals-encountered nil)
1275 (before-equals nil) 1275 (before-equals nil)
1276 (expr-delimited nil)) 1276 (expr-delimited nil))
1277 (catch 'done 1277 (catch 'done
1278 (while token 1278 (while token
1327 ((eq 'case token-kind) 1327 ((eq 'case token-kind)
1328 (throw 'done 1328 (throw 'done
1329 (if stmt-start 1329 (if stmt-start
1330 ;; We are not actually indenting to the case statement, 1330 ;; We are not actually indenting to the case statement,
1331 ;; but are within a label expression. 1331 ;; but are within a label expression.
1332 (delphi-stmt-line-indent-of 1332 (delphi-stmt-line-indent-of
1333 stmt-start delphi-indent-level) 1333 stmt-start delphi-indent-level)
1334 ;; Indent from the case keyword. 1334 ;; Indent from the case keyword.
1335 (delphi-stmt-line-indent-of 1335 (delphi-stmt-line-indent-of
1336 token delphi-case-label-indent)))) 1336 token delphi-case-label-indent))))
1337 1337
1338 ;; Body expression statements are enclosing. Indent from the 1338 ;; Body expression statements are enclosing. Indent from the
1339 ;; statement's keyword, unless we have a non-block statement following 1339 ;; statement's keyword, unless we have a non-block statement following
1340 ;; it. 1340 ;; it.
1341 ((delphi-is token-kind delphi-body-expr-statements) 1341 ((delphi-is token-kind delphi-body-expr-statements)
1342 (throw 'done 1342 (throw 'done
1343 (delphi-stmt-line-indent-of 1343 (delphi-stmt-line-indent-of
1344 (or stmt-start token) delphi-indent-level))) 1344 (or stmt-start token) delphi-indent-level)))
1345 1345
1346 ;; An else statement is enclosing, but it doesn't have an expression. 1346 ;; An else statement is enclosing, but it doesn't have an expression.
1347 ;; Thus we take into account last-token instead of stmt-start. 1347 ;; Thus we take into account last-token instead of stmt-start.
1348 ((eq 'else token-kind) 1348 ((eq 'else token-kind)
1386 (cond (last-token (delphi-indent-of last-token delphi-indent-level)) 1386 (cond (last-token (delphi-indent-of last-token delphi-indent-level))
1387 1387
1388 ((+ (delphi-section-indent-of token) delphi-indent-level))))) 1388 ((+ (delphi-section-indent-of token) delphi-indent-level)))))
1389 1389
1390 ;; Assembly sections always indent in from the asm keyword. 1390 ;; Assembly sections always indent in from the asm keyword.
1391 ((eq token-kind 'asm) 1391 ((eq token-kind 'asm)
1392 (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level))) 1392 (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level)))
1393 1393
1394 ;; Stop at an enclosing statement and indent from it. 1394 ;; Stop at an enclosing statement and indent from it.
1395 ((delphi-is token-kind delphi-enclosing-statements) 1395 ((delphi-is token-kind delphi-enclosing-statements)
1396 (throw 'done (delphi-stmt-line-indent-of 1396 (throw 'done (delphi-stmt-line-indent-of
1424 ;; val := Foo 1424 ;; val := Foo
1425 ;; (foo, args) 1425 ;; (foo, args)
1426 ;; + 2; 1426 ;; + 2;
1427 ;; which doesn't look right. 1427 ;; which doesn't look right.
1428 ;;;; Align binary ops with the before token. 1428 ;;;; Align binary ops with the before token.
1429 ;;((delphi-is from-kind delphi-binary-ops) 1429 ;;((delphi-is from-kind delphi-binary-ops)
1430 ;;(throw 'done (delphi-indent-of before-equals 0))) 1430 ;;(throw 'done (delphi-indent-of before-equals 0)))
1431 1431
1432 ;; Assignments (:=) we skip over to get a normal indent. 1432 ;; Assignments (:=) we skip over to get a normal indent.
1433 ((eq (delphi-token-kind last-token) 'equals)) 1433 ((eq (delphi-token-kind last-token) 'equals))
1434 1434
1435 ;; Otherwise indent in from the equals. 1435 ;; Otherwise indent in from the equals.
1436 ((throw 'done 1436 ((throw 'done
1437 (delphi-indent-of before-equals delphi-indent-level))))) 1437 (delphi-indent-of before-equals delphi-indent-level)))))
1438 1438
1439 ;; Remember any "=" we encounter if it has not already been processed. 1439 ;; Remember any "=" we encounter if it has not already been processed.
1440 ((eq token-kind 'equals) 1440 ((eq token-kind 'equals)
1441 (setq equals-encountered token 1441 (setq equals-encountered token
1442 before-equals last-token)) 1442 before-equals last-token))
1443 ) 1443 )
1444 (unless (delphi-is token-kind delphi-whitespace) 1444 (unless (delphi-is token-kind delphi-whitespace)
1445 (setq last-token token)) 1445 (setq last-token token))
1471 ;; Use a previous section/routine's indent. 1471 ;; Use a previous section/routine's indent.
1472 (delphi-section-indent-of token)) 1472 (delphi-section-indent-of token))
1473 1473
1474 ((delphi-is token-kind delphi-match-block-statements) 1474 ((delphi-is token-kind delphi-match-block-statements)
1475 ;; Use the block's indentation. 1475 ;; Use the block's indentation.
1476 (let ((block-start 1476 (let ((block-start
1477 (delphi-block-start token 'stop-on-class))) 1477 (delphi-block-start token 'stop-on-class)))
1478 (cond 1478 (cond
1479 ;; When trailing a body statement, indent to 1479 ;; When trailing a body statement, indent to
1480 ;; the statement's keyword. 1480 ;; the statement's keyword.
1481 ((delphi-is-block-after-expr-statement block-start) 1481 ((delphi-is-block-after-expr-statement block-start)