]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/hideif.el
Update copyright year to 2014 by running admin/update-copyright.
[gnu-emacs] / lisp / progmodes / hideif.el
index c359c819376bc8cf06c30d8034b4d7664f360135..35daeb0a573e62b075d453e1adde1ec18daafd75 100644 (file)
@@ -1,9 +1,9 @@
 ;;; hideif.el --- hides selected code within ifdef
 
-;; Copyright (C) 1988, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008  Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1994, 2001-2014 Free Software Foundation, Inc.
 
-;; Author: Daniel LaLiberte <liberte@holonexus.org>
+;; Author: Brian Marick
+;;     Daniel LaLiberte <liberte@holonexus.org>
 ;; Maintainer: FSF
 ;; Keywords: c, outlines
 
 
 ;;;###autoload
 (define-minor-mode hide-ifdef-mode
-  "Toggle Hide-Ifdef mode.  This is a minor mode, albeit a large one.
-With ARG, turn Hide-Ifdef mode on if arg is positive, off otherwise.
-In Hide-Ifdef mode, code within #ifdef constructs that the C preprocessor
-would eliminate may be hidden from view.  Several variables affect
-how the hiding is done:
+  "Toggle features to hide/show #ifdef blocks (Hide-Ifdef mode).
+With a prefix argument ARG, enable Hide-Ifdef mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+Hide-Ifdef mode is a buffer-local minor mode for use with C and
+C-like major modes.  When enabled, code within #ifdef constructs
+that the C preprocessor would eliminate may be hidden from view.
+Several variables affect how the hiding is done:
 
 `hide-ifdef-env'
        An association list of defined and undefined symbols for the
@@ -325,16 +329,23 @@ that form should be displayed.")
   "Prepend (var value) pair to hide-ifdef-env."
   (setq hide-ifdef-env (cons (cons var value) hide-ifdef-env)))
 
+(declare-function semantic-c-hideif-lookup  "semantic/bovine/c" (var))
+(declare-function semantic-c-hideif-defined "semantic/bovine/c" (var))
 
 (defun hif-lookup (var)
-  ;; (message "hif-lookup %s" var)
-  (let ((val (assoc var hide-ifdef-env)))
-    (if val
-       (cdr val)
-      hif-undefined-symbol)))
+  (or (when (bound-and-true-p semantic-c-takeover-hideif)
+       (semantic-c-hideif-lookup var))
+      (let ((val (assoc var hide-ifdef-env)))
+       (if val
+           (cdr val)
+         hif-undefined-symbol))))
 
 (defun hif-defined (var)
-   (if (assoc var hide-ifdef-env) 1 0))
+  (cond
+   ((bound-and-true-p semantic-c-takeover-hideif)
+    (semantic-c-hideif-defined var))
+   ((assoc var hide-ifdef-env) 1)
+   (t 0)))
 
 ;;===%%SF%% evaluation (End)  ===
 
@@ -412,13 +423,14 @@ that form should be displayed.")
   "Pop the next token from token-list into the let variable \"hif-token\"."
   (setq hif-token (pop hif-token-list)))
 
-(defun hif-parse-if-exp (hif-token-list)
+(defun hif-parse-if-exp (token-list)
   "Parse the TOKEN-LIST.  Return translated list in prefix form."
-  (hif-nexttoken)
-  (prog1
-      (hif-expr)
-    (if hif-token ; is there still a token?
-       (error "Error: unexpected token: %s" hif-token))))
+  (let ((hif-token-list token-list))
+    (hif-nexttoken)
+    (prog1
+        (hif-expr)
+      (if hif-token ; is there still a token?
+          (error "Error: unexpected token: %s" hif-token)))))
 
 (defun hif-expr ()
   "Parse an expression as found in #if.
@@ -507,7 +519,7 @@ that form should be displayed.")
    ;; Unary plus/minus.
    ((memq hif-token '(hif-minus hif-plus))
     (list (prog1 hif-token (hif-nexttoken)) 0 (hif-factor)))
+
    (t                                  ; identifier
     (let ((ident hif-token))
       (if (memq ident '(or and))
@@ -759,7 +771,7 @@ Point is left unchanged."
       (cond ((hif-looking-at-else)
             (setq else (point)))
            (t
-            (setq end (point)))) ; (save-excursion (end-of-line) (point))
+            (setq end (point)))) ; (line-end-position)
       ;; If found #else, look for #endif.
       (when else
        (while (progn
@@ -768,7 +780,7 @@ Point is left unchanged."
          (hif-ifdef-to-endif))
        (if (hif-looking-at-else)
            (error "Found two elses in a row?  Broken!"))
-       (setq end (point)))            ; (save-excursion (end-of-line) (point))
+       (setq end (point)))            ; (line-end-position)
       (hif-make-range start end else))))
 
 
@@ -817,7 +829,7 @@ Point is left unchanged."
 
 (defun hif-possibly-hide ()
   "Called at #ifX expression, this hides those parts that should be hidden.
-It uses the judgement of `hide-ifdef-evaluator'."
+It uses the judgment of `hide-ifdef-evaluator'."
   ;; (message "hif-possibly-hide") (sit-for 1)
   (let ((test (hif-canonicalize))
        (range (hif-find-range)))
@@ -998,7 +1010,7 @@ Return as (TOP . BOTTOM) the extent of ifdef block."
   "Compress the define list ENV into a list of defined symbols only."
   (let ((new-defs nil))
     (dolist (def env new-defs)
-      (if (hif-lookup (car def)) (push (car env) new-defs)))))
+      (if (hif-lookup (car def)) (push (car def) new-defs)))))
 
 (defun hide-ifdef-set-define-alist (name)
   "Set the association for NAME to `hide-ifdef-env'."
@@ -1024,5 +1036,4 @@ Return as (TOP . BOTTOM) the extent of ifdef block."
 
 (provide 'hideif)
 
-;; arch-tag: c6381d17-a59a-483a-b945-658f22277981
 ;;; hideif.el ends here