/[emacs]/emacs/lisp/progmodes/hideif.el
ViewVC logotype

Diff of /emacs/lisp/progmodes/hideif.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.40 by pj, Sun Jul 15 16:15:35 2001 UTC revision 1.40.4.1 by lektu, Mon Oct 21 09:06:38 2002 UTC
# Line 36  Line 36 
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  ;;  ;;
43  ;; The hidden code is marked by ellipses (...).  Be  ;; The hidden code is marked by ellipses (...).  Be
44  ;; cautious when editing near ellipses, since the hidden text is  ;; 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  ;; still in the buffer, and you can move the point into it and modify
46  ;; text unawares.  If you don't want to see the ellipses, set  ;; text unawares.  If you don't want to see the ellipses, set
47  ;; selective-display-ellipses to nil.  But this can be dangerous.  ;; selective-display-ellipses to nil.  But this can be dangerous.
48  ;; 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
49  ;; 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
50  ;; variable with hide-ifdef-toggle-read-only (C-c @ C-q).  ;; variable with hide-ifdef-toggle-read-only (C-c @ C-q).
51  ;;  ;;
52  ;; You can undo the effect of hide-ifdefs by typing  ;; You can undo the effect of hide-ifdefs by typing
# Line 59  Line 59 
59  ;; 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,
60  ;; the display will be updated.  Only the define list for the current  ;; the display will be updated.  Only the define list for the current
61  ;; buffer will be affected.  You can save changes to the local define  ;; buffer will be affected.  You can save changes to the local define
62  ;; list with hide-ifdef-set-define-alist.  This adds entries  ;; list with hide-ifdef-set-define-alist.  This adds entries
63  ;; to hide-ifdef-define-alist.  ;; to hide-ifdef-define-alist.
64  ;;  ;;
65  ;; If you have defined a hide-ifdef-mode-hook, you can set  ;; If you have defined a hide-ifdef-mode-hook, you can set
# Line 207  hide-ifdef-env Line 207  hide-ifdef-env
207          is used.          is used.
208    
209  hide-ifdef-define-alist  hide-ifdef-define-alist
210          An association list of defined symbol lists.            An association list of defined symbol lists.
211          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'
212          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'
213          from one of the lists in `hide-ifdef-define-alist'.          from one of the lists in `hide-ifdef-define-alist'.
# Line 232  hide-ifdef-read-only Line 232  hide-ifdef-read-only
232          (if (null arg)          (if (null arg)
233              (not hide-ifdef-mode)              (not hide-ifdef-mode)
234            (> (prefix-numeric-value arg) 0)))            (> (prefix-numeric-value arg) 0)))
235      
236    (force-mode-line-update)    (force-mode-line-update)
237    
238    (if hide-ifdef-mode    (if hide-ifdef-mode
# Line 259  hide-ifdef-read-only Line 259  hide-ifdef-read-only
259          (show-ifdefs))          (show-ifdefs))
260      (message "Exit Hide-Ifdef mode")      (message "Exit Hide-Ifdef mode")
261      ))      ))
262      
263    
264  ;; from outline.el with docstring fixed.  ;; from outline.el with docstring fixed.
265  (defun hif-outline-flag-region (from to flag)  (defun hif-outline-flag-region (from to flag)
# Line 288  If FLAG is \\n (newline character) then Line 288  If FLAG is \\n (newline character) then
288  (add-hook 'after-revert-hook 'hif-before-revert-function)  (add-hook 'after-revert-hook 'hif-before-revert-function)
289    
290  (defun hide-ifdef-region (start end)  (defun hide-ifdef-region (start end)
291    "START is the start of a #if or #else form.  END is the ending part.    "START is the start of an #if or #else form.  END is the ending part.
292  Everything including these lines is made invisible."  Everything including these lines is made invisible."
293    (hif-outline-flag-region start end ?\^M)    (hif-outline-flag-region start end ?\^M)
294    )    )
# Line 377  that form should be displayed.") Line 377  that form should be displayed.")
377      (unwind-protect      (unwind-protect
378          (progn          (progn
379            (set-syntax-table hide-ifdef-syntax-table)            (set-syntax-table hide-ifdef-syntax-table)
380            (while (< expr-start expr-length)            (while (< expr-start expr-length)
381  ;           (message "expr-start = %d" expr-start) (sit-for 1)  ;           (message "expr-start = %d" expr-start) (sit-for 1)
382              (cond              (cond
383               ((string-match "^[ \t]+" expr-string expr-start)               ((string-match "^[ \t]+" expr-string expr-start)
# Line 485  that form should be displayed.") Line 485  that form should be displayed.")
485        (hif-nexttoken)        (hif-nexttoken)
486        (setq result (list math-op result (hif-factor))))        (setq result (list math-op result (hif-factor))))
487    result))    result))
488      
489  (defun hif-factor ()  (defun hif-factor ()
490    "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id."    "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id."
491    (cond    (cond
# Line 774  Point is left unchanged." Line 774  Point is left unchanged."
774        (while (hif-looking-at-ifX)               ; Skip nested ifdef        (while (hif-looking-at-ifX)               ; Skip nested ifdef
775          (hif-ifdef-to-endif)          (hif-ifdef-to-endif)
776          (hif-find-next-relevant))          (hif-find-next-relevant))
777        ;; Found either a #else or an #endif.        ;; Found either an #else or an #endif.
778        (cond ((hif-looking-at-else)        (cond ((hif-looking-at-else)
779               (setq else-p t)               (setq else-p t)
780               (setq else (point)))               (setq else (point)))
# Line 794  Point is left unchanged." Line 794  Point is left unchanged."
794              ))              ))
795        (hif-make-range else-p start end else))))        (hif-make-range else-p start end else))))
796    
797              
798  ;;; A bit slimy.  ;;; A bit slimy.
799  ;;; NOTE:  If there's an #ifdef at the beginning of the file, we can't  ;;; NOTE:  If there's an #ifdef at the beginning of the file, we can't
800  ;;; hide it.  There's no previous newline to replace.  If we added  ;;; hide it.  There's no previous newline to replace.  If we added
# Line 814  Point is left unchanged." Line 814  Point is left unchanged."
814              (set-buffer-modified-p modp))              (set-buffer-modified-p modp))
815            ))            ))
816      ))      ))
817                      
818    
819  ;;;  Hif-Possibly-Hide  ;;;  Hif-Possibly-Hide
820  ;;;  There are four cases.  The #ifX expression is "taken" if it  ;;;  There are four cases.  The #ifX expression is "taken" if it
821  ;;;  the hide-ifdef-evaluator returns T.  Presumably, this means the code  ;;;  the hide-ifdef-evaluator returns T.  Presumably, this means the code
822  ;;;  inside the #ifdef would be included when the program was  ;;;  inside the #ifdef would be included when the program was
823  ;;;  compiled.    ;;;  compiled.
824  ;;;  ;;;
825  ;;;  Case 1:  #ifX taken, and there's an #else.  ;;;  Case 1:  #ifX taken, and there's an #else.
826  ;;;     The #else part must be hidden.  The #if (then) part must be  ;;;     The #else part must be hidden.  The #if (then) part must be
# Line 855  It uses the judgement of `hide-ifdef-eva Line 855  It uses the judgement of `hide-ifdef-eva
855      (let ((test (hif-canonicalize))      (let ((test (hif-canonicalize))
856            (range (hif-find-range)))            (range (hif-find-range)))
857  ;      (message "test = %s" test) (sit-for 1)  ;      (message "test = %s" test) (sit-for 1)
858          
859        (hif-hide-line (hif-range-end range))        (hif-hide-line (hif-range-end range))
860        (if (funcall hide-ifdef-evaluator test)        (if (funcall hide-ifdef-evaluator test)
861            (cond ((hif-range-else-p range) ; case 1            (cond ((hif-range-else-p range) ; case 1
862                   (hif-hide-line (hif-range-else range))                   (hif-hide-line (hif-range-else range))
863                   (hide-ifdef-region (hif-range-else range)                   (hide-ifdef-region (hif-range-else range)
864                                      (1- (hif-range-end range)))                                      (1- (hif-range-end range)))
865                   (hif-recurse-on (hif-range-start range)                   (hif-recurse-on (hif-range-start range)
866                                   (hif-range-else range)))                                   (hif-range-else range)))
# Line 938  It does not do the work that's pointless Line 938  It does not do the work that's pointless
938          )          )
939    (force-mode-line-update))    (force-mode-line-update))
940    
941          
942  (defun hide-ifdef-define (var)  (defun hide-ifdef-define (var)
943    "Define a VAR so that #ifdef VAR would be included."    "Define a VAR so that #ifdef VAR would be included."
944    (interactive "SDefine what? ")    (interactive "SDefine what? ")
# Line 953  It does not do the work that's pointless Line 953  It does not do the work that's pointless
953    
954    
955  (defun hide-ifdefs (&optional nomsg)  (defun hide-ifdefs (&optional nomsg)
956    "Hide the contents of some #ifdefs.      "Hide the contents of some #ifdefs.
957  Assume that defined symbols have been added to `hide-ifdef-env'.    Assume that defined symbols have been added to `hide-ifdef-env'.
958  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
959  preprocessor if it were given the file with those symbols defined.  preprocessor if it were given the file with those symbols defined.
960    

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.40.4.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26