]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/hideif.el
(ebrowse-revert-tree-buffer-from-file): Use with-no-warnings.
[gnu-emacs] / lisp / progmodes / hideif.el
index e814f296f0eec25a9cd93930442b7d61533aa5e5..23031c5bcda24f7f3075813656261013671052ac 100644 (file)
@@ -1,6 +1,6 @@
 ;;; hideif.el --- hides selected code within ifdef
 
-;; Copyright (C) 1988,1994,2001 Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1994, 2001, 2002, 2005 Free Software Foundation, Inc.
 
 ;; Author: Daniel LaLiberte <liberte@holonexus.org>
 ;; Maintainer: FSF
@@ -36,7 +36,7 @@
 ;; M-x hide-ifdefs  or C-c @ h
 ;;
 ;; Hide-ifdef suppresses the display of code that the preprocessor wouldn't
-;; pass through.  The support of constant expressions in #if lines is 
+;; pass through.  The support of constant expressions in #if lines is
 ;; limited to identifiers, parens, and the operators: &&, ||, !, and
 ;; "defined".  Please extend this.
 ;;
@@ -45,7 +45,7 @@
 ;; still in the buffer, and you can move the point into it and modify
 ;; text unawares.
 ;; You can make your buffer read-only while hide-ifdef-hiding by setting
-;; 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
 ;; variable with hide-ifdef-toggle-read-only (C-c @ C-q).
 ;;
 ;; You can undo the effect of hide-ifdefs by typing
@@ -58,7 +58,7 @@
 ;; If you define or undefine a symbol while hide-ifdef-mode is in effect,
 ;; the display will be updated.  Only the define list for the current
 ;; buffer will be affected.  You can save changes to the local define
-;; list with hide-ifdef-set-define-alist.  This adds entries 
+;; list with hide-ifdef-set-define-alist.  This adds entries
 ;; to hide-ifdef-define-alist.
 ;;
 ;; If you have defined a hide-ifdef-mode-hook, you can set
@@ -179,7 +179,7 @@ how the hiding is done:
        is used.
 
 `hide-ifdef-define-alist'
-       An association list of defined symbol lists.  
+       An association list of defined symbol lists.
         Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env'
         and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env'
         from one of the lists in `hide-ifdef-define-alist'.
@@ -197,7 +197,7 @@ how the hiding is done:
        After `show-ifdefs', read-only status is restored to previous value.
 
 \\{hide-ifdef-mode-map}"
-  nil " Ifdef" nil
+  :group 'hide-ifdef :lighter " Ifdef"
   (if hide-ifdef-mode
       (progn
        ;; inherit global values
@@ -220,7 +220,7 @@ how the hiding is done:
     (remove-from-invisibility-spec '(hide-ifdef . t))
     (if hide-ifdef-hiding
        (show-ifdefs))))
-  
+
 
 (defun hif-show-all ()
   "Show all of the text in the current buffer."
@@ -309,7 +309,7 @@ that form should be displayed.")
 ;; pattern to match initial identifier, !, &&, ||, (, or ).
 ;; Added ==, + and -: garyo@avs.com 8/9/94
 (defconst hif-token-regexp
-  "\\(&&\\|||\\|[!=]=\\|!\\|[()+-]\\|[<>]=?\\|\\w+\\)")
+  "\\(&&\\|||\\|[!=]=\\|!\\|[()+?:-]\\|[<>]=?\\|\\w+\\)")
 
 (defun hif-tokenize (start end)
   "Separate string between START and END into a list of tokens."
@@ -342,6 +342,8 @@ that form should be displayed.")
                     ((string-equal token "<=") 'hif-less-equal)
                     ((string-equal token "+") 'hif-plus)
                     ((string-equal token "-") 'hif-minus)
+                    ((string-equal token "?") 'hif-conditional)
+                    ((string-equal token ":") 'hif-colon)
                     ((string-match "\\`[0-9]*\\'" token)
                      (string-to-number token))
                     (t (intern token)))
@@ -368,15 +370,29 @@ that form should be displayed.")
 
 (defun hif-expr ()
   "Parse an expression as found in #if.
-       expr : term | expr '||' term."
-  (let ((result (hif-term)))
+       expr : or-expr | or-expr '?' expr ':' expr."
+  (let ((result (hif-or-expr))
+       middle)
+    (while (eq hif-token 'hif-conditional)
+      (hif-nexttoken)
+      (setq middle (hif-expr))
+      (if (eq hif-token 'hif-colon)
+         (progn
+           (hif-nexttoken)
+           (setq result (list 'hif-conditional result middle (hif-expr))))
+       (error "Error: unexpected token: %s" hif-token)))
+    result))
+
+(defun hif-or-expr ()
+  "Parse n or-expr : and-expr | or-expr '||' and-expr."
+  (let ((result (hif-and-expr)))
     (while (eq hif-token 'or)
       (hif-nexttoken)
-      (setq result (list 'hif-or result (hif-term))))
+      (setq result (list 'hif-or result (hif-and-expr))))
   result))
 
-(defun hif-term ()
-  "Parse a term : eq-expr | term '&&' eq-expr."
+(defun hif-and-expr ()
+  "Parse an and-expr : eq-expr | and-expr '&&' eq-expr."
   (let ((result (hif-eq-expr)))
     (while (eq hif-token 'and)
       (hif-nexttoken)
@@ -404,7 +420,7 @@ that form should be displayed.")
       (hif-nexttoken)
       (setq result (list math-op result (hif-factor))))
   result))
-  
+
 (defun hif-factor ()
   "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id."
   (cond
@@ -449,6 +465,8 @@ that form should be displayed.")
        ((null val) 0)
        (t val)))
 
+(defun hif-conditional (a b c)
+  (if (not (zerop (hif-mathify a))) (hif-mathify b) (hif-mathify c)))
 (defun hif-and (a b)
   (and (not (zerop (hif-mathify a))) (not (zerop (hif-mathify b)))))
 (defun hif-or (a b)
@@ -702,7 +720,7 @@ Point is left unchanged."
        (setq end (point)))            ; (save-excursion (end-of-line) (point))
       (hif-make-range start end else))))
 
-         
+
 ;;; A bit slimy.
 
 (defun hif-hide-line (point)
@@ -712,13 +730,13 @@ Point is left unchanged."
        (goto-char point)
        (hide-ifdef-region-internal (line-beginning-position)
                                    (progn (hif-end-of-line) (point))))))
-                 
+
 
 ;;;  Hif-Possibly-Hide
 ;;;  There are four cases.  The #ifX expression is "taken" if it
 ;;;  the hide-ifdef-evaluator returns T.  Presumably, this means the code
 ;;;  inside the #ifdef would be included when the program was
-;;;  compiled.  
+;;;  compiled.
 ;;;
 ;;;  Case 1:  #ifX taken, and there's an #else.
 ;;;    The #else part must be hidden.  The #if (then) part must be
@@ -753,7 +771,7 @@ It uses the judgement of `hide-ifdef-evaluator'."
   (let ((test (hif-canonicalize))
        (range (hif-find-range)))
     ;; (message "test = %s" test) (sit-for 1)
-      
+
     (hif-hide-line (hif-range-end range))
     (if (not (hif-not (funcall hide-ifdef-evaluator test)))
        (cond ((hif-range-else range)   ; case 1
@@ -833,7 +851,7 @@ It does not do the work that's pointless to redo on a recursive entry."
            hif-outside-read-only))
   (force-mode-line-update))
 
-      
+
 (defun hide-ifdef-define (var)
   "Define a VAR so that #ifdef VAR would be included."
   (interactive "SDefine what? ")
@@ -848,8 +866,8 @@ It does not do the work that's pointless to redo on a recursive entry."
 
 
 (defun hide-ifdefs (&optional nomsg)
-  "Hide the contents of some #ifdefs.  
-Assume that defined symbols have been added to `hide-ifdef-env'.  
+  "Hide the contents of some #ifdefs.
+Assume that defined symbols have been added to `hide-ifdef-env'.
 The text hidden is the text that would not be included by the C
 preprocessor if it were given the file with those symbols defined.
 
@@ -940,7 +958,10 @@ Return as (TOP . BOTTOM) the extent of ifdef block."
 
 (defun hide-ifdef-use-define-alist (name)
   "Set `hide-ifdef-env' to the define list specified by NAME."
-  (interactive "SUse define list: ")
+  (interactive
+   (list (completing-read "Use define list: "
+                         hide-ifdef-define-alist nil t)))
+  (if (stringp name) (setq name (intern name)))
   (let ((define-list (assoc name hide-ifdef-define-alist)))
     (if define-list
        (setq hide-ifdef-env
@@ -951,4 +972,5 @@ Return as (TOP . BOTTOM) the extent of ifdef block."
 
 (provide 'hideif)
 
+;;; arch-tag: c6381d17-a59a-483a-b945-658f22277981
 ;;; hideif.el ends here