Mercurial > emacs
comparison lisp/progmodes/hideif.el @ 210:01cbfdd59f82
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 06 Mar 1991 21:14:11 +0000 |
parents | ea71bd48f294 |
children | 08eb386dd0f3 |
comparison
equal
deleted
inserted
replaced
209:f501afd0a375 | 210:01cbfdd59f82 |
---|---|
118 ;;; will appear when text may be hidden ("hide-ifdef-hiding" is non-nil). | 118 ;;; will appear when text may be hidden ("hide-ifdef-hiding" is non-nil). |
119 | 119 |
120 | 120 |
121 | 121 |
122 (defvar hide-ifdef-mode-map nil | 122 (defvar hide-ifdef-mode-map nil |
123 "Keymap used with hide-ifdef mode") | 123 "Keymap used with Hide-Ifdef mode") |
124 | 124 |
125 (defconst hide-ifdef-mode-prefix-key "\C-c" | 125 (defconst hide-ifdef-mode-prefix-key "\C-c" |
126 "Prefix key for all hide-ifdef-mode commands.") | 126 "Prefix key for all Hide-Ifdef mode commands.") |
127 | 127 |
128 (defvar hide-ifdef-mode-map-before nil | 128 (defvar hide-ifdef-mode-map-before nil |
129 "Buffer-local variable to store a copy of the local keymap | 129 "Buffer-local variable to store a copy of the local keymap |
130 before hide-ifdef-mode modifies it.") | 130 before `hide-ifdef-mode' modifies it.") |
131 | 131 |
132 (defun define-hide-ifdef-mode-map () | 132 (defun define-hide-ifdef-mode-map () |
133 (if hide-ifdef-mode-map | 133 (if hide-ifdef-mode-map |
134 () ; dont redefine it. | 134 () ; dont redefine it. |
135 (setq hide-ifdef-mode-map (make-sparse-keymap)) | 135 (setq hide-ifdef-mode-map (make-sparse-keymap)) |
159 | 159 |
160 (defun hif-update-mode-line () | 160 (defun hif-update-mode-line () |
161 "Update mode-line by setting buffer-modified to itself." | 161 "Update mode-line by setting buffer-modified to itself." |
162 (set-buffer-modified-p (buffer-modified-p))) | 162 (set-buffer-modified-p (buffer-modified-p))) |
163 | 163 |
164 | |
165 (defvar hide-ifdef-mode nil | 164 (defvar hide-ifdef-mode nil |
166 "non-nil when hide-ifdef-mode is activated.") | 165 "non-nil when hide-ifdef-mode is activated.") |
167 | 166 |
168 (defvar hide-ifdef-hiding nil | 167 (defvar hide-ifdef-hiding nil |
169 "non-nil when text may be hidden.") | 168 "non-nil when text may be hidden.") |
176 (or (assq 'hide-ifdef-mode minor-mode-alist) | 175 (or (assq 'hide-ifdef-mode minor-mode-alist) |
177 (setq minor-mode-alist | 176 (setq minor-mode-alist |
178 (cons '(hide-ifdef-mode " Ifdef") | 177 (cons '(hide-ifdef-mode " Ifdef") |
179 minor-mode-alist))) | 178 minor-mode-alist))) |
180 | 179 |
181 | |
182 (defun hide-ifdef-mode (arg) | 180 (defun hide-ifdef-mode (arg) |
183 "Toggle hide-ifdef-mode. Thus this is a minor mode, albeit a large one. | 181 "Toggle Hide-Ifdef mode. This is a minor mode, albeit a large one. |
184 With arg, turn hide-ifdef-mode on iff arg is positive. | 182 With ARG, turn Hide-Ifdef mode on iff arg is positive. |
185 In hide-ifdef-mode, code within #ifdef constructs that the C preprocessor | 183 In Hide-Ifdef mode, code within #ifdef constructs that the C preprocessor |
186 would eliminate may be hidden from view. Several variables affect | 184 would eliminate may be hidden from view. Several variables affect |
187 how the hiding is done: | 185 how the hiding is done: |
188 | 186 |
189 hide-ifdef-env | 187 hide-ifdef-env |
190 An association list of defined and undefined symbols for the | 188 An association list of defined and undefined symbols for the |
191 current buffer. Initially, the global value of hide-ifdef-env is used. | 189 current buffer. Initially, the global value of `hide-ifdef-env' |
190 is used. | |
192 | 191 |
193 hide-ifdef-define-alist | 192 hide-ifdef-define-alist |
194 An association list of defined symbol lists. | 193 An association list of defined symbol lists. |
195 Use hide-ifdef-set-define-alist to save the current hide-ifdef-env | 194 Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env' |
196 and hide-ifdef-use-define-alist to set the current hide-ifdef-env | 195 and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env' |
197 from one of the lists in hide-ifdef-define-alist. | 196 from one of the lists in `hide-ifdef-define-alist'. |
198 | 197 |
199 hide-ifdef-lines | 198 hide-ifdef-lines |
200 Set to non-nil to not show #if, #ifdef, #ifndef, #else, and | 199 Set to non-nil to not show #if, #ifdef, #ifndef, #else, and |
201 #endif lines when hiding. | 200 #endif lines when hiding. |
202 | 201 |
203 hide-ifdef-initially | 202 hide-ifdef-initially |
204 Indicates whether hide-ifdefs should be called when hide-ifdef-mode | 203 Indicates whether `hide-ifdefs' should be called when Hide-Ifdef mode |
205 is activated. | 204 is activated. |
206 | 205 |
207 hide-ifdef-read-only | 206 hide-ifdef-read-only |
208 Set to non-nil if you want to make buffers read only while hiding. | 207 Set to non-nil if you want to make buffers read only while hiding. |
209 After show-ifdefs, read-only status is restored to previous value. | 208 After `show-ifdefs', read-only status is restored to previous value. |
210 | 209 |
211 \\{hide-ifdef-mode-map}" | 210 \\{hide-ifdef-mode-map}" |
212 | 211 |
213 (interactive "P") | 212 (interactive "P") |
214 (make-local-variable 'hide-ifdef-mode) | 213 (make-local-variable 'hide-ifdef-mode) |
409 "Parse the TOKEN-LIST. Return translated list in prefix form." | 408 "Parse the TOKEN-LIST. Return translated list in prefix form." |
410 (hif-nexttoken) | 409 (hif-nexttoken) |
411 (prog1 | 410 (prog1 |
412 (hif-expr) | 411 (hif-expr) |
413 (if token ; is there still a token? | 412 (if token ; is there still a token? |
414 (error "Error: unexpected token: %s" token))) | 413 (error "Error: unexpected token: %s" token)))) |
415 ) | |
416 | 414 |
417 (defun hif-nexttoken () | 415 (defun hif-nexttoken () |
418 "Pop the next token from token-list into the let variable \"token\"." | 416 "Pop the next token from token-list into the let variable \"token\"." |
419 (setq token (car token-list)) | 417 (setq token (car token-list)) |
420 (setq token-list (cdr token-list)) | 418 (setq token-list (cdr token-list)) |
421 token | 419 token) |
422 ) | |
423 | 420 |
424 (defun hif-expr () | 421 (defun hif-expr () |
425 "Parse and expression of the form | 422 "Parse and expression of the form |
426 expr : term | expr '||' term." | 423 expr : term | expr '||' term." |
427 (let ((result (hif-term))) | 424 (let ((result (hif-term))) |
428 (while (eq token 'or) | 425 (while (eq token 'or) |
429 (hif-nexttoken) | 426 (hif-nexttoken) |
430 (setq result (list 'or result (hif-term)))) | 427 (setq result (list 'or result (hif-term)))) |
431 result | 428 result)) |
432 )) | |
433 | 429 |
434 (defun hif-term () | 430 (defun hif-term () |
435 "Parse a term of the form | 431 "Parse a term of the form |
436 term : factor | term '&&' factor." | 432 term : factor | term '&&' factor." |
437 (let ((result (hif-factor))) | 433 (let ((result (hif-factor))) |
438 (while (eq token 'and) | 434 (while (eq token 'and) |
439 (hif-nexttoken) | 435 (hif-nexttoken) |
440 (setq result (list 'and result (hif-factor)))) | 436 (setq result (list 'and result (hif-factor)))) |
441 result | 437 result)) |
442 )) | |
443 | 438 |
444 (defun hif-factor () | 439 (defun hif-factor () |
445 "Parse a factor of the form | 440 "Parse a factor of the form |
446 factor : '!' factor | '(' expr ')' | 'defined(' id ')' | id." | 441 factor : '!' factor | '(' expr ')' | 'defined(' id ')' | id." |
447 (cond | 442 (cond |
477 (if (memq ident '(or and)) | 472 (if (memq ident '(or and)) |
478 (error "Error: missing identifier")) | 473 (error "Error: missing identifier")) |
479 (hif-nexttoken) | 474 (hif-nexttoken) |
480 (` (hif-lookup (quote (, ident)))) | 475 (` (hif-lookup (quote (, ident)))) |
481 )) | 476 )) |
482 | |
483 )) | 477 )) |
484 | 478 |
485 ;;;----------- end of parser ----------------------- | 479 ;;;----------- end of parser ----------------------- |
486 | 480 |
487 | 481 |
515 NOT including one on this line." | 509 NOT including one on this line." |
516 ; (message "hif-find-next-relevant at %d" (point)) | 510 ; (message "hif-find-next-relevant at %d" (point)) |
517 (end-of-line) | 511 (end-of-line) |
518 ; avoid infinite recursion by only going to beginning of line if match found | 512 ; avoid infinite recursion by only going to beginning of line if match found |
519 (if (re-search-forward hif-ifx-else-endif-regexp (point-max) t) | 513 (if (re-search-forward hif-ifx-else-endif-regexp (point-max) t) |
520 (beginning-of-line)) | 514 (beginning-of-line))) |
521 ) | |
522 | 515 |
523 (defun hif-find-previous-relevant () | 516 (defun hif-find-previous-relevant () |
524 "Position at beginning of previous #ifdef, #ifndef, #else, #endif, | 517 "Position at beginning of previous #ifdef, #ifndef, #else, #endif, |
525 NOT including one on this line." | 518 NOT including one on this line." |
526 ; (message "hif-find-previous-relevant at %d" (point)) | 519 ; (message "hif-find-previous-relevant at %d" (point)) |
527 (beginning-of-line) | 520 (beginning-of-line) |
528 ; avoid infinite recursion by only going to beginning of line if match found | 521 ; avoid infinite recursion by only going to beginning of line if match found |
529 (if (re-search-backward hif-ifx-else-endif-regexp (point-min) t) | 522 (if (re-search-backward hif-ifx-else-endif-regexp (point-min) t) |
530 (beginning-of-line) | 523 (beginning-of-line))) |
531 ) | |
532 ) | |
533 | 524 |
534 | 525 |
535 (defun hif-looking-at-ifX () ;; Should eventually see #if | 526 (defun hif-looking-at-ifX () ;; Should eventually see #if |
536 (looking-at hif-ifx-regexp)) | 527 (looking-at hif-ifx-regexp)) |
537 (defun hif-looking-at-endif () | 528 (defun hif-looking-at-endif () |
551 ((hif-looking-at-else) | 542 ((hif-looking-at-else) |
552 (hif-ifdef-to-endif)) ; find endif following else | 543 (hif-ifdef-to-endif)) ; find endif following else |
553 ((hif-looking-at-endif) | 544 ((hif-looking-at-endif) |
554 'done) | 545 'done) |
555 (t | 546 (t |
556 (error "Missmatched #ifdef #endif pair")) | 547 (error "Missmatched #ifdef #endif pair")))) |
557 )) | |
558 | 548 |
559 | 549 |
560 (defun hif-endif-to-ifdef () | 550 (defun hif-endif-to-ifdef () |
561 "If positioned at #endif form, skip backward to corresponding #ifX." | 551 "If positioned at #endif form, skip backward to corresponding #ifX." |
562 ; (message "hif-endif-to-ifdef at %d" (point)) | 552 ; (message "hif-endif-to-ifdef at %d" (point)) |
569 (hif-endif-to-ifdef)) ; find beginning of outer if or else | 559 (hif-endif-to-ifdef)) ; find beginning of outer if or else |
570 ((hif-looking-at-else) | 560 ((hif-looking-at-else) |
571 (hif-endif-to-ifdef)) | 561 (hif-endif-to-ifdef)) |
572 ((hif-looking-at-ifX) | 562 ((hif-looking-at-ifX) |
573 'done) | 563 'done) |
574 (t ; never gets here | 564 (t ; never gets here))) |
575 ))) | |
576 | 565 |
577 | 566 |
578 (defun forward-ifdef (&optional arg) | 567 (defun forward-ifdef (&optional arg) |
579 "Move point to beginning of line of the next ifdef-endif. | 568 "Move point to beginning of line of the next ifdef-endif. |
580 With argument, do this that many times." | 569 With argument, do this that many times." |
581 (interactive "p") | 570 (interactive "p") |
582 (or arg (setq arg 1)) | 571 (or arg (setq arg 1)) |
583 (if (< arg 0) | 572 (if (< arg 0) |
584 (backward-ifdef (- arg))) | 573 (backward-ifdef (- arg))) |
585 (while (< 0 arg) | 574 (while (< 0 arg) |
594 )))) | 583 )))) |
595 | 584 |
596 | 585 |
597 (defun backward-ifdef (&optional arg) | 586 (defun backward-ifdef (&optional arg) |
598 "Move point to beginning of the previous ifdef-endif. | 587 "Move point to beginning of the previous ifdef-endif. |
599 With argument, do this that many times." | 588 With argument, do this that many times." |
600 (interactive "p") | 589 (interactive "p") |
601 (or arg (setq arg 1)) | 590 (or arg (setq arg 1)) |
602 (if (< arg 0) | 591 (if (< arg 0) |
603 (forward-ifdef (- arg))) | 592 (forward-ifdef (- arg))) |
604 (while (< 0 arg) | 593 (while (< 0 arg) |
608 (if (not (hif-looking-at-endif)) | 597 (if (not (hif-looking-at-endif)) |
609 (hif-find-previous-relevant)) | 598 (hif-find-previous-relevant)) |
610 (if (hif-looking-at-endif) | 599 (if (hif-looking-at-endif) |
611 (hif-endif-to-ifdef) | 600 (hif-endif-to-ifdef) |
612 (goto-char start) | 601 (goto-char start) |
613 (error "No previous #ifdef") | 602 (error "No previous #ifdef"))))) |
614 )))) | |
615 | |
616 | 603 |
617 | 604 |
618 (defun down-ifdef () | 605 (defun down-ifdef () |
619 "Move point to beginning of nested ifdef or else-part." | 606 "Move point to beginning of nested ifdef or else-part." |
620 (interactive) | 607 (interactive) |
621 (let ((start (point))) | 608 (let ((start (point))) |
622 (hif-find-next-relevant) | 609 (hif-find-next-relevant) |
623 (if (or (hif-looking-at-ifX) (hif-looking-at-else)) | 610 (if (or (hif-looking-at-ifX) (hif-looking-at-else)) |
624 () | 611 () |
625 (goto-char start) | 612 (goto-char start) |
626 (error "No following #ifdef") | 613 (error "No following #ifdef")))) |
627 ))) | |
628 | 614 |
629 | 615 |
630 (defun up-ifdef () | 616 (defun up-ifdef () |
631 "Move point to beginning of enclosing ifdef or else-part." | 617 "Move point to beginning of enclosing ifdef or else-part." |
632 (interactive) | 618 (interactive) |
635 (if (not (hif-looking-at-endif)) | 621 (if (not (hif-looking-at-endif)) |
636 (hif-find-previous-relevant)) | 622 (hif-find-previous-relevant)) |
637 (if (hif-looking-at-endif) | 623 (if (hif-looking-at-endif) |
638 (hif-endif-to-ifdef)) | 624 (hif-endif-to-ifdef)) |
639 (if (= start (point)) | 625 (if (= start (point)) |
640 (error "No previous #ifdef") | 626 (error "No previous #ifdef")))) |
641 ))) | |
642 | 627 |
643 (defun next-ifdef (&optional arg) | 628 (defun next-ifdef (&optional arg) |
644 "Move to the beginning of the next #ifX, #else, or #endif. | 629 "Move to the beginning of the next #ifX, #else, or #endif. |
645 With argument, do this that many times." | 630 With argument, do this that many times." |
646 (interactive "p") | 631 (interactive "p") |
647 (or arg (setq arg 1)) | 632 (or arg (setq arg 1)) |
648 (if (< arg 0) | 633 (if (< arg 0) |
649 (previous-ifdef (- arg))) | 634 (previous-ifdef (- arg))) |
650 (while (< 0 arg) | 635 (while (< 0 arg) |
651 (setq arg (1- arg)) | 636 (setq arg (1- arg)) |
652 (hif-find-next-relevant) | 637 (hif-find-next-relevant) |
653 (if (eolp) | 638 (if (eolp) |
654 (progn | 639 (progn |
655 (beginning-of-line) | 640 (beginning-of-line) |
656 (error "No following #ifdefs, #elses, or #endifs") | 641 (error "No following #ifdefs, #elses, or #endifs"))))) |
657 )))) | |
658 | 642 |
659 (defun previous-ifdef (&optional arg) | 643 (defun previous-ifdef (&optional arg) |
660 "Move to the beginning of the previous #ifX, #else, or #endif. | 644 "Move to the beginning of the previous #ifX, #else, or #endif. |
661 With argument, do this that many times." | 645 With argument, do this that many times." |
662 (interactive "p") | 646 (interactive "p") |
663 (or arg (setq arg 1)) | 647 (or arg (setq arg 1)) |
664 (if (< arg 0) | 648 (if (< arg 0) |
665 (next-ifdef (- arg))) | 649 (next-ifdef (- arg))) |
666 (while (< 0 arg) | 650 (while (< 0 arg) |
741 ;;; NOTE: If there's an #ifdef at the beginning of the file, we can't | 725 ;;; NOTE: If there's an #ifdef at the beginning of the file, we can't |
742 ;;; hide it. There's no previous newline to replace. If we added | 726 ;;; hide it. There's no previous newline to replace. If we added |
743 ;;; one, we'd throw off all the counts. Feh. | 727 ;;; one, we'd throw off all the counts. Feh. |
744 | 728 |
745 (defun hif-hide-line (point) | 729 (defun hif-hide-line (point) |
746 "Hide the line containing point. Does nothing if | 730 "Hide the line containing point. Does nothing if `hide-ifdef-lines' is nil." |
747 hide-ifdef-lines is nil." | |
748 (if hide-ifdef-lines | 731 (if hide-ifdef-lines |
749 (save-excursion | 732 (save-excursion |
750 (goto-char point) | 733 (goto-char point) |
751 (let ((modp (buffer-modified-p))) | 734 (let ((modp (buffer-modified-p))) |
752 (unwind-protect | 735 (unwind-protect |
781 ;;; | 764 ;;; |
782 ;;; When hif-possibly-hide returns, point is at the end of the | 765 ;;; When hif-possibly-hide returns, point is at the end of the |
783 ;;; possibly-hidden range. | 766 ;;; possibly-hidden range. |
784 | 767 |
785 (defun hif-recurse-on (start end) | 768 (defun hif-recurse-on (start end) |
786 "Call hide-ifdef-guts after narrowing to end of START line and END | 769 "Call `hide-ifdef-guts' after narrowing to end of START line and END line." |
787 line." | |
788 (save-excursion | 770 (save-excursion |
789 (save-restriction | 771 (save-restriction |
790 (goto-char start) | 772 (goto-char start) |
791 (end-of-line) | 773 (end-of-line) |
792 (narrow-to-region (point) end) | 774 (narrow-to-region (point) end) |
793 (hide-ifdef-guts)))) | 775 (hide-ifdef-guts)))) |
794 | 776 |
795 (defun hif-possibly-hide () | 777 (defun hif-possibly-hide () |
796 "Called at #ifX expression, this hides those parts that should be | 778 "Called at #ifX expression, this hides those parts that should be |
797 hidden, according to judgement of hide-ifdef-evaluator." | 779 hidden, according to judgement of `hide-ifdef-evaluator'." |
798 ; (message "hif-possibly-hide") (sit-for 1) | 780 ; (message "hif-possibly-hide") (sit-for 1) |
799 (let ((test (hif-canonicalize)) | 781 (let ((test (hif-canonicalize)) |
800 (range (hif-find-range))) | 782 (range (hif-find-range))) |
801 ; (message "test = %s" test) (sit-for 1) | 783 ; (message "test = %s" test) (sit-for 1) |
802 | 784 |
827 )) | 809 )) |
828 | 810 |
829 | 811 |
830 | 812 |
831 (defun hide-ifdef-guts () | 813 (defun hide-ifdef-guts () |
832 "Does the work of hide-ifdefs, except for the work that's pointless | 814 "Does the work of `hide-ifdefs', except for the work that's pointless |
833 to redo on a recursive entry." | 815 to redo on a recursive entry." |
834 ; (message "hide-ifdef-guts") | 816 ; (message "hide-ifdef-guts") |
835 (save-excursion | 817 (save-excursion |
836 (goto-char (point-min)) | 818 (goto-char (point-min)) |
837 (while (hif-find-any-ifX) | 819 (while (hif-find-any-ifX) |
841 | 823 |
842 | 824 |
843 ;===%%SF%% exports (Start) === | 825 ;===%%SF%% exports (Start) === |
844 | 826 |
845 (defvar hide-ifdef-initially nil | 827 (defvar hide-ifdef-initially nil |
846 "*Non-nil if hide-ifdefs should be called when hide-ifdef-mode | 828 "*Non-nil if `hide-ifdefs' should be called when Hide-Ifdef mode |
847 is first activated.") | 829 is first activated.") |
848 | 830 |
849 (defvar hide-ifdef-hiding nil | 831 (defvar hide-ifdef-hiding nil |
850 "Non-nil if text might be hidden.") | 832 "Non-nil if text might be hidden.") |
851 | 833 |
852 (defvar hide-ifdef-read-only nil | 834 (defvar hide-ifdef-read-only nil |
853 "*Set to non-nil if you want buffer to be read-only while hiding text.") | 835 "*Set to non-nil if you want buffer to be read-only while hiding text.") |
854 | 836 |
855 (defvar hif-outside-read-only nil | 837 (defvar hif-outside-read-only nil |
856 "Internal variable. Saves the value of buffer-read-only while hiding.") | 838 "Internal variable. Saves the value of `buffer-read-only' while hiding.") |
857 | 839 |
858 (defvar hide-ifdef-lines nil | 840 (defvar hide-ifdef-lines nil |
859 "*Set to t if you don't want to see the #ifX, #else, and #endif lines.") | 841 "*Set to t if you don't want to see the #ifX, #else, and #endif lines.") |
860 | 842 |
861 (defun hide-ifdef-toggle-read-only () | 843 (defun hide-ifdef-toggle-read-only () |
864 (setq hide-ifdef-read-only (not hide-ifdef-read-only)) | 846 (setq hide-ifdef-read-only (not hide-ifdef-read-only)) |
865 (message "Hide-Read-Only %s" | 847 (message "Hide-Read-Only %s" |
866 (if hide-ifdef-read-only "ON" "OFF")) | 848 (if hide-ifdef-read-only "ON" "OFF")) |
867 (if hide-ifdef-hiding | 849 (if hide-ifdef-hiding |
868 (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only))) | 850 (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only))) |
869 (hif-update-mode-line) | 851 (hif-update-mode-line)) |
870 ) | |
871 | 852 |
872 (defun hide-ifdef-toggle-outside-read-only () | 853 (defun hide-ifdef-toggle-outside-read-only () |
873 "Replacement for toggle-read-only within hide-ifdef-mode." | 854 "Replacement for `toggle-read-only' within Hide-Ifdef mode." |
874 (interactive) | 855 (interactive) |
875 (setq hif-outside-read-only (not hif-outside-read-only)) | 856 (setq hif-outside-read-only (not hif-outside-read-only)) |
876 (message "Read only %s" | 857 (message "Read only %s" |
877 (if hif-outside-read-only "ON" "OFF")) | 858 (if hif-outside-read-only "ON" "OFF")) |
878 (setq buffer-read-only | 859 (setq buffer-read-only |
879 (or (and hide-ifdef-hiding hide-ifdef-read-only) | 860 (or (and hide-ifdef-hiding hide-ifdef-read-only) |
880 hif-outside-read-only) | 861 hif-outside-read-only) |
881 ) | 862 ) |
882 (hif-update-mode-line) | 863 (hif-update-mode-line)) |
883 ) | |
884 | 864 |
885 | 865 |
886 (defun hide-ifdef-define (var) | 866 (defun hide-ifdef-define (var) |
887 "Define a VAR so that #ifdef VAR would be included." | 867 "Define a VAR so that #ifdef VAR would be included." |
888 (interactive "SDefine what? ") | 868 (interactive "SDefine what? ") |
896 (if hide-ifdef-hiding (hide-ifdefs))) | 876 (if hide-ifdef-hiding (hide-ifdefs))) |
897 | 877 |
898 | 878 |
899 (defun hide-ifdefs () | 879 (defun hide-ifdefs () |
900 "Hide the contents of some #ifdefs. Assume that defined symbols have | 880 "Hide the contents of some #ifdefs. Assume that defined symbols have |
901 been added to hide-ifdef-env. The text hidden is the text that would not | 881 been added to `hide-ifdef-env'. The text hidden is the text that would not |
902 be included by the C preprocessor if it were given the file with those | 882 be included by the C preprocessor if it were given the file with those |
903 symbols defined. | 883 symbols defined. |
904 | 884 |
905 Turn off hiding by calling show-ifdef." | 885 Turn off hiding by calling show-ifdef." |
906 | 886 |
913 (if buffer-read-only (toggle-read-only)) ; make it writable temporarily | 893 (if buffer-read-only (toggle-read-only)) ; make it writable temporarily |
914 (setq selective-display t) | 894 (setq selective-display t) |
915 (setq hide-ifdef-hiding t) | 895 (setq hide-ifdef-hiding t) |
916 (hide-ifdef-guts) | 896 (hide-ifdef-guts) |
917 (if (or hide-ifdef-read-only hif-outside-read-only) | 897 (if (or hide-ifdef-read-only hif-outside-read-only) |
918 (toggle-read-only) ; make it read only | 898 (toggle-read-only)) ; make it read only |
919 ) | 899 (message "Hiding done")) |
920 (message "Hiding done") | |
921 ) | |
922 | 900 |
923 | 901 |
924 (defun show-ifdefs () | 902 (defun show-ifdefs () |
925 "Cancel the effects of hide-ifdef. The contents of all #ifdefs is shown." | 903 "Cancel the effects of hide-ifdef. The contents of all #ifdefs is shown." |
926 (interactive) | 904 (interactive) |
927 (if buffer-read-only (toggle-read-only)) ; make it writable temporarily | 905 (if buffer-read-only (toggle-read-only)) ; make it writable temporarily |
928 (setq selective-display nil) ; defaults | 906 (setq selective-display nil) ; defaults |
929 (hif-show-all) | 907 (hif-show-all) |
930 (if hif-outside-read-only | 908 (if hif-outside-read-only |
931 (toggle-read-only)) ; make it read only | 909 (toggle-read-only)) ; make it read only |
932 (setq hide-ifdef-hiding nil) | 910 (setq hide-ifdef-hiding nil)) |
933 ) | |
934 | 911 |
935 | 912 |
936 (defun hif-find-ifdef-block () | 913 (defun hif-find-ifdef-block () |
937 "Utilitiy for hide and show ifdef-block. Set top and bottom of ifdef block." | 914 "Utilitiy for hide and show ifdef-block. Set top and bottom of ifdef block." |
938 (let (max-bottom) | 915 (let (max-bottom) |
940 (beginning-of-line) | 917 (beginning-of-line) |
941 (if (not (or (hif-looking-at-else) (hif-looking-at-ifX))) | 918 (if (not (or (hif-looking-at-else) (hif-looking-at-ifX))) |
942 (up-ifdef)) | 919 (up-ifdef)) |
943 (setq top (point)) | 920 (setq top (point)) |
944 (hif-ifdef-to-endif) | 921 (hif-ifdef-to-endif) |
945 (setq max-bottom (1- (point))) | 922 (setq max-bottom (1- (point)))) |
946 ) | |
947 (save-excursion | 923 (save-excursion |
948 (beginning-of-line) | 924 (beginning-of-line) |
949 (if (not (hif-looking-at-endif)) | 925 (if (not (hif-looking-at-endif)) |
950 (hif-find-next-relevant)) | 926 (hif-find-next-relevant)) |
951 (while (hif-looking-at-ifX) | 927 (while (hif-looking-at-ifX) |
952 (hif-ifdef-to-endif) | 928 (hif-ifdef-to-endif) |
953 (hif-find-next-relevant) | 929 (hif-find-next-relevant)) |
954 ) | 930 (setq bottom (min max-bottom (1- (point)))))) |
955 (setq bottom (min max-bottom (1- (point)))) | |
956 )) | |
957 ) | 931 ) |
958 | 932 |
959 | 933 |
960 (defun hide-ifdef-block () | 934 (defun hide-ifdef-block () |
961 "Hide the ifdef block (true or false part) enclosing or before the cursor." | 935 "Hide the ifdef block (true or false part) enclosing or before the cursor." |
969 (hide-ifdef-region top bottom) | 943 (hide-ifdef-region top bottom) |
970 (if hide-ifdef-lines | 944 (if hide-ifdef-lines |
971 (progn | 945 (progn |
972 (hif-hide-line top) | 946 (hif-hide-line top) |
973 (hif-hide-line (1+ bottom)))) | 947 (hif-hide-line (1+ bottom)))) |
974 (setq hide-ifdef-hiding t) | 948 (setq hide-ifdef-hiding t)) |
975 ) | |
976 (if (or hide-ifdef-read-only hif-outside-read-only) | 949 (if (or hide-ifdef-read-only hif-outside-read-only) |
977 (toggle-read-only)) | 950 (toggle-read-only))) |
978 ) | |
979 | 951 |
980 | 952 |
981 (defun show-ifdef-block () | 953 (defun show-ifdef-block () |
982 "Show the ifdef block (true or false part) enclosing or before the cursor." | 954 "Show the ifdef block (true or false part) enclosing or before the cursor." |
983 (interactive) | 955 (interactive) |
992 (hif-find-ifdef-block) | 964 (hif-find-ifdef-block) |
993 (hif-show-ifdef-region (1- top) bottom)) | 965 (hif-show-ifdef-region (1- top) bottom)) |
994 ) | 966 ) |
995 | 967 |
996 ; restore read only status since we dont know if all is shown. | 968 ; restore read only status since we dont know if all is shown. |
997 (if old-read-only (toggle-read-only)) | 969 (if old-read-only (toggle-read-only)))) |
998 )) | |
999 | |
1000 | 970 |
1001 | 971 |
1002 ;;; defininition alist support | 972 ;;; defininition alist support |
1003 | 973 |
1004 (defvar hide-ifdef-define-alist nil | 974 (defvar hide-ifdef-define-alist nil |
1012 (new-defs nil)) | 982 (new-defs nil)) |
1013 (while defs | 983 (while defs |
1014 (if (car defs) | 984 (if (car defs) |
1015 (setq new-defs (cons (car defs) new-defs))) | 985 (setq new-defs (cons (car defs) new-defs))) |
1016 (setq defs (cdr defs))) | 986 (setq defs (cdr defs))) |
1017 new-defs | 987 new-defs)) |
1018 )) | |
1019 | 988 |
1020 (defun hide-ifdef-set-define-alist (name) | 989 (defun hide-ifdef-set-define-alist (name) |
1021 "Set the association for NAME to hide-ifdef-env." | 990 "Set the association for NAME to hide-ifdef-env." |
1022 (interactive "SSet define list: ") | 991 (interactive "SSet define list: ") |
1023 (setq hide-ifdef-define-alist | 992 (setq hide-ifdef-define-alist |
1024 (cons (cons name (hif-compress-define-list hide-ifdef-env)) | 993 (cons (cons name (hif-compress-define-list hide-ifdef-env)) |
1025 hide-ifdef-define-alist)) | 994 hide-ifdef-define-alist))) |
1026 ) | |
1027 | 995 |
1028 (defun hide-ifdef-use-define-alist (name) | 996 (defun hide-ifdef-use-define-alist (name) |
1029 "Set hide-ifdef-env to the define list specified by NAME." | 997 "Set hide-ifdef-env to the define list specified by NAME." |
1030 (interactive "SUse define list: ") | 998 (interactive "SUse define list: ") |
1031 (let ((define-list (assoc name hide-ifdef-define-alist))) | 999 (let ((define-list (assoc name hide-ifdef-define-alist))) |
1032 (if define-list | 1000 (if define-list |
1033 (setq hide-ifdef-env | 1001 (setq hide-ifdef-env |
1034 (mapcar '(lambda (arg) (cons arg t)) | 1002 (mapcar '(lambda (arg) (cons arg t)) |
1035 (cdr define-list))) | 1003 (cdr define-list))) |
1036 (error "No define list for %s" name)) | 1004 (error "No define list for %s" name)) |
1037 (if hide-ifdef-hiding (hide-ifdefs)) | 1005 (if hide-ifdef-hiding (hide-ifdefs)))) |
1038 ) | |
1039 ) | |
1040 | 1006 |
1041 ;===%%SF%% exports (End) === | 1007 ;===%%SF%% exports (End) === |