Mercurial > emacs
comparison lisp/progmodes/hideif.el @ 49598:0d8b17d428b5
Trailing whitepace deleted.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 04 Feb 2003 13:24:35 +0000 |
parents | 91939e9a62ec |
children | 695cf19ef79e d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
49597:e88404e8f2cf | 49598:0d8b17d428b5 |
---|---|
34 ;; define list (default empty), type | 34 ;; define list (default empty), type |
35 ;; | 35 ;; |
36 ;; M-x hide-ifdefs or C-c @ h | 36 ;; M-x hide-ifdefs or C-c @ h |
37 ;; | 37 ;; |
38 ;; Hide-ifdef suppresses the display of code that the preprocessor wouldn't | 38 ;; Hide-ifdef suppresses the display of code that the preprocessor wouldn't |
39 ;; pass through. The support of constant expressions in #if lines is | 39 ;; pass through. The support of constant expressions in #if lines is |
40 ;; limited to identifiers, parens, and the operators: &&, ||, !, and | 40 ;; limited to identifiers, parens, and the operators: &&, ||, !, and |
41 ;; "defined". Please extend this. | 41 ;; "defined". Please extend this. |
42 ;; | 42 ;; |
43 ;; The hidden code is marked by ellipses (...). Be | 43 ;; The hidden code is marked by ellipses (...). Be |
44 ;; cautious when editing near ellipses, since the hidden text is | 44 ;; cautious when editing near ellipses, since the hidden text is |
45 ;; still in the buffer, and you can move the point into it and modify | 45 ;; still in the buffer, and you can move the point into it and modify |
46 ;; text unawares. | 46 ;; text unawares. |
47 ;; You can make your buffer read-only while hide-ifdef-hiding by setting | 47 ;; You can make your buffer read-only while hide-ifdef-hiding by setting |
48 ;; hide-ifdef-read-only to a non-nil value. You can toggle this | 48 ;; hide-ifdef-read-only to a non-nil value. You can toggle this |
49 ;; variable with hide-ifdef-toggle-read-only (C-c @ C-q). | 49 ;; variable with hide-ifdef-toggle-read-only (C-c @ C-q). |
50 ;; | 50 ;; |
51 ;; You can undo the effect of hide-ifdefs by typing | 51 ;; You can undo the effect of hide-ifdefs by typing |
52 ;; | 52 ;; |
53 ;; M-x show-ifdefs or C-c @ s | 53 ;; M-x show-ifdefs or C-c @ s |
56 ;; Use M-x hide-ifdef-undef (C-c @ u) to undefine a symbol. | 56 ;; Use M-x hide-ifdef-undef (C-c @ u) to undefine a symbol. |
57 ;; | 57 ;; |
58 ;; If you define or undefine a symbol while hide-ifdef-mode is in effect, | 58 ;; If you define or undefine a symbol while hide-ifdef-mode is in effect, |
59 ;; the display will be updated. Only the define list for the current | 59 ;; the display will be updated. Only the define list for the current |
60 ;; buffer will be affected. You can save changes to the local define | 60 ;; buffer will be affected. You can save changes to the local define |
61 ;; list with hide-ifdef-set-define-alist. This adds entries | 61 ;; list with hide-ifdef-set-define-alist. This adds entries |
62 ;; to hide-ifdef-define-alist. | 62 ;; to hide-ifdef-define-alist. |
63 ;; | 63 ;; |
64 ;; If you have defined a hide-ifdef-mode-hook, you can set | 64 ;; If you have defined a hide-ifdef-mode-hook, you can set |
65 ;; up a list of symbols that may be used by hide-ifdefs as in the | 65 ;; up a list of symbols that may be used by hide-ifdefs as in the |
66 ;; following example: | 66 ;; following example: |
177 An association list of defined and undefined symbols for the | 177 An association list of defined and undefined symbols for the |
178 current buffer. Initially, the global value of `hide-ifdef-env' | 178 current buffer. Initially, the global value of `hide-ifdef-env' |
179 is used. | 179 is used. |
180 | 180 |
181 `hide-ifdef-define-alist' | 181 `hide-ifdef-define-alist' |
182 An association list of defined symbol lists. | 182 An association list of defined symbol lists. |
183 Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env' | 183 Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env' |
184 and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env' | 184 and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env' |
185 from one of the lists in `hide-ifdef-define-alist'. | 185 from one of the lists in `hide-ifdef-define-alist'. |
186 | 186 |
187 `hide-ifdef-lines' | 187 `hide-ifdef-lines' |
218 ;; else end hide-ifdef-mode | 218 ;; else end hide-ifdef-mode |
219 (kill-local-variable 'line-move-ignore-invisible) | 219 (kill-local-variable 'line-move-ignore-invisible) |
220 (remove-from-invisibility-spec '(hide-ifdef . t)) | 220 (remove-from-invisibility-spec '(hide-ifdef . t)) |
221 (if hide-ifdef-hiding | 221 (if hide-ifdef-hiding |
222 (show-ifdefs)))) | 222 (show-ifdefs)))) |
223 | 223 |
224 | 224 |
225 (defun hif-show-all () | 225 (defun hif-show-all () |
226 "Show all of the text in the current buffer." | 226 "Show all of the text in the current buffer." |
227 (interactive) | 227 (interactive) |
228 (hif-show-ifdef-region (point-min) (point-max))) | 228 (hif-show-ifdef-region (point-min) (point-max))) |
418 (while (memq hif-token '(hif-plus hif-minus)) | 418 (while (memq hif-token '(hif-plus hif-minus)) |
419 (setq math-op hif-token) | 419 (setq math-op hif-token) |
420 (hif-nexttoken) | 420 (hif-nexttoken) |
421 (setq result (list math-op result (hif-factor)))) | 421 (setq result (list math-op result (hif-factor)))) |
422 result)) | 422 result)) |
423 | 423 |
424 (defun hif-factor () | 424 (defun hif-factor () |
425 "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id." | 425 "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id." |
426 (cond | 426 (cond |
427 ((eq hif-token 'not) | 427 ((eq hif-token 'not) |
428 (hif-nexttoken) | 428 (hif-nexttoken) |
718 (if (hif-looking-at-else) | 718 (if (hif-looking-at-else) |
719 (error "Found two elses in a row? Broken!")) | 719 (error "Found two elses in a row? Broken!")) |
720 (setq end (point))) ; (save-excursion (end-of-line) (point)) | 720 (setq end (point))) ; (save-excursion (end-of-line) (point)) |
721 (hif-make-range start end else)))) | 721 (hif-make-range start end else)))) |
722 | 722 |
723 | 723 |
724 ;;; A bit slimy. | 724 ;;; A bit slimy. |
725 | 725 |
726 (defun hif-hide-line (point) | 726 (defun hif-hide-line (point) |
727 "Hide the line containing point. Does nothing if `hide-ifdef-lines' is nil." | 727 "Hide the line containing point. Does nothing if `hide-ifdef-lines' is nil." |
728 (if hide-ifdef-lines | 728 (if hide-ifdef-lines |
729 (save-excursion | 729 (save-excursion |
730 (goto-char point) | 730 (goto-char point) |
731 (hide-ifdef-region-internal (line-beginning-position) | 731 (hide-ifdef-region-internal (line-beginning-position) |
732 (progn (hif-end-of-line) (point)))))) | 732 (progn (hif-end-of-line) (point)))))) |
733 | 733 |
734 | 734 |
735 ;;; Hif-Possibly-Hide | 735 ;;; Hif-Possibly-Hide |
736 ;;; There are four cases. The #ifX expression is "taken" if it | 736 ;;; There are four cases. The #ifX expression is "taken" if it |
737 ;;; the hide-ifdef-evaluator returns T. Presumably, this means the code | 737 ;;; the hide-ifdef-evaluator returns T. Presumably, this means the code |
738 ;;; inside the #ifdef would be included when the program was | 738 ;;; inside the #ifdef would be included when the program was |
739 ;;; compiled. | 739 ;;; compiled. |
740 ;;; | 740 ;;; |
741 ;;; Case 1: #ifX taken, and there's an #else. | 741 ;;; Case 1: #ifX taken, and there's an #else. |
742 ;;; The #else part must be hidden. The #if (then) part must be | 742 ;;; The #else part must be hidden. The #if (then) part must be |
743 ;;; processed for nested #ifX's. | 743 ;;; processed for nested #ifX's. |
744 ;;; Case 2: #ifX taken, and there's no #else. | 744 ;;; Case 2: #ifX taken, and there's no #else. |
769 It uses the judgement of `hide-ifdef-evaluator'." | 769 It uses the judgement of `hide-ifdef-evaluator'." |
770 ;; (message "hif-possibly-hide") (sit-for 1) | 770 ;; (message "hif-possibly-hide") (sit-for 1) |
771 (let ((test (hif-canonicalize)) | 771 (let ((test (hif-canonicalize)) |
772 (range (hif-find-range))) | 772 (range (hif-find-range))) |
773 ;; (message "test = %s" test) (sit-for 1) | 773 ;; (message "test = %s" test) (sit-for 1) |
774 | 774 |
775 (hif-hide-line (hif-range-end range)) | 775 (hif-hide-line (hif-range-end range)) |
776 (if (not (hif-not (funcall hide-ifdef-evaluator test))) | 776 (if (not (hif-not (funcall hide-ifdef-evaluator test))) |
777 (cond ((hif-range-else range) ; case 1 | 777 (cond ((hif-range-else range) ; case 1 |
778 (hif-hide-line (hif-range-else range)) | 778 (hif-hide-line (hif-range-else range)) |
779 (hide-ifdef-region (hif-range-else range) | 779 (hide-ifdef-region (hif-range-else range) |
849 (setq buffer-read-only | 849 (setq buffer-read-only |
850 (or (and hide-ifdef-hiding hide-ifdef-read-only) | 850 (or (and hide-ifdef-hiding hide-ifdef-read-only) |
851 hif-outside-read-only)) | 851 hif-outside-read-only)) |
852 (force-mode-line-update)) | 852 (force-mode-line-update)) |
853 | 853 |
854 | 854 |
855 (defun hide-ifdef-define (var) | 855 (defun hide-ifdef-define (var) |
856 "Define a VAR so that #ifdef VAR would be included." | 856 "Define a VAR so that #ifdef VAR would be included." |
857 (interactive "SDefine what? ") | 857 (interactive "SDefine what? ") |
858 (hif-set-var var 1) | 858 (hif-set-var var 1) |
859 (if hide-ifdef-hiding (hide-ifdefs))) | 859 (if hide-ifdef-hiding (hide-ifdefs))) |
864 (hif-set-var var nil) | 864 (hif-set-var var nil) |
865 (if hide-ifdef-hiding (hide-ifdefs))) | 865 (if hide-ifdef-hiding (hide-ifdefs))) |
866 | 866 |
867 | 867 |
868 (defun hide-ifdefs (&optional nomsg) | 868 (defun hide-ifdefs (&optional nomsg) |
869 "Hide the contents of some #ifdefs. | 869 "Hide the contents of some #ifdefs. |
870 Assume that defined symbols have been added to `hide-ifdef-env'. | 870 Assume that defined symbols have been added to `hide-ifdef-env'. |
871 The text hidden is the text that would not be included by the C | 871 The text hidden is the text that would not be included by the C |
872 preprocessor if it were given the file with those symbols defined. | 872 preprocessor if it were given the file with those symbols defined. |
873 | 873 |
874 Turn off hiding by calling `show-ifdefs'." | 874 Turn off hiding by calling `show-ifdefs'." |
875 | 875 |