emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 ad68bbd: Fix another "wrong side of point" error


From: Alan Mackenzie
Subject: [Emacs-diffs] emacs-26 ad68bbd: Fix another "wrong side of point" error in CC Mode.
Date: Thu, 26 Oct 2017 14:38:02 -0400 (EDT)

branch: emacs-26
commit ad68bbd0da4ed90117f09dc2344c0c3d9d728851
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Fix another "wrong side of point" error in CC Mode.
    
    This fixes (a follow-up to) bug #28850.
    A internal generated form for scanning text to fontify had a LIMIT 
parameter.
    It also locally bound LIMIT to a value possibly beyond the original LIMIT,
    allowing point to move beyond the original LIMIT, and to create the wrong 
side
    error.  Fix it by checking point is not beyond LIMIT in the outer context
    before using it.
    
    * lisp/progmodes/cc-fonts.el (c-make-font-lock-search-form): Add a new
    parameter CHECK-POINT which, when non-nil, directs the function to generate 
a
    check on point.
    (c-make-font-lock-context-search-function): Invoke the above function with 
new
    argument value t.
---
 lisp/progmodes/cc-fonts.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index a2ac2a3..d352e5b 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -292,12 +292,17 @@
                              nil)))))
          res))))
 
-  (defun c-make-font-lock-search-form (regexp highlights)
+  (defun c-make-font-lock-search-form (regexp highlights &optional check-point)
     ;; Return a lisp form which will fontify every occurrence of REGEXP
     ;; (a regular expression, NOT a function) between POINT and `limit'
     ;; with HIGHLIGHTS, a list of highlighters as specified on page
-    ;; "Search-based Fontification" in the elisp manual.
-    `(while (re-search-forward ,regexp limit t)
+    ;; "Search-based Fontification" in the elisp manual.  If CHECK-POINT
+    ;; is non-nil, we will check (< (point) limit) in the main loop.
+    `(while
+        ,(if check-point
+             `(and (< (point) limit)
+                   (re-search-forward ,regexp limit t))
+           `(re-search-forward ,regexp limit t))
        (unless (progn
                 (goto-char (match-beginning 0))
                 (c-skip-comments-and-strings limit))
@@ -476,7 +481,9 @@
                        ,(c-make-font-lock-search-form
                          regexp highlights)))))
             state-stanzas)
-         ,(c-make-font-lock-search-form (car normal) (cdr normal))
+         ;; In the next form, check that point hasn't been moved beyond
+         ;; `limit' in any of the above stanzas.
+         ,(c-make-font-lock-search-form (car normal) (cdr normal) t)
          nil))))
 
 ;  (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]