diff options
| author | Richard M. Stallman | 1997-04-15 05:00:36 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-04-15 05:00:36 +0000 |
| commit | 815eae1d277a1fdb64a0aec2b5efb7f548cfed57 (patch) | |
| tree | 6f5c6a551aac819203c3f73a3fce76b9298f94fc | |
| parent | cdf3e5a2c76de62b01f881f6f71ca15925d1743b (diff) | |
| download | emacs-815eae1d277a1fdb64a0aec2b5efb7f548cfed57.tar.gz emacs-815eae1d277a1fdb64a0aec2b5efb7f548cfed57.zip | |
(font-lock-fontify-syntactically-region): Use new
features of parse-partial-sexp instead of doing regexp search.
| -rw-r--r-- | lisp/font-lock.el | 98 |
1 files changed, 26 insertions, 72 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 5186399ba34..81ed9d61541 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -1027,14 +1027,8 @@ delimit the region to fontify." | |||
| 1027 | (defun font-lock-fontify-syntactically-region (start end &optional loudly) | 1027 | (defun font-lock-fontify-syntactically-region (start end &optional loudly) |
| 1028 | "Put proper face on each string and comment between START and END. | 1028 | "Put proper face on each string and comment between START and END. |
| 1029 | START should be at the beginning of a line." | 1029 | START should be at the beginning of a line." |
| 1030 | (let ((synstart (cond (font-lock-comment-start-regexp | 1030 | (let (state prev here comment |
| 1031 | (concat "\\s\"\\|" font-lock-comment-start-regexp)) | 1031 | (cache (marker-position font-lock-cache-position))) |
| 1032 | (comment-start-skip | ||
| 1033 | (concat "\\s\"\\|" comment-start-skip)) | ||
| 1034 | (t | ||
| 1035 | "\\s\""))) | ||
| 1036 | (cache (marker-position font-lock-cache-position)) | ||
| 1037 | state prev here beg) | ||
| 1038 | (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) | 1032 | (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) |
| 1039 | (goto-char start) | 1033 | (goto-char start) |
| 1040 | ;; | 1034 | ;; |
| @@ -1058,73 +1052,33 @@ START should be at the beginning of a line." | |||
| 1058 | (set-marker font-lock-cache-position start)) | 1052 | (set-marker font-lock-cache-position start)) |
| 1059 | ;; | 1053 | ;; |
| 1060 | ;; If the region starts inside a string, show the extent of it. | 1054 | ;; If the region starts inside a string, show the extent of it. |
| 1061 | (when (nth 3 state) | 1055 | (when (or (nth 4 state) (nth 3 state)) |
| 1062 | (setq here (point)) | 1056 | (setq comment (nth 4 state) here (point)) |
| 1063 | (while (and (re-search-forward "\\s\"" end 'move) | 1057 | (setq state (parse-partial-sexp (point) end |
| 1064 | ;; Verify the state so we don't get fooled by quoting. | 1058 | nil nil state 'syntax-table)) |
| 1065 | (nth 3 (parse-partial-sexp here (point) nil nil state)))) | 1059 | (put-text-property here (point) 'face |
| 1066 | (put-text-property here (point) 'face font-lock-string-face) | 1060 | (if comment |
| 1067 | (setq state (parse-partial-sexp here (point) nil nil state))) | 1061 | font-lock-comment-face |
| 1068 | ;; | 1062 | font-lock-string-face))) |
| 1069 | ;; Likewise for a comment. | ||
| 1070 | (when (or (nth 4 state) (nth 7 state)) | ||
| 1071 | (let ((comstart (cond (font-lock-comment-start-regexp | ||
| 1072 | font-lock-comment-start-regexp) | ||
| 1073 | (comment-start-skip | ||
| 1074 | (concat "\\s<\\|" comment-start-skip)) | ||
| 1075 | (t | ||
| 1076 | "\\s<"))) | ||
| 1077 | (count 1)) | ||
| 1078 | (setq here (point)) | ||
| 1079 | (condition-case nil | ||
| 1080 | (save-restriction | ||
| 1081 | (narrow-to-region (point-min) end) | ||
| 1082 | ;; Go back to the real start of the comment. | ||
| 1083 | (re-search-backward comstart) | ||
| 1084 | (forward-comment 1) | ||
| 1085 | ;; If there is more than one comment type, then the previous | ||
| 1086 | ;; comment start might not be the real comment start. | ||
| 1087 | ;; For example, in C++ code, `here' might be on a line following | ||
| 1088 | ;; a // comment that is actually within a /* */ comment. | ||
| 1089 | (while (<= (point) here) | ||
| 1090 | (goto-char here) | ||
| 1091 | (re-search-backward comstart nil nil (incf count)) | ||
| 1092 | (forward-comment 1)) | ||
| 1093 | ;; Go back to the real end of the comment. | ||
| 1094 | (skip-chars-backward " \t")) | ||
| 1095 | (error (goto-char end))) | ||
| 1096 | (put-text-property here (point) 'face font-lock-comment-face) | ||
| 1097 | (setq state (parse-partial-sexp here (point) nil nil state)))) | ||
| 1098 | ;; | 1063 | ;; |
| 1099 | ;; Find each interesting place between here and `end'. | 1064 | ;; Find each interesting place between here and `end'. |
| 1100 | (while (and (< (point) end) | 1065 | (while (and (< (point) end) |
| 1101 | (setq prev (point)) | 1066 | (progn |
| 1102 | (re-search-forward synstart end t) | 1067 | (setq prev (point) |
| 1103 | (setq state (parse-partial-sexp prev (point) nil nil state))) | 1068 | state (parse-partial-sexp (point) end |
| 1104 | (cond ((nth 3 state) | 1069 | nil nil state 'syntax-table)) |
| 1105 | ;; | 1070 | (or (nth 3 state) (nth 4 state)))) |
| 1106 | ;; Found a real string start. | 1071 | (setq here (nth 8 state) comment (nth 4 state)) |
| 1107 | (setq here (point) beg (match-beginning 0)) | 1072 | (setq state (parse-partial-sexp (point) end |
| 1108 | (condition-case nil | 1073 | nil nil state 'syntax-table)) |
| 1109 | (save-restriction | 1074 | (put-text-property here (point) 'face |
| 1110 | (narrow-to-region (point-min) end) | 1075 | (if comment |
| 1111 | (goto-char (scan-sexps beg 1))) | 1076 | font-lock-comment-face |
| 1112 | (error (goto-char end))) | 1077 | font-lock-string-face)) |
| 1113 | (put-text-property beg (point) 'face font-lock-string-face) | 1078 | ;; |
| 1114 | (setq state (parse-partial-sexp here (point) nil nil state))) | 1079 | ;; Make sure `prev' is non-nil after the loop |
| 1115 | ((or (nth 4 state) (nth 7 state)) | 1080 | ;; only if it was set on the very last iteration. |
| 1116 | ;; | 1081 | (setq prev nil)))) |
| 1117 | ;; Found a real comment start. | ||
| 1118 | (setq here (point) beg (or (match-end 1) (match-beginning 0))) | ||
| 1119 | (goto-char beg) | ||
| 1120 | (condition-case nil | ||
| 1121 | (save-restriction | ||
| 1122 | (narrow-to-region (point-min) end) | ||
| 1123 | (forward-comment 1) | ||
| 1124 | (skip-chars-backward " \t")) | ||
| 1125 | (error (goto-char end))) | ||
| 1126 | (put-text-property beg (point) 'face font-lock-comment-face) | ||
| 1127 | (setq state (parse-partial-sexp here (point) nil nil state))))))) | ||
| 1128 | 1082 | ||
| 1129 | ;;; End of Syntactic fontification functions. | 1083 | ;;; End of Syntactic fontification functions. |
| 1130 | 1084 | ||