Subject: bug#6158: bug in hideshow (trunk)

From: Theodor Rascanu <[email-masked]>
Date: Mon, 10 May 2010 17:32:45 +0200

Hi all,

I guess I have found a the bug in the hideshow package:

Assume the following c++ code:

inline int round_to_next_power2(register unsigned int x){
  //if(x!=32){
  x--;
  x |= (x >> 1);
  x |= (x >> 2);
  x |= (x >> 4);
  x |= (x >> 8);
  x |= (x >> 16);
  return x + 1;
  //}
}

Ok this example do not make much sense programming wise but it shows the
probelm:
Hiding this function will not work.
Having the cursor somewhere inside the function outside the commented lines
and trying to hide it (i.e. by C-c @ C-c) will produce the following:

inline int round_to_next_power2(register unsigned int x){
//if(x!=32){... }

Attached is a patch producing the expected behaviour:
inline int round_to_next_power2(register unsigned int x){... }

Greetings,
Theodor
--- lisp/progmodes/hideshow.el.orig	2010-05-10 13:21:48.555732323 +0200
+++ lisp/progmodes/hideshow.el	2010-05-10 13:21:40.745646130 +0200
@@ -690,10 +690,12 @@ Return point, or nil if original point w
         (point)
       ;; look backward for the start of a block that contains the cursor
       (while (and (re-search-backward hs-block-start-regexp nil t)
-                  (not (setq done
-                             (< here (save-excursion
-                                       (hs-forward-sexp (match-data t) 1)
-                                       (point)))))))
+                  (setq done
+			     (< here (save-excursion
+				       (hs-forward-sexp (match-data t) 1)
+				       (point))))
+		  (hs-inside-comment-p)
+		  (not (setq done nil))))
       (if done
           (point)
         (goto-char here)