]> code.delx.au - gnu-emacs/blobdiff - lisp/mouse.el
Make double-click-1 work with unbalanced parens in CC Mode. Fixes bug#5560.
[gnu-emacs] / lisp / mouse.el
index 85ffc43d0dc18e304ac371a7f47b01055b5654fc..fa355ffeb71e605f7577d2f1a7b865d17ef0892a 100644 (file)
@@ -931,20 +931,29 @@ If MODE is 2 then do the same for lines."
               (= start end)
              (char-after start)
               (= (char-syntax (char-after start)) ?\())
-        (list start
-              (save-excursion
-                (goto-char start)
-                (forward-sexp 1)
-                (point))))
+         (if (/= (syntax-class (syntax-after start)) 4) ; raw syntax code for ?\(
+             ;; This happens in CC Mode when unbalanced parens in CPP
+             ;; constructs are given punctuation syntax with
+             ;; syntax-table text properties.  (2016-02-21).
+             (signal 'scan-error (list "Containing expression ends prematurely"
+                                       start start))
+           (list start
+                 (save-excursion
+                   (goto-char start)
+                   (forward-sexp 1)
+                   (point)))))
         ((and (= mode 1)
               (= start end)
              (char-after start)
               (= (char-syntax (char-after start)) ?\)))
-        (list (save-excursion
-                (goto-char (1+ start))
-                (backward-sexp 1)
-                (point))
-              (1+ start)))
+         (if (/= (syntax-class (syntax-after start)) 5) ; raw syntax code for ?\)
+             ;; See above comment about CC Mode.
+             (signal 'scan-error (list "Unbalanced parentheses" start start))
+           (list (save-excursion
+                   (goto-char (1+ start))
+                   (backward-sexp 1)
+                   (point))
+                 (1+ start))))
        ((and (= mode 1)
               (= start end)
              (char-after start)