]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/hideshow.el
Merge branch 'emacs-24'
[gnu-emacs] / lisp / progmodes / hideshow.el
index 8463648e679c4c56f908eddffe3baa5d98298154..a016c3283ebe9a0d1a61876569da741dd9353bd0 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-2014 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
   :group 'languages)
 
 (defcustom hs-hide-comments-when-hiding-all t
-  "*Hide the comments too when you do an `hs-hide-all'."
+  "Hide the comments too when you do an `hs-hide-all'."
   :type 'boolean
   :group 'hideshow)
 
 (defcustom hs-minor-mode-hook nil
-  "*Hook called when hideshow minor mode is activated or deactivated."
+  "Hook called when hideshow minor mode is activated or deactivated."
   :type 'hook
   :group 'hideshow
   :version "21.1")
 
 (defcustom hs-isearch-open 'code
-  "*What kind of hidden blocks to open when doing `isearch'.
+  "What kind of hidden blocks to open when doing `isearch'.
 One of the following symbols:
 
   code    -- open only code blocks
@@ -272,7 +272,7 @@ This has effect only if `search-invisible' is set to `open'."
     (bibtex-mode ("@\\S(*\\(\\s(\\)" 1))
     (java-mode "{" "}" "/[*/]" nil nil)
     (js-mode "{" "}" "/[*/]" nil)))
-  "*Alist for initializing the hideshow variables for different modes.
+  "Alist for initializing the hideshow variables for different modes.
 Each element has the form
   (MODE START END COMMENT-START FORWARD-SEXP-FUNC ADJUST-BEG-FUNC).
 
@@ -300,25 +300,25 @@ appropriate values.  The regexps should not contain leading or trailing
 whitespace.  Case does not matter.")
 
 (defvar hs-hide-all-non-comment-function nil
-  "*Function called if non-nil when doing `hs-hide-all' for non-comments.")
+  "Function called if non-nil when doing `hs-hide-all' for non-comments.")
 
 (defvar hs-allow-nesting nil
-  "*If non-nil, hiding remembers internal blocks.
+  "If non-nil, hiding remembers internal blocks.
 This means that when the outer block is shown again,
 any previously hidden internal blocks remain hidden.")
 
 (defvar hs-hide-hook nil
-  "*Hook called (with `run-hooks') at the end of commands to hide text.
+  "Hook called (with `run-hooks') at the end of commands to hide text.
 These commands include the toggling commands (when the result is to hide
 a block), `hs-hide-all', `hs-hide-block' and `hs-hide-level'.")
 
 (defvar hs-show-hook nil
-  "*Hook called (with `run-hooks') at the end of commands to show text.
+  "Hook called (with `run-hooks') at the end of commands to show text.
 These commands include the toggling commands (when the result is to show
 a block), `hs-show-all' and `hs-show-block'.")
 
 (defvar hs-set-up-overlay nil
-  "*Function called with one arg, OV, a newly initialized overlay.
+  "Function called with one arg, OV, a newly initialized overlay.
 Hideshow puts a unique overlay on each range of text to be hidden
 in the buffer.  Here is a simple example of how to use this variable:
 
@@ -390,37 +390,31 @@ Use the command `hs-minor-mode' to toggle or set this variable.")
       :help "Do not hidden code or comment blocks when isearch matches inside them"
       :active t :style radio :selected (eq hs-isearch-open nil)])))
 
-(defvar hs-c-start-regexp nil
+(defvar-local hs-c-start-regexp nil
   "Regexp for beginning of comments.
 Differs from mode-specific comment regexps in that
 surrounding whitespace is stripped.")
-(make-variable-buffer-local 'hs-c-start-regexp)
 
-(defvar hs-block-start-regexp nil
+(defvar-local hs-block-start-regexp nil
   "Regexp for beginning of block.")
-(make-variable-buffer-local 'hs-block-start-regexp)
 
-(defvar hs-block-start-mdata-select nil
+(defvar-local hs-block-start-mdata-select nil
   "Element in `hs-block-start-regexp' match data to consider as block start.
 The internal function `hs-forward-sexp' moves point to the beginning of this
 element (using `match-beginning') before calling `hs-forward-sexp-func'.")
-(make-variable-buffer-local 'hs-block-start-mdata-select)
 
-(defvar hs-block-end-regexp nil
+(defvar-local 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
+(defvar-local hs-forward-sexp-func 'forward-sexp
   "Function used to do a `forward-sexp'.
 Should change for Algol-ish modes.  For single-character block
 delimiters -- ie, the syntax table regexp for the character is
 either `(' or `)' -- `hs-forward-sexp-func' would just be
 `forward-sexp'.  For other modes such as simula, a more specialized
 function is necessary.")
-(make-variable-buffer-local 'hs-forward-sexp-func)
 
-(defvar hs-adjust-block-beginning nil
+(defvar-local hs-adjust-block-beginning nil
   "Function used to tweak the block beginning.
 The block is hidden from the position returned by this function,
 as opposed to hiding it from the position returned when searching
@@ -439,7 +433,6 @@ It should return the position from where we should start hiding.
 It should not move the point.
 
 See `hs-c-like-adjust-block-beginning' for an example of using this.")
-(make-variable-buffer-local 'hs-adjust-block-beginning)
 
 (defvar hs-headline nil
   "Text of the line where a hidden block begins, set during isearch.
@@ -789,6 +782,7 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
      (unless hs-allow-nesting
        (hs-discard-overlays (point-min) (point-max)))
      (goto-char (point-min))
+     (syntax-propertize (point-max))
      (let ((spew (make-progress-reporter "Hiding all blocks..."
                                          (point-min) (point-max)))
            (re (concat "\\("
@@ -804,12 +798,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))