changeset 65839:8d9f98ffeae4

(tex-font-lock-syntactic-face-function): Don't set any syntax-table property here. (tex-font-lock-verb): New function. Do it here. (tex-font-lock-syntactic-keywords): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 04 Oct 2005 20:45:58 +0000
parents e7add15f0f59
children df9b548f3218
files lisp/textmodes/tex-mode.el
diffstat 1 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/tex-mode.el	Tue Oct 04 20:31:22 2005 +0000
+++ b/lisp/textmodes/tex-mode.el	Tue Oct 04 20:45:58 2005 +0000
@@ -631,7 +631,10 @@
       (,(concat "^\\(\\\\\\)end *{" verbs "}\\(.?\\)") (1 "|") (3 "<"))
       ;; ("^\\(\\\\\\)begin *{comment}" 1 "< b")
       ;; ("^\\\\end *{comment}.*\\(\n\\)" 1 "> b")
-      ("\\\\verb\\**\\([^a-z@*]\\)" 1 "\""))))
+      ("\\\\verb\\**\\([^a-z@*]\\)"
+       ;; Do it last, because it uses syntax-ppss which needs the
+       ;; syntax-table properties of previous entries.
+       1 (tex-font-lock-verb (match-end 1))))))
 
 (defun tex-font-lock-unfontify-region (beg end)
   (font-lock-default-unfontify-region beg end)
@@ -670,22 +673,38 @@
 (put 'tex-verbatim-face 'face-alias 'tex-verbatim)
 (defvar tex-verbatim-face 'tex-verbatim)
 
+(defun tex-font-lock-verb (end)
+  "Place syntax-table properties on the \verb construct.
+END is the position of the first delimiter after \verb."
+  (unless (nth 8 (syntax-ppss end))
+    ;; Do nothing if the \verb construct is itself inside a comment or
+    ;; verbatim env.
+    (save-excursion
+      ;; Let's find the end and mark it.
+      ;; We used to do it inside tex-font-lock-syntactic-face-function, but
+      ;; this leads to funny effects when jumping to the end of the buffer,
+      ;; because font-lock applies font-lock-syntactic-keywords to the whole
+      ;; preceding text but font-lock-syntactic-face-function only to the
+      ;; actually displayed text.
+      (goto-char end)
+      (let ((char (char-before)))
+        (skip-chars-forward (string ?^ char)) ;; Use `end' ?
+        (when (eq (char-syntax (preceding-char)) ?/)
+          (put-text-property (1- (point)) (point) 'syntax-table '(1)))
+        (unless (eobp)
+          (put-text-property (point) (1+ (point)) 'syntax-table '(7))
+          ;; Cause the rest of the buffer to be re-fontified.
+          ;; (remove-text-properties (1+ (point)) (point-max) '(fontified))
+          )))
+    "\""))
+
 ;; Use string syntax but math face for $...$.
 (defun tex-font-lock-syntactic-face-function (state)
   (let ((char (nth 3 state)))
     (cond
      ((not char) font-lock-comment-face)
      ((eq char ?$) tex-math-face)
-     (t
-      (when (char-valid-p char)
-	;; This is a \verb?...? construct.  Let's find the end and mark it.
-	(save-excursion
-	  (skip-chars-forward (string ?^ char)) ;; Use `end' ?
-	  (when (eq (char-syntax (preceding-char)) ?/)
-	    (put-text-property (1- (point)) (point) 'syntax-table '(1)))
-	  (unless (eobp)
-	    (put-text-property (point) (1+ (point)) 'syntax-table '(7)))))
-      tex-verbatim-face))))
+     (t tex-verbatim-face))))
 
 
 (defun tex-define-common-keys (keymap)