Commits

steveb  committed 15a5827

font-latex.el update for v21 XEmacs

  • Participants
  • Parent commits 1fedd4d

Comments (0)

Files changed (3)

+1998-04-10  SL Baur  <steve@altair.xemacs.org>
+
+	* font-latex.el-0.512.
+
+1998-04-07  SL Baur  <steve@altair.xemacs.org>
+
+	* Makefile (binkit): Use TAR/EXCLUDES variables from XEmacs.rules.
+
 1998-02-25  SL Baur  <steve@altair.xemacs.org>
 
 	* texi/auc-tex.texi: Add direntry section for automatic
 
 # remove the MULE_ELCS line for building without Mule.
 
-VERSION = 1.07
+VERSION = 1.08
 AUTHOR_VERSION = 9.7p
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = auctex

File font-latex.el

 
 ;; Copyright (C) 1996, 1997, 1998 Peter S. Galbraith
  
-;; Authors:    Peter S. Galbraith <galbraith@mixing.qc.dfo.ca>
+;; Authors:    Peter S. Galbraith <GalbraithP@df0-mpo.gc.ca>
 ;;             Simon Marshall <Simon.Marshall@esrin.esa.it>
-;; Maintainer: Peter S. Galbraith <galbraith@mixing.qc.dfo.ca>
+;; Maintainer: Peter S. Galbraith <GalbraithP@df0-mpo.gc.ca>
 ;; Created:    06 July 1996
-;; Version:    0.509 (06 Feb 98)
+;; Version:    0.512 (7 Apr 98)
 ;; Keywords:   LaTeX faces
 
 ;; RCS $Id$
 ;; Note: RCS version number does not correspond to release number.
 
 ;; LCD Archive Entry: (Not yet submitted!)
-;; font-latex|Peter Galbraith|galbraith@mixing.qc.dfo.ca|
+;; font-latex|Peter Galbraith|GalbraithP@df0-mpo.gc.ca|
 ;; LaTeX fontification for font-lock|
 ;; 06-Jul-1996|0.01|~/modes/font-latex.el|
 
 ;; New versions of this package (if they exist) may be found at:
 ;;  ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/font-latex.el
 
+;; ** Infinite loops !? **
+;;  If you get an infinite loop, send me a bug report!
+;;  Then set the following in your ~/.emacs file to keep on working:
+;;   (setq font-latex-do-multi-line nil)
+
 ;; Description:
 ;;  This package enhances font-lock fontification patterns for LaTeX.
 ;;  font-lock mode is a minor mode that causes your comments to be
 ;;    instead of `highlighting 1: \(^\|[^\\]\)\(\\[a-zA-Z\\]+\)'
 ;; ----------------------------------------------------------------------------
 ;;; Change log:
+;; V0.512 07Apr98 Stephen R. Anderson <sra@bloch.ling.yale.edu> (RCS V1.57)
+;;    xemacs beta 20.5 sets the major version to 21.
+;; V0.511 07Apr98 PSG (RCS V1.55)
+;;    {\bf ...} multi-line cache related infinite loop fixed.
+;; V0.510 19Mar98 PSG (RCS V1.54)
+;;    More multi-line cache related infinite loops fixed.
 ;; V0.509 20Feb98 PSG (RCS V1.53)
 ;;    XEmacs infinite loop in font-latex-match-font-inside-braces cache.
 ;; V0.508 06Feb98 PSG (RCS V1.51)
 ;;; Code:
 (require 'font-lock)
 
+(defvar font-latex-do-multi-line t
+  "*Set this to nil to disable the multi-line fontification 
+prone to infinite loop bugs.")
+
 (defvar font-latex-warning-face			'font-latex-warning-face
   "Face to use for LaTeX major keywords.")
 (defvar font-latex-sedate-face			'font-latex-sedate-face
 (defvar font-latex-is-XEmacs20
   (and (not (null (save-match-data 
                     (string-match "XEmacs\\|Lucid" emacs-version))))
-       (= 20 emacs-major-version)))
+       (<= 20 emacs-major-version)))    ;xemacs-beta-20.5 sets it to version 21
 (defvar font-latex-is-Emacs19
   (and (not font-latex-is-XEmacs19) 
        (not font-latex-is-XEmacs20) 
  subexpression 1 is the contents of any following [...] forms 
  subexpression 2 is the contents of any following {...} forms.  
 Returns nil if none of KEYWORDS is found."
-  (when (and font-latex-match-command-cache-keywords
+  (when (and font-latex-do-multi-line
+             font-latex-match-command-cache-keywords
              font-latex-match-command-cache-limit
              font-latex-match-command-cache-start
              font-latex-match-command-cache-end
              (equal font-latex-match-command-cache-keywords keywords)
+             (not (= font-latex-match-command-cache-end (point)))
              (< font-latex-match-command-cache-start (point))
-             (not (= font-latex-match-command-cache-end (point)))
-             (> font-latex-match-command-cache-limit (point))
-             (not font-latex-match-command-cache-stop))
+             (>= font-latex-match-command-cache-limit (point))
+             (not font-latex-match-command-cache-stop)
+             (font-latex-not-on-same-line-as 
+              font-latex-match-command-cache-start))
     (goto-char font-latex-match-command-cache-start))
   (setq font-latex-match-command-cache-stop nil)
   (when (re-search-forward keywords limit t)
                   (goto-char cend))))))
         (store-match-data (list kbeg kend sbeg send cbeg cend))
 
-        (when (and font-latex-match-command-cache-keywords ;Sanity check!
+        (when (and font-latex-do-multi-line
+                   font-latex-match-command-cache-keywords ;Sanity check!
                    (equal font-latex-match-command-cache-keywords keywords)
                    font-latex-match-command-cache-match
                    (equal font-latex-match-command-cache-match
         (setq font-latex-match-command-cache-match
               (list kbeg kend sbeg send cbeg cend))
 
-        (when cache-reset
+        (when (and font-latex-do-multi-line cache-reset)
           (setq font-latex-match-command-cache-start kbeg
                 font-latex-match-command-cache-end   kend
                 font-latex-match-command-cache-limit (point)
   "Cache end of unterminated match to fontify")
 (defvar font-latex-match-font-cache-limit nil
   "Cache limit of unterminated match to fontify")
+(defvar font-latex-match-font-cache-match nil
+  "Cache last match of unterminated match")
+(defvar font-latex-match-font-cache-stop nil
+  "Flag to not move point, because same pattern was returned twice to fontify")
 (make-variable-buffer-local 'font-latex-match-font-cache-start)
 (make-variable-buffer-local 'font-latex-match-font-cache-end)
 (make-variable-buffer-local 'font-latex-match-font-cache-limit)
+(make-variable-buffer-local 'font-latex-match-font-cache-match)
+(make-variable-buffer-local 'font-latex-match-font-cache-stop)
 
 (defun font-latex-match-font-outside-braces (limit)
   "Search for font-changing command like \textbf{fubar} before LIMIT.  
  subexpression 2 is the content to fontify in bold.
  subexpression 3 is the content to fontify in type-face.
 Returns nil if no font-changing command is found."
-  (when (and font-latex-match-font-cache-limit
+  (when (and font-latex-do-multi-line
+             font-latex-match-font-cache-limit
              font-latex-match-font-cache-start
              font-latex-match-font-cache-end
              (not (= font-latex-match-font-cache-end (point)))
-             (> font-latex-match-font-cache-limit (point))
-             (< font-latex-match-font-cache-start (point)))
+             (>= font-latex-match-font-cache-limit (point))
+             (< font-latex-match-font-cache-start (point))
+	     (not font-latex-match-font-cache-stop)
+             (font-latex-not-on-same-line-as 
+              font-latex-match-font-cache-start))
     (goto-char font-latex-match-font-cache-start))
+  (setq font-latex-match-font-cache-stop nil)
   (when (re-search-forward
          (eval-when-compile
            (concat "\\\\" "\\("
               ((match-beginning 6)
                (setq ttbeg beg  ttend end))
               (t
+
                (setq bfbeg beg  bfend end)))
         (store-match-data 
          (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
         ;; Start the subsequent search immediately after this keyword.
         (goto-char kend)
+
+	(when ;Sanity check!
+	    (equal font-latex-match-font-cache-match
+		   (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
+	  (setq font-latex-match-font-cache-stop t))
+        (setq font-latex-match-font-cache-match
+              (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
         t)))))
 
 (defvar font-latex-match-infont-cache-start nil
 (defvar font-latex-match-infont-cache-end nil
   "Cache end of unterminated match to fontify")
 (defvar font-latex-match-infont-cache-limit nil
-  "Cache end of unterminated match to fontify")
+  "Cache limit of unterminated match to fontify")
+(defvar font-latex-match-infont-cache-match nil
+  "Cache last match of unterminated match")
+(defvar font-latex-match-infont-cache-stop nil
+  "Flag to not move point, because same pattern was returned twice to fontify")
 (make-variable-buffer-local 'font-latex-match-infont-cache-start)
 (make-variable-buffer-local 'font-latex-match-infont-cache-end)
 (make-variable-buffer-local 'font-latex-match-infont-cache-limit)
+(make-variable-buffer-local 'font-latex-match-infont-cache-match)
+(make-variable-buffer-local 'font-latex-match-infont-cache-stop)
 
 (defun font-latex-match-font-inside-braces (limit)
   "Search for font-changing command like {\bf fubar} before LIMIT.  
  subexpression 2 is the content to fontify in bold.
  subexpression 3 is the content to fontify in type-face.
 Returns nil if no font-changing command is found."
-  (when (and font-latex-match-infont-cache-limit
-             font-latex-match-infont-cache-start
-             font-latex-match-infont-cache-end
-             (not (= font-latex-match-infont-cache-end (point)))
-             (> font-latex-match-infont-cache-limit (point))
-             (<  font-latex-match-infont-cache-start (point)))
-    (goto-char font-latex-match-infont-cache-start))
-  (when (re-search-forward
-         (eval-when-compile
-           (concat "\\\\" "\\("
+  ;; Infinite loop without this configuration.
+  (if font-latex-match-infont-cache-stop
+      (setq font-latex-match-infont-cache-stop nil) ;Stop now!
+    (when (and font-latex-do-multi-line
+               font-latex-match-infont-cache-limit
+               (>= font-latex-match-infont-cache-limit (point))
+               (<  font-latex-match-infont-cache-start (point))
+               (font-latex-not-on-same-line-as 
+                font-latex-match-infont-cache-start))
+      (goto-char font-latex-match-infont-cache-start))
+    (setq font-latex-match-infont-cache-stop nil)
+    (when (re-search-forward
+           (eval-when-compile
+             (concat "\\\\" "\\("
                                                               ;;; 2 - italic
-                   "\\(em\\|it\\(shape\\)?\\|sl\\(shape\\)?\\)\\|"
+                     "\\(em\\|it\\(shape\\)?\\|sl\\(shape\\)?\\)\\|"
 	                                                      ;;; 5 - bold
-                   "\\(bf\\(series\\)?\\|upshape\\|sc\\(shape\\)?\\)\\|"
-                   "mdseries\\|tt\\(family\\)?\\|"
-                   "sf\\(family\\)?\\|rm\\(family\\)?\\|"
-                   "tiny\\|scriptsize\\|footnotesize\\|"
-                   "small\\|normalsize\\|large\\|Large\\|LARGE\\|huge\\|Huge"
-                   "\\)\\>[ \t]*"))
-         limit t)
-    (cond
-     ((font-latex-commented-outp)
-      ;; Return a nul match such that we skip over this pattern.
-      ;; (Would be better to skip over internally to this function)
-      ;; Using `prepend' won't help here, because the problem is that
-      ;; scan-sexp *fails* to find a commented-out matching bracket!
-      (store-match-data (list nil nil))
-      t)
-     (t
-      (let ((kbeg (match-beginning 0)) (kend (match-end 1)) 
-            (beg  (match-end 0))
-            end itbeg itend bfbeg bfend ttbeg ttend
-            (parse-sexp-ignore-comments t)) ; scan-sexps ignores comments
-        (goto-char kbeg)
-        (cond 
-         ((not (eq (preceding-char) ?\{))
-          ;; Fontify only the keyword as bf/it/type (no argument found).
-          (cond ((match-beginning 2) (setq itbeg kbeg itend kend))
-                ((match-beginning 5) (setq bfbeg kbeg bfend kend))
-                (t                   (setq ttbeg kbeg ttend kend)))
-          (goto-char (match-end 0))
-          (store-match-data 
-           (list nil nil itbeg itend bfbeg bfend ttbeg ttend))
-          t)
-         (t
-          ;; There's an opening bracket
-          (save-restriction
-            ;; Restrict to LIMIT.
-            (narrow-to-region (point-min) limit)
-            (forward-char -1)           ;Move on the opening bracket
-            (cond 
-             ((condition-case nil
-                  (goto-char (or (scan-sexps (point) 1) (point-max)))
-                (error))
-              (setq end (point)))
-             (t                         ;error!
-              (setq end (point-max))
-              (goto-char end)
-              (setq font-latex-match-infont-cache-start kbeg
-                    font-latex-match-infont-cache-end   kend
-                    font-latex-match-infont-cache-limit (point))))
-            (cond ((match-beginning 2) (setq itbeg beg  itend end))
-                  ((match-beginning 5) (setq bfbeg beg  bfend end))
-                  (t                   (setq ttbeg beg  ttend end)))
+                     "\\(bf\\(series\\)?\\|upshape\\|sc\\(shape\\)?\\)\\|"
+                     "mdseries\\|tt\\(family\\)?\\|"
+                     "sf\\(family\\)?\\|rm\\(family\\)?\\|"
+                     "tiny\\|scriptsize\\|footnotesize\\|"
+                     "small\\|normalsize\\|large\\|Large\\|LARGE\\|huge\\|Huge"
+                     "\\)\\>[ \t]*"))
+           limit t)
+      (cond
+       ((font-latex-commented-outp)
+        ;; Return a nul match such that we skip over this pattern.
+        ;; (Would be better to skip over internally to this function)
+        ;; Using `prepend' won't help here, because the problem is that
+        ;; scan-sexp *fails* to find a commented-out matching bracket!
+        (store-match-data (list nil nil))
+        t)
+       (t
+        (let ((kbeg (match-beginning 0)) (kend (match-end 1)) 
+              (beg  (match-end 0))
+              end itbeg itend bfbeg bfend ttbeg ttend
+              (parse-sexp-ignore-comments t)) ; scan-sexps ignores comments
+          (goto-char kbeg)
+          (cond
+           ((not (eq (preceding-char) ?\{))
+            ;; Fontify only the keyword as bf/it/type (no argument found).
+            (cond ((match-beginning 2) (setq itbeg kbeg itend kend))
+                  ((match-beginning 5) (setq bfbeg kbeg bfend kend))
+                  (t                   (setq ttbeg kbeg ttend kend)))
+            (goto-char (match-end 0))
             (store-match-data 
-             (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
-            ;; Start the subsequent search immediately after this keyword.
-            (goto-char kend)
-            t))))))))
+             (list nil nil itbeg itend bfbeg bfend ttbeg ttend))
+            t)
+           (t
+            ;; There's an opening bracket
+            (save-restriction
+              ;; Restrict to LIMIT.
+              (narrow-to-region (point-min) limit)
+              (forward-char -1)           ;Move on the opening bracket
+              (cond 
+               ((condition-case nil
+                    (goto-char (or (scan-sexps (point) 1) (point-max)))
+                  (error))
+                (setq end (1- (point))))
+               (t                       ;error!
+                (setq end (point-max))
+                (goto-char end)
+                (setq font-latex-match-infont-cache-start kbeg
+                      font-latex-match-infont-cache-end   kend
+                      font-latex-match-infont-cache-limit (point))))
+              (cond ((match-beginning 2) (setq itbeg beg  itend end))
+                    ((match-beginning 5) (setq bfbeg beg  bfend end))
+                    (t                   (setq ttbeg beg  ttend end)))
+              (store-match-data 
+               (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
+
+              ;; XEmacs appears to move point after the fartest match.
+              ;; Emacs lets me move point within the match, usually after the
+              ;; first keyword.
+              (when ;Sanity check!
+                  (equal font-latex-match-infont-cache-match
+                         (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
+                (setq font-latex-match-infont-cache-stop t))
+              (setq font-latex-match-infont-cache-match
+                    (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
+              
+              ;; Start the subsequent search immediately after this keyword.
+              (goto-char kend)
+              t)))))))))
+
+(defun font-latex-not-on-same-line-as (cache-start)
+  "Return t if point is not on same line as CACHE-START."
+  (save-excursion
+    (not (= (progn (beginning-of-line)(point))
+            (progn (goto-char cache-start) (beginning-of-line)(point))))))
 
 ;;; FIXME: Add caches for math-env, math-envII and quotations.
 (defun font-latex-match-math-env (limit)