diff options
| author | Dima Kogan | 2011-05-28 14:35:29 -0400 |
|---|---|---|
| committer | Chong Yidong | 2011-05-28 14:35:29 -0400 |
| commit | 5012f24c2a7ca12a298a4bdaf991961282ddc167 (patch) | |
| tree | 647a69a6e450d3b82dea8ab1a93923776e942460 | |
| parent | bf41276f9c9a6534a5deb1b44a5d84d9a30ccb4c (diff) | |
| download | emacs-5012f24c2a7ca12a298a4bdaf991961282ddc167.tar.gz emacs-5012f24c2a7ca12a298a4bdaf991961282ddc167.zip | |
More fixes to prevent hide-show from being confused by commented-out braces (Bug#8279).
* progmodes/hideshow.el (hs-looking-at-block-start-p): New fun.
(hs-hide-block-at-point, hs-find-block-beginning)
(hs-already-hidden-p, hs-hide-block, hs-show-block): Use it.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/progmodes/hideshow.el | 27 |
2 files changed, 23 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3480e3a1382..dba8f538d5e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2011-05-28 Dima Kogan <dkogan@cds.caltech.edu> (tiny change) | ||
| 2 | |||
| 3 | * progmodes/hideshow.el (hs-looking-at-block-start-p): New fun. | ||
| 4 | (hs-hide-block-at-point, hs-find-block-beginning) | ||
| 5 | (hs-already-hidden-p, hs-hide-block, hs-show-block): Use it | ||
| 6 | (Bug#8279). | ||
| 7 | |||
| 1 | 2011-05-28 Glenn Morris <rgm@gnu.org> | 8 | 2011-05-28 Glenn Morris <rgm@gnu.org> |
| 2 | 9 | ||
| 3 | * startup.el (fancy-about-screen): Use standard mode line. (Bug#8740) | 10 | * startup.el (fancy-about-screen): Use standard mode line. (Bug#8740) |
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el index d07edd5de2f..49202ab6692 100644 --- a/lisp/progmodes/hideshow.el +++ b/lisp/progmodes/hideshow.el | |||
| @@ -536,6 +536,11 @@ property of an overlay." | |||
| 536 | (overlay-put ov 'display nil)))) | 536 | (overlay-put ov 'display nil)))) |
| 537 | (overlay-put ov 'invisible (and hide-p 'hs))) | 537 | (overlay-put ov 'invisible (and hide-p 'hs))) |
| 538 | 538 | ||
| 539 | (defun hs-looking-at-block-start-p () | ||
| 540 | "Return non-nil if the point is at the block start." | ||
| 541 | (and (looking-at hs-block-start-regexp) | ||
| 542 | (save-match-data (not (nth 4 (syntax-ppss)))))) | ||
| 543 | |||
| 539 | (defun hs-forward-sexp (match-data arg) | 544 | (defun hs-forward-sexp (match-data arg) |
| 540 | "Adjust point based on MATCH-DATA and call `hs-forward-sexp-func' w/ ARG. | 545 | "Adjust point based on MATCH-DATA and call `hs-forward-sexp-func' w/ ARG. |
| 541 | Original match data is restored upon return." | 546 | Original match data is restored upon return." |
| @@ -564,7 +569,7 @@ The block beginning is adjusted by `hs-adjust-block-beginning' | |||
| 564 | and then further adjusted to be at the end of the line." | 569 | and then further adjusted to be at the end of the line." |
| 565 | (if comment-reg | 570 | (if comment-reg |
| 566 | (hs-hide-comment-region (car comment-reg) (cadr comment-reg) end) | 571 | (hs-hide-comment-region (car comment-reg) (cadr comment-reg) end) |
| 567 | (when (looking-at hs-block-start-regexp) | 572 | (when (hs-looking-at-block-start-p) |
| 568 | (let ((mdata (match-data t)) | 573 | (let ((mdata (match-data t)) |
| 569 | (header-end (match-end 0)) | 574 | (header-end (match-end 0)) |
| 570 | p q ov) | 575 | p q ov) |
| @@ -684,16 +689,16 @@ Return point, or nil if original point was not in a block." | |||
| 684 | (let ((done nil) | 689 | (let ((done nil) |
| 685 | (here (point))) | 690 | (here (point))) |
| 686 | ;; look if current line is block start | 691 | ;; look if current line is block start |
| 687 | (if (looking-at hs-block-start-regexp) | 692 | (if (hs-looking-at-block-start-p) |
| 688 | (point) | 693 | (point) |
| 689 | ;; look backward for the start of a block that contains the cursor | 694 | ;; look backward for the start of a block that contains the cursor |
| 690 | (while (and (re-search-backward hs-block-start-regexp nil t) | 695 | (while (and (re-search-backward hs-block-start-regexp nil t) |
| 691 | (save-match-data | 696 | ;; go again if in a comment |
| 692 | (not (nth 4 (syntax-ppss)))) ; not inside comments | 697 | (or (save-match-data (nth 4 (syntax-ppss))) |
| 693 | (not (setq done | 698 | (not (setq done |
| 694 | (< here (save-excursion | 699 | (< here (save-excursion |
| 695 | (hs-forward-sexp (match-data t) 1) | 700 | (hs-forward-sexp (match-data t) 1) |
| 696 | (point))))))) | 701 | (point)))))))) |
| 697 | (if done | 702 | (if done |
| 698 | (point) | 703 | (point) |
| 699 | (goto-char here) | 704 | (goto-char here) |
| @@ -750,7 +755,7 @@ and `case-fold-search' are both t." | |||
| 750 | (end-of-line) | 755 | (end-of-line) |
| 751 | (when (and (not c-reg) | 756 | (when (and (not c-reg) |
| 752 | (hs-find-block-beginning) | 757 | (hs-find-block-beginning) |
| 753 | (looking-at hs-block-start-regexp)) | 758 | (hs-looking-at-block-start-p)) |
| 754 | ;; point is inside a block | 759 | ;; point is inside a block |
| 755 | (goto-char (match-end 0))))) | 760 | (goto-char (match-end 0))))) |
| 756 | (end-of-line) | 761 | (end-of-line) |
| @@ -835,7 +840,7 @@ Upon completion, point is repositioned and the normal hook | |||
| 835 | (<= (count-lines (car c-reg) (nth 1 c-reg)) 1))) | 840 | (<= (count-lines (car c-reg) (nth 1 c-reg)) 1))) |
| 836 | (message "(not enough comment lines to hide)")) | 841 | (message "(not enough comment lines to hide)")) |
| 837 | ((or c-reg | 842 | ((or c-reg |
| 838 | (looking-at hs-block-start-regexp) | 843 | (hs-looking-at-block-start-p) |
| 839 | (hs-find-block-beginning)) | 844 | (hs-find-block-beginning)) |
| 840 | (hs-hide-block-at-point end c-reg) | 845 | (hs-hide-block-at-point end c-reg) |
| 841 | (run-hooks 'hs-hide-hook)))))) | 846 | (run-hooks 'hs-hide-hook)))))) |
| @@ -867,7 +872,7 @@ See documentation for functions `hs-hide-block' and `run-hooks'." | |||
| 867 | q (cadr c-reg)))) | 872 | q (cadr c-reg)))) |
| 868 | ((and (hs-find-block-beginning) | 873 | ((and (hs-find-block-beginning) |
| 869 | ;; ugh, fresh match-data | 874 | ;; ugh, fresh match-data |
| 870 | (looking-at hs-block-start-regexp)) | 875 | (hs-looking-at-block-start-p)) |
| 871 | (setq p (point) | 876 | (setq p (point) |
| 872 | q (progn (hs-forward-sexp (match-data t) 1) (point))))) | 877 | q (progn (hs-forward-sexp (match-data t) 1) (point))))) |
| 873 | (when (and p q) | 878 | (when (and p q) |