;;; hideshow.el --- minor mode cmds to selectively display code/comment blocks
;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
;; Author: Thien-Thi Nguyen <ttn@gnu.org>
;; Dan Nicolaescu <dann@ics.uci.edu>
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;;###autoload
(defvar hs-special-modes-alist
- '((c-mode "{" "}" "/[*/]" nil hs-c-like-adjust-block-beginning)
- (c++-mode "{" "}" "/[*/]" nil hs-c-like-adjust-block-beginning)
+ (mapcar 'purecopy
+ '((c-mode "{" "}" "/[*/]" nil nil)
+ (c++-mode "{" "}" "/[*/]" nil nil)
(bibtex-mode ("@\\S(*\\(\\s(\\)" 1))
- (java-mode "{" "}" "/[*/]" nil hs-c-like-adjust-block-beginning))
+ (java-mode "{" "}" "/[*/]" nil nil)
+ (js-mode "{" "}" "/[*/]" nil)))
"*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).
(defvar hs-allow-nesting nil
"*If non-nil, hiding remembers internal blocks.
-This means that when the outer block is shown again, any
-previously hidden internal blocks remain hidden.")
+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.
(defvar hs-show-hook nil
"*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'..")
+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.
["Toggle Hiding" hs-toggle-hiding
:help "Toggle the hiding state of the current block"]
"----"
- ["Hide comments when hiding all"
+ ["Hide comments when hiding all"
(setq hs-hide-comments-when-hiding-all
(not hs-hide-comments-when-hiding-all))
:help "If t also hide comment blocks when doing `hs-hide-all'"
(hs-hide-comment-region (car comment-reg) (cadr comment-reg) end)
(when (looking-at hs-block-start-regexp)
(let* ((mdata (match-data t))
- (pure-p (match-end 0))
- (p
- ;; `p' is the point at the end of the block beginning,
- ;; which may need to be adjusted
- (save-excursion
- (goto-char (funcall (or hs-adjust-block-beginning
- 'identity)
- pure-p))
- ;; whatever the adjustment, we move to eol
- (line-end-position)))
- (q
- ;; `q' is the point at the end of the block
- (progn (hs-forward-sexp mdata 1)
- (end-of-line)
- (point)))
- ov)
- (when (and (< p (point)) (> (count-lines p q) 1))
+ (header-beg (match-beginning 0))
+ (header-end (match-end 0))
+ p q ov)
+ ;; `p' is the point at the end of the block beginning, which
+ ;; may need to be adjusted
+ (save-excursion
+ (if hs-adjust-block-beginning
+ (goto-char (funcall hs-adjust-block-beginning
+ header-end))
+ (goto-char header-end))
+ (setq p (line-end-position)))
+ ;; `q' is the point at the end of the block
+ (hs-forward-sexp mdata 1)
+ (setq q (if (looking-back hs-block-end-regexp)
+ (match-beginning 0)
+ (point)))
+ (when (and (< p q) (> (count-lines p q) 1))
(cond ((and hs-allow-nesting (setq ov (hs-overlay-at p)))
(delete-overlay ov))
((not hs-allow-nesting)
(hs-discard-overlays p q)))
- (hs-make-overlay p q 'code (- pure-p p)))
- (goto-char (if end q (min p pure-p)))))))
+ (hs-make-overlay p q 'code (- header-end p)))
+ (goto-char (if end q (min p header-end)))))))
(defun hs-inside-comment-p ()
"Return non-nil if point is inside a comment, otherwise nil.
(end-of-line)
(hs-overlay-at (point))))
+;; This function is not used anymore (Bug#700).
(defun hs-c-like-adjust-block-beginning (initial)
"Adjust INITIAL, the buffer position after `hs-block-start-regexp'.
Actually, point is never moved; a new position is returned that is
q (progn (hs-forward-sexp (match-data t) 1) (point)))))
(when (and p q)
(hs-discard-overlays p q)
- (goto-char (if end q (1+ p)))))
- (run-hooks 'hs-show-hook))))
+ (goto-char (if end q (1+ p))))))
+ (run-hooks 'hs-show-hook)))
(defun hs-hide-level (arg)
"Hide all blocks ARG levels below this block.
;;;###autoload
(define-minor-mode hs-minor-mode
- "Minor mode to selectively hide/show code and comment blocks.
+ "Minor mode to selectively hide/show code and comment blocks.
When hideshow minor mode is on, the menu bar is augmented with hideshow
commands and the hideshow commands are enabled.
The value '(hs . t) is added to `buffer-invisibility-spec'.
Key bindings:
\\{hs-minor-mode-map}"
- :group 'hideshow
+ :group 'hideshow
:lighter " hs"
:keymap hs-minor-mode-map
(setq hs-headline nil)