branch: externals/csharp-mode commit 0a2a3b0943c2463ca38b673c6c42d2e3e9bc2d5a Author: Jostein Kjønigsen <jost...@kjonigsen.net> Commit: Jostein Kjønigsen <jost...@kjonigsen.net>
Fix Emacs-lockup during fontification. Fixes non-exiting loop in detection of square-parentasis regions. Closes https://github.com/josteink/csharp-mode/issues/17. --- csharp-mode.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/csharp-mode.el b/csharp-mode.el index 75e3130..e2003e7 100644 --- a/csharp-mode.el +++ b/csharp-mode.el @@ -539,6 +539,20 @@ comment at the start of cc-engine.el for more info." rtn)) +(defun csharp-is-square-parentasis-block-p () + "Attempts to safely assess if the current point is at the opening of +a square parentasis block [ ... ]." + (let* ((start (point)) ;; variables used to hold our position, so that we know that + (end)) ;; our code isn't stuck trying to look for a non-existant sexp. + (and (eq (char-after) 91) ;; open square + (while (and (eq (char-after) 91) + (not (eq start end))) + (c-safe (c-forward-sexp 1)) + (setq end (point))) + (eq (char-before) 93))) ;; close square + ) + + ;; ================================================================== ;; end of csharp-mode utility and feature defuns @@ -942,10 +956,7 @@ comment at the start of cc-engine.el for more info." (if (or (eq (char-after) ?{) ;; open curly - (and (eq (char-after) 91) ;; open square - (while (eq (char-after) 91) - (c-safe (c-forward-sexp 1))) - (eq (char-before) 93)) ;; close square + (csharp-is-square-parentasis-block-p) (and (eq (char-after) 40) ;; open paren (c-safe (c-forward-sexp 1) t)))