Skip to content

Commit 0a2a3b0

Browse files
committed
Fix Emacs-lockup during fontification.
Fixes non-exiting loop in detection of square-parentasis regions. Closes #17.
1 parent e4ce203 commit 0a2a3b0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

csharp-mode.el

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,20 @@ comment at the start of cc-engine.el for more info."
539539
rtn))
540540

541541

542+
(defun csharp-is-square-parentasis-block-p ()
543+
"Attempts to safely assess if the current point is at the opening of
544+
a square parentasis block [ ... ]."
545+
(let* ((start (point)) ;; variables used to hold our position, so that we know that
546+
(end)) ;; our code isn't stuck trying to look for a non-existant sexp.
547+
(and (eq (char-after) 91) ;; open square
548+
(while (and (eq (char-after) 91)
549+
(not (eq start end)))
550+
(c-safe (c-forward-sexp 1))
551+
(setq end (point)))
552+
(eq (char-before) 93))) ;; close square
553+
)
554+
555+
542556

543557
;; ==================================================================
544558
;; end of csharp-mode utility and feature defuns
@@ -942,10 +956,7 @@ comment at the start of cc-engine.el for more info."
942956

943957
(if (or
944958
(eq (char-after) ?{) ;; open curly
945-
(and (eq (char-after) 91) ;; open square
946-
(while (eq (char-after) 91)
947-
(c-safe (c-forward-sexp 1)))
948-
(eq (char-before) 93)) ;; close square
959+
(csharp-is-square-parentasis-block-p)
949960
(and (eq (char-after) 40) ;; open paren
950961
(c-safe (c-forward-sexp 1) t)))
951962

0 commit comments

Comments
 (0)