aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThien-Thi Nguyen2004-12-26 19:48:10 +0000
committerThien-Thi Nguyen2004-12-26 19:48:10 +0000
commitdfdc1af2c60d3490f50844f734a31e692b12fb7e (patch)
treea06283124d309ab3aa070095f0394a2e01a0430f
parent4e6e2184d82de441fca1d1daf9b51a518c7ff265 (diff)
downloademacs-dfdc1af2c60d3490f50844f734a31e692b12fb7e.tar.gz
emacs-dfdc1af2c60d3490f50844f734a31e692b12fb7e.zip
(hs-set-up-overlay): New user var.
(hs-make-overlay): New function. (hs-isearch-show-temporary): Handle `display' overlay prop specially. (hs-flag-region): Delete function. (hs-hide-comment-region): No longer use `hs-flag-region'. Instead, use `hs-discard-overlays' and `hs-make-overlay'. (hs-hide-block-at-point): Likewise. (hs-hide-level-recursive): Use `hs-discard-overlays'. (hs-hide-all, hs-show-all): Likewise. (hs-show-block): Likewise. Also, use overlay prop `hs-b-offset', not `hs-ofs'.
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/progmodes/hideshow.el117
2 files changed, 95 insertions, 36 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index aebf3cc4285..18ceb9cfefa 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
12004-12-26 Thien-Thi Nguyen <ttn@gnu.org>
2
3 * progmodes/hideshow.el (hs-set-up-overlay): New user var.
4 (hs-make-overlay): New function.
5 (hs-isearch-show-temporary): Handle `display' overlay prop specially.
6 (hs-flag-region): Delete function.
7 (hs-hide-comment-region): No longer use `hs-flag-region'.
8 Instead, use `hs-discard-overlays' and `hs-make-overlay'.
9 (hs-hide-block-at-point): Likewise.
10 (hs-hide-level-recursive): Use `hs-discard-overlays'.
11 (hs-hide-all, hs-show-all): Likewise.
12 (hs-show-block): Likewise.
13 Also, use overlay prop `hs-b-offset', not `hs-ofs'.
14
12004-12-24 Thien-Thi Nguyen <ttn@gnu.org> 152004-12-24 Thien-Thi Nguyen <ttn@gnu.org>
2 16
3 * progmodes/hideshow.el: Require `cl' when compiling. 17 * progmodes/hideshow.el: Require `cl' when compiling.
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el
index 3bd5dd2a1f6..07fcda385ef 100644
--- a/lisp/progmodes/hideshow.el
+++ b/lisp/progmodes/hideshow.el
@@ -5,7 +5,7 @@
5;; Author: Thien-Thi Nguyen <ttn@gnu.org> 5;; Author: Thien-Thi Nguyen <ttn@gnu.org>
6;; Dan Nicolaescu <dann@ics.uci.edu> 6;; Dan Nicolaescu <dann@ics.uci.edu>
7;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines 7;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines
8;; Maintainer-Version: 5.39.2.8 8;; Maintainer-Version: 5.58.2.3
9;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning 9;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning
10 10
11;; This file is part of GNU Emacs. 11;; This file is part of GNU Emacs.
@@ -138,6 +138,19 @@
138;; If you have an entry that works particularly well, consider 138;; If you have an entry that works particularly well, consider
139;; submitting it for inclusion in hideshow.el. See docstring for 139;; submitting it for inclusion in hideshow.el. See docstring for
140;; `hs-special-modes-alist' for more info on the entry format. 140;; `hs-special-modes-alist' for more info on the entry format.
141;;
142;; See also variable `hs-set-up-overlay' for per-block customization of
143;; appearance or other effects associated with overlays. For example:
144;;
145;; (setq hs-set-up-overlay
146;; (defun my-display-code-line-counts (ov)
147;; (when (eq 'code (overlay-get ov 'hs))
148;; (overlay-put ov 'display
149;; (propertize
150;; (format " ... <%d>"
151;; (count-lines (overlay-start ov)
152;; (overlay-end ov)))
153;; 'face 'font-lock-type-face)))))
141 154
142;; * Bugs 155;; * Bugs
143;; 156;;
@@ -304,6 +317,24 @@ a block), `hs-hide-all', `hs-hide-block' and `hs-hide-level'.")
304These commands include the toggling commands (when the result is to show 317These commands include the toggling commands (when the result is to show
305a block), `hs-show-all' and `hs-show-block'..") 318a block), `hs-show-all' and `hs-show-block'..")
306 319
320(defvar hs-set-up-overlay nil
321 "*Function called with one arg, OV, a newly initialized overlay.
322Hideshow puts a unique overlay on each range of text to be hidden
323in the buffer. Here is a simple example of how to use this variable:
324
325 (defun display-code-line-counts (ov)
326 (when (eq 'code (overlay-get ov 'hs))
327 (overlay-put ov 'display
328 (format \"... / %d\"
329 (count-lines (overlay-start ov)
330 (overlay-end ov))))))
331
332 (setq hs-set-up-overlay 'display-code-line-counts)
333
334This example shows how to get information from the overlay as well
335as how to set its `display' property. See `hs-make-overlay' and
336info node `(elisp)Overlays'.")
337
307;;--------------------------------------------------------------------------- 338;;---------------------------------------------------------------------------
308;; internal variables 339;; internal variables
309 340
@@ -388,6 +419,35 @@ Note that `mode-line-format' is buffer-local.")
388 (when (overlay-get ov 'hs) 419 (when (overlay-get ov 'hs)
389 (delete-overlay ov)))) 420 (delete-overlay ov))))
390 421
422(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.
424KIND is either `code' or `comment'. Optional fourth arg B-OFFSET
425when added to B specifies the actual buffer position where the block
426begins. Likewise for optional fifth arg E-OFFSET. If unspecified
427they are taken to be 0 (zero). The following properties are set
428in the overlay: 'invisible 'hs 'hs-b-offset 'hs-e-offset. Also,
429depending on variable `hs-isearch-open', the following properties may
430be present: 'isearch-open-invisible 'isearch-open-invisible-temporary.
431If variable `hs-set-up-overlay' is non-nil it should specify a function
432to call with the newly initialized overlay."
433 (unless b-offset (setq b-offset 0))
434 (unless e-offset (setq e-offset 0))
435 (let ((ov (make-overlay b e))
436 (io (if (eq 'block hs-isearch-open)
437 ;; backward compatibility -- `block'<=>`code'
438 'code
439 hs-isearch-open)))
440 (overlay-put ov 'invisible 'hs)
441 (overlay-put ov 'hs kind)
442 (overlay-put ov 'hs-b-offset b-offset)
443 (overlay-put ov 'hs-e-offset e-offset)
444 (when (or (eq io t) (eq io kind))
445 (overlay-put ov 'isearch-open-invisible 'hs-isearch-show)
446 (overlay-put ov 'isearch-open-invisible-temporary
447 'hs-isearch-show-temporary))
448 (when hs-set-up-overlay (funcall hs-set-up-overlay ov))
449 ov))
450
391(defun hs-isearch-show (ov) 451(defun hs-isearch-show (ov)
392 "Delete overlay OV, and set `hs-headline' to nil. 452 "Delete overlay OV, and set `hs-headline' to nil.
393 453
@@ -416,32 +476,17 @@ property of an overlay."
416 (point)) 476 (point))
417 start))))) 477 start)))))
418 (force-mode-line-update) 478 (force-mode-line-update)
479 ;; handle `display' property specially
480 (let (value)
481 (if hide-p
482 (when (setq value (overlay-get ov 'hs-isearch-display))
483 (overlay-put ov 'display value)
484 (overlay-put ov 'hs-isearch-display nil))
485 (when (setq value (overlay-get ov 'display))
486 (overlay-put ov 'hs-isearch-display value)
487 (overlay-put ov 'display nil))))
419 (overlay-put ov 'invisible (and hide-p 'hs))) 488 (overlay-put ov 'invisible (and hide-p 'hs)))
420 489
421(defun hs-flag-region (from to flag)
422 "Hide or show lines from FROM to TO, according to FLAG.
423If FLAG is nil then text is shown, while if FLAG is non-nil the text is
424hidden. FLAG must be one of the symbols `code' or `comment', depending
425on what kind of block is to be hidden."
426 (save-excursion
427 ;; first clear it all out
428 (hs-discard-overlays from to)
429 ;; now create overlays if needed
430 (when flag
431 (let ((overlay (make-overlay from to)))
432 (overlay-put overlay 'invisible 'hs)
433 (overlay-put overlay 'hs flag)
434 (when (or (eq hs-isearch-open t)
435 (eq hs-isearch-open flag)
436 ;; deprecated backward compatibility -- `block'<=>`code'
437 (and (eq 'block hs-isearch-open)
438 (eq 'code flag)))
439 (overlay-put overlay 'isearch-open-invisible 'hs-isearch-show)
440 (overlay-put overlay
441 'isearch-open-invisible-temporary
442 'hs-isearch-show-temporary))
443 overlay))))
444
445(defun hs-forward-sexp (match-data arg) 490(defun hs-forward-sexp (match-data arg)
446 "Adjust point based on MATCH-DATA and call `hs-forward-sexp-func' w/ ARG. 491 "Adjust point based on MATCH-DATA and call `hs-forward-sexp-func' w/ ARG.
447Original match data is restored upon return." 492Original match data is restored upon return."
@@ -453,9 +498,10 @@ Original match data is restored upon return."
453(defun hs-hide-comment-region (beg end &optional repos-end) 498(defun hs-hide-comment-region (beg end &optional repos-end)
454 "Hide a region from BEG to END, marking it as a comment. 499 "Hide a region from BEG to END, marking it as a comment.
455Optional arg REPOS-END means reposition at end." 500Optional arg REPOS-END means reposition at end."
456 (hs-flag-region (progn (goto-char beg) (end-of-line) (point)) 501 (let ((beg-eol (progn (goto-char beg) (end-of-line) (point)))
457 (progn (goto-char end) (end-of-line) (point)) 502 (end-eol (progn (goto-char end) (end-of-line) (point))))
458 'comment) 503 (hs-discard-overlays beg-eol end-eol)
504 (hs-make-overlay beg-eol end-eol 'comment beg end))
459 (goto-char (if repos-end end beg))) 505 (goto-char (if repos-end end beg)))
460 506
461(defun hs-hide-block-at-point (&optional end comment-reg) 507(defun hs-hide-block-at-point (&optional end comment-reg)
@@ -488,9 +534,8 @@ and then further adjusted to be at the end of the line."
488 (end-of-line) 534 (end-of-line)
489 (point)))) 535 (point))))
490 (when (and (< p (point)) (> (count-lines p q) 1)) 536 (when (and (< p (point)) (> (count-lines p q) 1))
491 (overlay-put (hs-flag-region p q 'code) 537 (hs-discard-overlays p q)
492 'hs-ofs 538 (hs-make-overlay p q 'code (- pure-p p)))
493 (- pure-p p)))
494 (goto-char (if end q (min p pure-p))))))) 539 (goto-char (if end q (min p pure-p)))))))
495 540
496(defun hs-safety-is-job-n () 541(defun hs-safety-is-job-n ()
@@ -612,7 +657,7 @@ Return point, or nil if original point was not in a block."
612 (setq minp (1+ (point))) 657 (setq minp (1+ (point)))
613 (funcall hs-forward-sexp-func 1) 658 (funcall hs-forward-sexp-func 1)
614 (setq maxp (1- (point)))) 659 (setq maxp (1- (point))))
615 (hs-flag-region minp maxp nil) ; eliminate weirdness 660 (hs-discard-overlays minp maxp) ; eliminate weirdness
616 (goto-char minp) 661 (goto-char minp)
617 (while (progn 662 (while (progn
618 (forward-comment (buffer-size)) 663 (forward-comment (buffer-size))
@@ -678,7 +723,7 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
678 (hs-life-goes-on 723 (hs-life-goes-on
679 (message "Hiding all blocks ...") 724 (message "Hiding all blocks ...")
680 (save-excursion 725 (save-excursion
681 (hs-flag-region (point-min) (point-max) nil) ; eliminate weirdness 726 (hs-discard-overlays (point-min) (point-max)) ; eliminate weirdness
682 (goto-char (point-min)) 727 (goto-char (point-min))
683 (let ((count 0) 728 (let ((count 0)
684 (re (concat "\\(" 729 (re (concat "\\("
@@ -717,7 +762,7 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
717 (interactive) 762 (interactive)
718 (hs-life-goes-on 763 (hs-life-goes-on
719 (message "Showing all blocks ...") 764 (message "Showing all blocks ...")
720 (hs-flag-region (point-min) (point-max) nil) 765 (hs-discard-overlays (point-min) (point-max))
721 (message "Showing all blocks ... done") 766 (message "Showing all blocks ... done")
722 (run-hooks 'hs-show-hook))) 767 (run-hooks 'hs-show-hook)))
723 768
@@ -755,7 +800,7 @@ See documentation for functions `hs-hide-block' and `run-hooks'."
755 (goto-char 800 (goto-char
756 (cond (end (overlay-end ov)) 801 (cond (end (overlay-end ov))
757 ((eq 'comment (overlay-get ov 'hs)) here) 802 ((eq 'comment (overlay-get ov 'hs)) here)
758 (t (+ (overlay-start ov) (overlay-get ov 'hs-ofs))))) 803 (t (+ (overlay-start ov) (overlay-get ov 'hs-b-offset)))))
759 (delete-overlay ov) 804 (delete-overlay ov)
760 (throw 'eol-begins-hidden-region-p t))) 805 (throw 'eol-begins-hidden-region-p t)))
761 nil)) 806 nil))
@@ -771,7 +816,7 @@ See documentation for functions `hs-hide-block' and `run-hooks'."
771 (setq p (point) 816 (setq p (point)
772 q (progn (hs-forward-sexp (hs-match-data t) 1) (point))))) 817 q (progn (hs-forward-sexp (hs-match-data t) 1) (point)))))
773 (when (and p q) 818 (when (and p q)
774 (hs-flag-region p q nil) 819 (hs-discard-overlays p q)
775 (goto-char (if end q (1+ p))))) 820 (goto-char (if end q (1+ p)))))
776 (hs-safety-is-job-n) 821 (hs-safety-is-job-n)
777 (run-hooks 'hs-show-hook)))) 822 (run-hooks 'hs-show-hook))))