aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThien-Thi Nguyen2005-09-14 00:29:50 +0000
committerThien-Thi Nguyen2005-09-14 00:29:50 +0000
commita5b101dc44c7039d43efeef32995a0a56e31e003 (patch)
treebe9f91707768b8dececb88570438aac9c83c4dff
parent2bbf184223d79952d8da0a8586a5848fd8d9ec05 (diff)
downloademacs-a5b101dc44c7039d43efeef32995a0a56e31e003.tar.gz
emacs-a5b101dc44c7039d43efeef32995a0a56e31e003.zip
(hs-hide-comments-when-hiding-all): Remove autoload cookie.
(hs-allow-nesting): New user var. (hs-discard-overlays): Skip "internal" overlays if nesting allowed. (hs-hide-block-at-point): When nesting allowed, if there is already an overlay in place, delete it. (hs-safety-is-job-n): Delete func; remove call sites. (hs-hide-level-recursive): Don't pre-clean if nesting allowed. (hs-overlay-at): New func. (hs-already-hidden-p, hs-show-block): Use it. (hs-hide-all): Don't pre-clean if nesting allowed. (hs-show-all): Temporarily disallow nesting around call to `hs-discard-overlays'.
-rw-r--r--lisp/ChangeLog16
-rw-r--r--lisp/progmodes/hideshow.el90
2 files changed, 65 insertions, 41 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 94f9f4cf37e..b53df64a0be 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12005-09-14 Thien-Thi Nguyen <ttn@gnu.org>
2
3 * progmodes/hideshow.el
4 (hs-hide-comments-when-hiding-all): Remove autoload cookie.
5 (hs-allow-nesting): New user var.
6 (hs-discard-overlays): Skip "internal" overlays if nesting allowed.
7 (hs-hide-block-at-point): When nesting allowed,
8 if there is already an overlay in place, delete it.
9 (hs-safety-is-job-n): Delete func; remove call sites.
10 (hs-hide-level-recursive): Don't pre-clean if nesting allowed.
11 (hs-overlay-at): New func.
12 (hs-already-hidden-p, hs-show-block): Use it.
13 (hs-hide-all): Don't pre-clean if nesting allowed.
14 (hs-show-all): Temporarily disallow
15 nesting around call to `hs-discard-overlays'.
16
12005-09-14 Chong Yidong <cyd@stupidchicken.com> 172005-09-14 Chong Yidong <cyd@stupidchicken.com>
2 18
3 * mouse.el (mouse-major-mode-menu): Make `prefix' optional. 19 * mouse.el (mouse-major-mode-menu): Make `prefix' optional.
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el
index ac62fd00f30..ddc0e277200 100644
--- a/lisp/progmodes/hideshow.el
+++ b/lisp/progmodes/hideshow.el
@@ -6,7 +6,7 @@
6;; Author: Thien-Thi Nguyen <ttn@gnu.org> 6;; Author: Thien-Thi Nguyen <ttn@gnu.org>
7;; Dan Nicolaescu <dann@ics.uci.edu> 7;; Dan Nicolaescu <dann@ics.uci.edu>
8;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines 8;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines
9;; Maintainer-Version: 9;; Maintainer-Version: 5.65.2.2
10;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning 10;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning
11 11
12;; This file is part of GNU Emacs. 12;; This file is part of GNU Emacs.
@@ -243,7 +243,6 @@
243 :prefix "hs-" 243 :prefix "hs-"
244 :group 'languages) 244 :group 'languages)
245 245
246;;;###autoload
247(defcustom hs-hide-comments-when-hiding-all t 246(defcustom hs-hide-comments-when-hiding-all t
248 "*Hide the comments too when you do an `hs-hide-all'." 247 "*Hide the comments too when you do an `hs-hide-all'."
249 :type 'boolean 248 :type 'boolean
@@ -307,6 +306,11 @@ whitespace. Case does not matter.")
307(defvar hs-hide-all-non-comment-function nil 306(defvar hs-hide-all-non-comment-function nil
308 "*Function called if non-nil when doing `hs-hide-all' for non-comments.") 307 "*Function called if non-nil when doing `hs-hide-all' for non-comments.")
309 308
309(defvar hs-allow-nesting nil
310 "*If non-nil, hiding remembers internal blocks.
311This means that when the outer block is shown again, any
312previously hidden internal blocks remain hidden.")
313
310(defvar hs-hide-hook nil 314(defvar hs-hide-hook nil
311 "*Hook called (with `run-hooks') at the end of commands to hide text. 315 "*Hook called (with `run-hooks') at the end of commands to hide text.
312These commands include the toggling commands (when the result is to hide 316These commands include the toggling commands (when the result is to hide
@@ -412,12 +416,19 @@ Note that `mode-line-format' is buffer-local.")
412;; support functions 416;; support functions
413 417
414(defun hs-discard-overlays (from to) 418(defun hs-discard-overlays (from to)
415 "Delete hideshow overlays in region defined by FROM and TO." 419 "Delete hideshow overlays in region defined by FROM and TO.
420Skip \"internal\" overlays if `hs-allow-nesting' is non-nil."
416 (when (< to from) 421 (when (< to from)
417 (setq from (prog1 to (setq to from)))) 422 (setq from (prog1 to (setq to from))))
418 (dolist (ov (overlays-in from to)) 423 (if hs-allow-nesting
419 (when (overlay-get ov 'hs) 424 (let (ov)
420 (delete-overlay ov)))) 425 (while (> to (setq from (next-overlay-change from)))
426 (when (setq ov (hs-overlay-at from))
427 (setq from (overlay-end ov))
428 (delete-overlay ov))))
429 (dolist (ov (overlays-in from to))
430 (when (overlay-get ov 'hs)
431 (delete-overlay ov)))))
421 432
422(defun hs-make-overlay (b e kind &optional b-offset e-offset) 433(defun hs-make-overlay (b e kind &optional b-offset e-offset)
423 "Return a new overlay in region defined by B and E with type KIND. 434 "Return a new overlay in region defined by B and E with type KIND.
@@ -532,19 +543,16 @@ and then further adjusted to be at the end of the line."
532 ;; `q' is the point at the end of the block 543 ;; `q' is the point at the end of the block
533 (progn (hs-forward-sexp mdata 1) 544 (progn (hs-forward-sexp mdata 1)
534 (end-of-line) 545 (end-of-line)
535 (point)))) 546 (point)))
547 ov)
536 (when (and (< p (point)) (> (count-lines p q) 1)) 548 (when (and (< p (point)) (> (count-lines p q) 1))
537 (hs-discard-overlays p q) 549 (cond ((and hs-allow-nesting (setq ov (hs-overlay-at p)))
550 (delete-overlay ov))
551 ((not hs-allow-nesting)
552 (hs-discard-overlays p q)))
538 (hs-make-overlay p q 'code (- pure-p p))) 553 (hs-make-overlay p q 'code (- pure-p p)))
539 (goto-char (if end q (min p pure-p))))))) 554 (goto-char (if end q (min p pure-p)))))))
540 555
541(defun hs-safety-is-job-n ()
542 "Warn if `buffer-invisibility-spec' does not contain symbol `hs'."
543 (unless (and (listp buffer-invisibility-spec)
544 (assq 'hs buffer-invisibility-spec))
545 (message "Warning: `buffer-invisibility-spec' does not contain hs!!")
546 (sit-for 2)))
547
548(defun hs-inside-comment-p () 556(defun hs-inside-comment-p ()
549 "Return non-nil if point is inside a comment, otherwise nil. 557 "Return non-nil if point is inside a comment, otherwise nil.
550Actually, return a list containing the buffer position of the start 558Actually, return a list containing the buffer position of the start
@@ -658,7 +666,8 @@ Return point, or nil if original point was not in a block."
658 (setq minp (1+ (point))) 666 (setq minp (1+ (point)))
659 (funcall hs-forward-sexp-func 1) 667 (funcall hs-forward-sexp-func 1)
660 (setq maxp (1- (point)))) 668 (setq maxp (1- (point))))
661 (hs-discard-overlays minp maxp) ; eliminate weirdness 669 (unless hs-allow-nesting
670 (hs-discard-overlays minp maxp))
662 (goto-char minp) 671 (goto-char minp)
663 (while (progn 672 (while (progn
664 (forward-comment (buffer-size)) 673 (forward-comment (buffer-size))
@@ -668,7 +677,6 @@ Return point, or nil if original point was not in a block."
668 (hs-hide-level-recursive (1- arg) minp maxp) 677 (hs-hide-level-recursive (1- arg) minp maxp)
669 (goto-char (match-beginning hs-block-start-mdata-select)) 678 (goto-char (match-beginning hs-block-start-mdata-select))
670 (hs-hide-block-at-point t))) 679 (hs-hide-block-at-point t)))
671 (hs-safety-is-job-n)
672 (goto-char maxp)) 680 (goto-char maxp))
673 681
674(defmacro hs-life-goes-on (&rest body) 682(defmacro hs-life-goes-on (&rest body)
@@ -682,6 +690,15 @@ and `case-fold-search' are both t."
682 690
683(put 'hs-life-goes-on 'edebug-form-spec '(&rest form)) 691(put 'hs-life-goes-on 'edebug-form-spec '(&rest form))
684 692
693(defun hs-overlay-at (position)
694 "Return hideshow overlay at POSITION, or nil if none to be found."
695 (let ((overlays (overlays-at position))
696 ov found)
697 (while (and (not found) (setq ov (car overlays)))
698 (setq found (and (overlay-get ov 'hs) ov)
699 overlays (cdr overlays)))
700 found))
701
685(defun hs-already-hidden-p () 702(defun hs-already-hidden-p ()
686 "Return non-nil if point is in an already-hidden block, otherwise nil." 703 "Return non-nil if point is in an already-hidden block, otherwise nil."
687 (save-excursion 704 (save-excursion
@@ -695,12 +712,7 @@ and `case-fold-search' are both t."
695 ;; point is inside a block 712 ;; point is inside a block
696 (goto-char (match-end 0))))) 713 (goto-char (match-end 0)))))
697 (end-of-line) 714 (end-of-line)
698 (let ((overlays (overlays-at (point))) 715 (hs-overlay-at (point))))
699 (found nil))
700 (while (and (not found) (overlayp (car overlays)))
701 (setq found (overlay-get (car overlays) 'hs)
702 overlays (cdr overlays)))
703 found)))
704 716
705(defun hs-c-like-adjust-block-beginning (initial) 717(defun hs-c-like-adjust-block-beginning (initial)
706 "Adjust INITIAL, the buffer position after `hs-block-start-regexp'. 718 "Adjust INITIAL, the buffer position after `hs-block-start-regexp'.
@@ -724,7 +736,8 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
724 (hs-life-goes-on 736 (hs-life-goes-on
725 (message "Hiding all blocks ...") 737 (message "Hiding all blocks ...")
726 (save-excursion 738 (save-excursion
727 (hs-discard-overlays (point-min) (point-max)) ; eliminate weirdness 739 (unless hs-allow-nesting
740 (hs-discard-overlays (point-min) (point-max)))
728 (goto-char (point-min)) 741 (goto-char (point-min))
729 (let ((count 0) 742 (let ((count 0)
730 (re (concat "\\(" 743 (re (concat "\\("
@@ -752,8 +765,7 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
752 (if (> (count-lines (car c-reg) (nth 1 c-reg)) 1) 765 (if (> (count-lines (car c-reg) (nth 1 c-reg)) 1)
753 (hs-hide-block-at-point t c-reg) 766 (hs-hide-block-at-point t c-reg)
754 (goto-char (nth 1 c-reg)))))) 767 (goto-char (nth 1 c-reg))))))
755 (message "Hiding ... %d" (setq count (1+ count))))) 768 (message "Hiding ... %d" (setq count (1+ count))))))
756 (hs-safety-is-job-n))
757 (beginning-of-line) 769 (beginning-of-line)
758 (message "Hiding all blocks ... done") 770 (message "Hiding all blocks ... done")
759 (run-hooks 'hs-hide-hook))) 771 (run-hooks 'hs-hide-hook)))
@@ -763,7 +775,8 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
763 (interactive) 775 (interactive)
764 (hs-life-goes-on 776 (hs-life-goes-on
765 (message "Showing all blocks ...") 777 (message "Showing all blocks ...")
766 (hs-discard-overlays (point-min) (point-max)) 778 (let ((hs-allow-nesting nil))
779 (hs-discard-overlays (point-min) (point-max)))
767 (message "Showing all blocks ... done") 780 (message "Showing all blocks ... done")
768 (run-hooks 'hs-show-hook))) 781 (run-hooks 'hs-show-hook)))
769 782
@@ -782,7 +795,6 @@ Upon completion, point is repositioned and the normal hook
782 (looking-at hs-block-start-regexp) 795 (looking-at hs-block-start-regexp)
783 (hs-find-block-beginning)) 796 (hs-find-block-beginning))
784 (hs-hide-block-at-point end c-reg) 797 (hs-hide-block-at-point end c-reg)
785 (hs-safety-is-job-n)
786 (run-hooks 'hs-hide-hook)))))) 798 (run-hooks 'hs-hide-hook))))))
787 799
788(defun hs-show-block (&optional end) 800(defun hs-show-block (&optional end)
@@ -794,17 +806,15 @@ See documentation for functions `hs-hide-block' and `run-hooks'."
794 (hs-life-goes-on 806 (hs-life-goes-on
795 (or 807 (or
796 ;; first see if we have something at the end of the line 808 ;; first see if we have something at the end of the line
797 (catch 'eol-begins-hidden-region-p 809 (let ((ov (hs-overlay-at (save-excursion (end-of-line) (point))))
798 (let ((here (point))) 810 (here (point)))
799 (dolist (ov (save-excursion (end-of-line) (overlays-at (point)))) 811 (when ov
800 (when (overlay-get ov 'hs) 812 (goto-char
801 (goto-char 813 (cond (end (overlay-end ov))
802 (cond (end (overlay-end ov)) 814 ((eq 'comment (overlay-get ov 'hs)) here)
803 ((eq 'comment (overlay-get ov 'hs)) here) 815 (t (+ (overlay-start ov) (overlay-get ov 'hs-b-offset)))))
804 (t (+ (overlay-start ov) (overlay-get ov 'hs-b-offset))))) 816 (delete-overlay ov)
805 (delete-overlay ov) 817 t))
806 (throw 'eol-begins-hidden-region-p t)))
807 nil))
808 ;; not immediately obvious, look for a suitable block 818 ;; not immediately obvious, look for a suitable block
809 (let ((c-reg (hs-inside-comment-p)) 819 (let ((c-reg (hs-inside-comment-p))
810 p q) 820 p q)
@@ -820,7 +830,6 @@ See documentation for functions `hs-hide-block' and `run-hooks'."
820 (when (and p q) 830 (when (and p q)
821 (hs-discard-overlays p q) 831 (hs-discard-overlays p q)
822 (goto-char (if end q (1+ p))))) 832 (goto-char (if end q (1+ p)))))
823 (hs-safety-is-job-n)
824 (run-hooks 'hs-show-hook)))) 833 (run-hooks 'hs-show-hook))))
825 834
826(defun hs-hide-level (arg) 835(defun hs-hide-level (arg)
@@ -832,7 +841,6 @@ The hook `hs-hide-hook' is run; see `run-hooks'."
832 (message "Hiding blocks ...") 841 (message "Hiding blocks ...")
833 (hs-hide-level-recursive arg (point-min) (point-max)) 842 (hs-hide-level-recursive arg (point-min) (point-max))
834 (message "Hiding blocks ... done")) 843 (message "Hiding blocks ... done"))
835 (hs-safety-is-job-n)
836 (run-hooks 'hs-hide-hook))) 844 (run-hooks 'hs-hide-hook)))
837 845
838(defun hs-toggle-hiding () 846(defun hs-toggle-hiding ()