Subject: [PATCH] Prevent hide-show mode from getting confused by braces in comments

From: Dima Kogan <[email-masked]>
Date: Sun, 13 Feb 2011 23:02:57 -0800

Emacs bug #700 (http://debbugs.gnu.org/cgi/bugreport.cgi?bug=700)
contained a patch by Dmitry Bolshakov addressing 2 issues in hide-show
minor mode. The fix to one of the issues got integrated into the code
base, but the other one fell through the cracks, I think. The issue it
fixes is to prevent hide-show mode from parsing braces inside comments.
These braces can confuse the parser, since they don't necessarily match
up.

I'm attaching Dmitry's test case that demonstrates the issue, and his patch to
fix it.

dima

--- hideshow.el.original_emacs_22.2	2008-01-10 12:15:42.000000000 -0800
+++ hideshow_my.el	2008-08-12 15:39:12.000000000 -0700
@@ -541,7 +541,10 @@
              (q
               ;; `q' is the point at the end of the block
               (progn (hs-forward-sexp mdata 1)
-                     (end-of-line)
+					 ;; see http://www.emacswiki.org/cgi-bin/wiki/HideShow and search page for "hs-block-includes-last-line"
+					 ;(forward-line -1)
+                     ;(end-of-line)
+					 (backward-char 1) ; better
                      (point)))
              ov)
         (when (and (< p (point)) (> (count-lines p q) 1))
@@ -672,10 +675,13 @@
            (forward-comment (buffer-size))
            (and (< (point) maxp)
                 (re-search-forward hs-block-start-regexp maxp t)))
-    (if (> arg 1)
-        (hs-hide-level-recursive (1- arg) minp maxp)
-      (goto-char (match-beginning hs-block-start-mdata-select))
-      (hs-hide-block-at-point t)))
+	(when (not (nth 4 (syntax-ppss))) ; not inside comments
+	  (if (> arg 1)
+		  (hs-hide-level-recursive (1- arg) minp maxp)
+		(goto-char (match-beginning hs-block-start-mdata-select))
+		(hs-hide-block-at-point t))
+	  )
+	)
   (goto-char maxp))
 
 (defmacro hs-life-goes-on (&rest body)