36 |
;; M-x hide-ifdefs or C-c @ h |
;; M-x hide-ifdefs or C-c @ h |
37 |
;; |
;; |
38 |
;; Hide-ifdef suppresses the display of code that the preprocessor wouldn't |
;; Hide-ifdef suppresses the display of code that the preprocessor wouldn't |
39 |
;; pass through. The support of constant expressions in #if lines is |
;; pass through. The support of constant expressions in #if lines is |
40 |
;; limited to identifiers, parens, and the operators: &&, ||, !, and |
;; limited to identifiers, parens, and the operators: &&, ||, !, and |
41 |
;; "defined". Please extend this. |
;; "defined". Please extend this. |
42 |
;; |
;; |
45 |
;; still in the buffer, and you can move the point into it and modify |
;; still in the buffer, and you can move the point into it and modify |
46 |
;; text unawares. |
;; text unawares. |
47 |
;; You can make your buffer read-only while hide-ifdef-hiding by setting |
;; 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 |
;; 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). |
;; variable with hide-ifdef-toggle-read-only (C-c @ C-q). |
50 |
;; |
;; |
51 |
;; You can undo the effect of hide-ifdefs by typing |
;; You can undo the effect of hide-ifdefs by typing |
58 |
;; If you define or undefine a symbol while hide-ifdef-mode is in effect, |
;; 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 |
;; 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 |
;; buffer will be affected. You can save changes to the local define |
61 |
;; list with hide-ifdef-set-define-alist. This adds entries |
;; list with hide-ifdef-set-define-alist. This adds entries |
62 |
;; to hide-ifdef-define-alist. |
;; to hide-ifdef-define-alist. |
63 |
;; |
;; |
64 |
;; If you have defined a hide-ifdef-mode-hook, you can set |
;; If you have defined a hide-ifdef-mode-hook, you can set |
179 |
is used. |
is used. |
180 |
|
|
181 |
`hide-ifdef-define-alist' |
`hide-ifdef-define-alist' |
182 |
An association list of defined symbol lists. |
An association list of defined symbol lists. |
183 |
Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env' |
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' |
and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env' |
185 |
from one of the lists in `hide-ifdef-define-alist'. |
from one of the lists in `hide-ifdef-define-alist'. |
220 |
(remove-from-invisibility-spec '(hide-ifdef . t)) |
(remove-from-invisibility-spec '(hide-ifdef . t)) |
221 |
(if hide-ifdef-hiding |
(if hide-ifdef-hiding |
222 |
(show-ifdefs)))) |
(show-ifdefs)))) |
223 |
|
|
224 |
|
|
225 |
(defun hif-show-all () |
(defun hif-show-all () |
226 |
"Show all of the text in the current buffer." |
"Show all of the text in the current buffer." |
420 |
(hif-nexttoken) |
(hif-nexttoken) |
421 |
(setq result (list math-op result (hif-factor)))) |
(setq result (list math-op result (hif-factor)))) |
422 |
result)) |
result)) |
423 |
|
|
424 |
(defun hif-factor () |
(defun hif-factor () |
425 |
"Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id." |
"Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id." |
426 |
(cond |
(cond |
720 |
(setq end (point))) ; (save-excursion (end-of-line) (point)) |
(setq end (point))) ; (save-excursion (end-of-line) (point)) |
721 |
(hif-make-range start end else)))) |
(hif-make-range start end else)))) |
722 |
|
|
723 |
|
|
724 |
;;; A bit slimy. |
;;; A bit slimy. |
725 |
|
|
726 |
(defun hif-hide-line (point) |
(defun hif-hide-line (point) |
730 |
(goto-char point) |
(goto-char point) |
731 |
(hide-ifdef-region-internal (line-beginning-position) |
(hide-ifdef-region-internal (line-beginning-position) |
732 |
(progn (hif-end-of-line) (point)))))) |
(progn (hif-end-of-line) (point)))))) |
733 |
|
|
734 |
|
|
735 |
;;; Hif-Possibly-Hide |
;;; Hif-Possibly-Hide |
736 |
;;; There are four cases. The #ifX expression is "taken" if it |
;;; There are four cases. The #ifX expression is "taken" if it |
737 |
;;; the hide-ifdef-evaluator returns T. Presumably, this means the code |
;;; the hide-ifdef-evaluator returns T. Presumably, this means the code |
738 |
;;; inside the #ifdef would be included when the program was |
;;; inside the #ifdef would be included when the program was |
739 |
;;; compiled. |
;;; compiled. |
740 |
;;; |
;;; |
741 |
;;; Case 1: #ifX taken, and there's an #else. |
;;; Case 1: #ifX taken, and there's an #else. |
742 |
;;; The #else part must be hidden. The #if (then) part must be |
;;; The #else part must be hidden. The #if (then) part must be |
771 |
(let ((test (hif-canonicalize)) |
(let ((test (hif-canonicalize)) |
772 |
(range (hif-find-range))) |
(range (hif-find-range))) |
773 |
;; (message "test = %s" test) (sit-for 1) |
;; (message "test = %s" test) (sit-for 1) |
774 |
|
|
775 |
(hif-hide-line (hif-range-end range)) |
(hif-hide-line (hif-range-end range)) |
776 |
(if (not (hif-not (funcall hide-ifdef-evaluator test))) |
(if (not (hif-not (funcall hide-ifdef-evaluator test))) |
777 |
(cond ((hif-range-else range) ; case 1 |
(cond ((hif-range-else range) ; case 1 |
851 |
hif-outside-read-only)) |
hif-outside-read-only)) |
852 |
(force-mode-line-update)) |
(force-mode-line-update)) |
853 |
|
|
854 |
|
|
855 |
(defun hide-ifdef-define (var) |
(defun hide-ifdef-define (var) |
856 |
"Define a VAR so that #ifdef VAR would be included." |
"Define a VAR so that #ifdef VAR would be included." |
857 |
(interactive "SDefine what? ") |
(interactive "SDefine what? ") |
866 |
|
|
867 |
|
|
868 |
(defun hide-ifdefs (&optional nomsg) |
(defun hide-ifdefs (&optional nomsg) |
869 |
"Hide the contents of some #ifdefs. |
"Hide the contents of some #ifdefs. |
870 |
Assume that defined symbols have been added to `hide-ifdef-env'. |
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 |
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. |
preprocessor if it were given the file with those symbols defined. |
873 |
|
|