;;; hideshow.el --- minor mode cmds to selectively display code/comment blocks
-;; Copyright (C) 1994-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1994-2012 Free Software Foundation, Inc.
;; Author: Thien-Thi Nguyen <ttn@gnu.org>
;; Dan Nicolaescu <dann@ics.uci.edu>
;; Unfortunately, these workarounds do not restore hideshow state.
;; If someone figures out a better way, please let me know.
-;; * Correspondance
+;; * Correspondence
;;
-;; Correspondance welcome; please indicate version number. Send bug
+;; Correspondence welcome; please indicate version number. Send bug
;; reports and inquiries to <ttn@gnu.org>.
;; * Thanks
(overlay-put ov 'display nil))))
(overlay-put ov 'invisible (and hide-p 'hs)))
+(defun hs-looking-at-block-start-p ()
+ "Return non-nil if the point is at the block start."
+ (and (looking-at hs-block-start-regexp)
+ (save-match-data (not (nth 8 (syntax-ppss))))))
+
(defun hs-forward-sexp (match-data arg)
"Adjust point based on MATCH-DATA and call `hs-forward-sexp-func' w/ ARG.
Original match data is restored upon return."
and then further adjusted to be at the end of the line."
(if comment-reg
(hs-hide-comment-region (car comment-reg) (cadr comment-reg) end)
- (when (looking-at hs-block-start-regexp)
- (let* ((mdata (match-data t))
- (header-beg (match-beginning 0))
- (header-end (match-end 0))
- p q ov)
+ (when (hs-looking-at-block-start-p)
+ (let ((mdata (match-data t))
+ (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
(let ((done nil)
(here (point)))
;; look if current line is block start
- (if (looking-at hs-block-start-regexp)
+ (if (hs-looking-at-block-start-p)
(point)
;; look backward for the start of a block that contains the cursor
(while (and (re-search-backward hs-block-start-regexp nil t)
- (save-match-data
- (not (nth 4 (syntax-ppss)))) ; not inside comments
- (not (setq done
- (< here (save-excursion
- (hs-forward-sexp (match-data t) 1)
- (point)))))))
+ ;; go again if in a comment or a string
+ (or (save-match-data (nth 8 (syntax-ppss)))
+ (not (setq done
+ (< here (save-excursion
+ (hs-forward-sexp (match-data t) 1)
+ (point))))))))
(if done
(point)
(goto-char here)
(and (< (point) maxp)
(re-search-forward hs-block-start-regexp maxp t)))
(when (save-match-data
- (not (nth 4 (syntax-ppss)))) ; not inside comments
+ (not (nth 8 (syntax-ppss)))) ; not inside comments or strings
(if (> arg 1)
(hs-hide-level-recursive (1- arg) minp maxp)
(goto-char (match-beginning hs-block-start-mdata-select))
(end-of-line)
(when (and (not c-reg)
(hs-find-block-beginning)
- (looking-at hs-block-start-regexp))
+ (hs-looking-at-block-start-p))
;; point is inside a block
(goto-char (match-end 0)))))
(end-of-line)
(<= (count-lines (car c-reg) (nth 1 c-reg)) 1)))
(message "(not enough comment lines to hide)"))
((or c-reg
- (looking-at hs-block-start-regexp)
+ (hs-looking-at-block-start-p)
(hs-find-block-beginning))
(hs-hide-block-at-point end c-reg)
(run-hooks 'hs-hide-hook))))))
q (cadr c-reg))))
((and (hs-find-block-beginning)
;; ugh, fresh match-data
- (looking-at hs-block-start-regexp))
+ (hs-looking-at-block-start-p))
(setq p (point)
q (progn (hs-forward-sexp (match-data t) 1) (point)))))
(when (and p q)