Merge from emacs-24; up to 2012-12-31T11:35:13Z!rudalics@gmx.at
[bpt/emacs.git] / lisp / progmodes / hideshow.el
index e2016e2..fc753bf 100644 (file)
@@ -1,6 +1,6 @@
-;;; hideshow.el --- minor mode cmds to selectively display code/comment blocks
+;;; hideshow.el --- minor mode cmds to selectively display code/comment blocks -*- coding: utf-8 -*-
 
-;; Copyright (C) 1994-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1994-2013 Free Software Foundation, Inc.
 
 ;; Author: Thien-Thi Nguyen <ttn@gnu.org>
 ;;      Dan Nicolaescu <dann@ics.uci.edu>
@@ -52,7 +52,7 @@
 ;;
 ;; First make sure hideshow.el is in a directory in your `load-path'.
 ;; You can optionally byte-compile it using `M-x byte-compile-file'.
-;; Then, add the following to your ~/.emacs:
+;; Then, add the following to your init file:
 ;;
 ;; (load-library "hideshow")
 ;; (add-hook 'X-mode-hook               ; other modes similarly
 ;;  Dean Andrews, Alf-Ivar Holm, Holger Bauer, Christoph Conrad, Dave Love,
 ;;  Dirk Herrmann, Gael Marziou, Jan Djarv, Guillaume Leray, Moody Ahmad,
 ;;  Preston F. Crow, Lars Lindberg, Reto Zimmermann, Keith Sheffield,
-;;  Chew Meng Kuan, Tony Lam, Pete Ware, François Pinard, Stefan Monnier,
+;;  Chew Meng Kuan, Tony Lam, Pete Ware, François Pinard, Stefan Monnier,
 ;;  Joseph Eydelnant, Michael Ernst, Peter Heslin
 ;;
 ;; Special thanks go to Dan Nicolaescu, who reimplemented hideshow using
@@ -408,6 +408,8 @@ element (using `match-beginning') before calling `hs-forward-sexp-func'.")
 
 (defvar hs-block-end-regexp nil
   "Regexp for end of block.")
+(make-variable-buffer-local 'hs-block-end-regexp)
+
 
 (defvar hs-forward-sexp-func 'forward-sexp
   "Function used to do a `forward-sexp'.
@@ -802,12 +804,15 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
                   (forward-comment (point-max)))
                 (re-search-forward re (point-max) t))
          (if (match-beginning 1)
-             ;; we have found a block beginning
+             ;; We have found a block beginning.
              (progn
                (goto-char (match-beginning 1))
-               (if hs-hide-all-non-comment-function
-                   (funcall hs-hide-all-non-comment-function)
-                 (hs-hide-block-at-point t)))
+              (unless (if hs-hide-all-non-comment-function
+                          (funcall hs-hide-all-non-comment-function)
+                        (hs-hide-block-at-point t))
+                ;; Go to end of matched data to prevent from getting stuck
+                ;; with an endless loop.
+                (goto-char (match-end 0))))
            ;; found a comment, probably
            (let ((c-reg (hs-inside-comment-p)))
              (when (and c-reg (car c-reg))